Bug #74175 [NEW]: php_random_bytes() failing with built on system where SYS_getrandom is defined
| From: | lbarnaud@php.net | Date: | Mon, 27 Feb 2017 13:12:03 +0000 |
| Subject: | Bug #74175 [NEW]: php_random_bytes() failing with built on system where SYS_getrandom is defined | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-207577@lists.php.net to get a copy of this message | ||
From: lbarnaud@php.net
Operating system: Linux
PHP version: 7.1.2
Package: Unknown/Other Function
Bug Type: Bug
Bug description:php_random_bytes() failing with built on system where SYS_getrandom is defined
Description:
------------
- 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 https://hub.docker.com/_/php/) 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.
--
Edit bug report at https://bugs.php.net/bug.php?id=74175&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74175&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74175&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74175&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=74175&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=74175&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=74175&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=74175&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=74175&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=74175&r=support
Expected behavior: https://bugs.php.net/fix.php?id=74175&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=74175&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=74175&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=74175&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74175&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=74175&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=74175&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=74175&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=74175&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=74175&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=74175&r=mysqlcfg