|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74175 php_random_bytes() failing with php built on system where SYS_getrandom is defnd
Submitted: 2017-02-27 13:11 UTC Modified: 2017-02-27 15:48 UTC
From: Assigned:
Status: Duplicate Package: Unknown/Other Function
PHP Version: 7.1.2 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
16 + 7 = ?
Subscribe to this entry?

 [2017-02-27 13:11 UTC]
- Built PHP on a system where the SYS_getrandom macro is defined
- Ran the executable on a Kernel that doesn't implement this syscall
- php_random_bytes() is unable to generate random bytes (always returns FAILURE)

I stumbled upon this issue by running a "php:7-alpine" Docker container (from on a Debian 8 with a 3.16 kernel. The getrandom syscall is apparently implemented in linux 3.17.

The problem became visible when session_regenerate_id() failed with the following error:

    Failed to create new session ID: user (path: /sessions)

Which I traced to php_random_bytes() returning FAILURE.

Expected result:
php_random_bytes() could fallback to other methods, such as readon /dev/urandom, when the "getrandom" syscall is not implemented by the kernel.

Actual result:
php_random_bytes() calls syscall(SYS_getrandom, ...). This returns -1, with errno=38. php_random_bytes() returns FAILURE.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-02-27 13:14 UTC]
-Summary: php_random_bytes() failing with built on system where SYS_getrandom is defined +Summary: php_random_bytes() failing with php built on system where SYS_getrandom is defnd
 [2017-02-27 15:48 UTC]
-Status: Open +Status: Duplicate
 [2017-02-27 15:48 UTC]
Duplicate of bug #74105 which has been fixed in master.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Dec 08 00:05:52 2022 UTC