Bug #75409 [NEW]: accept EFAULT in addition to ENOSYS as indicator that getrandom() is missing

From: Date: Fri, 20 Oct 2017 09:44:39 +0000
Subject: Bug #75409 [NEW]: accept EFAULT in addition to ENOSYS as indicator that getrandom() is missing
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-211789@lists.php.net to get a copy of this message
From:             martin dot zdrahal at s-team dot at
Operating system: Linux
PHP version:      7.1.10
Package:          *Encryption and hash functions
Bug Type:         Bug
Bug description:accept EFAULT in addition to ENOSYS as indicator that getrandom() is missing

Description:
------------
When running php -r '\random_int(0,20);' on my QNAP NAS, PHP always
returns an error. The kernel on my NAS returns EPERM instead of ENOSYS,
thus degrading to /dev/urandom does not happen.
This has been fixed in python a while back
(https://bugs.python.org/issue27955, albeit it does not catch EFAULT).

I suspect this behaviour exists in every PHP version that uses the
getrandom() syscall

Test script:
---------------
\random_int(0,20);

Actual result:
--------------
PHP Fatal error:  Uncaught Exception: Could not gather sufficient random
data in Command line code:1
Stack trace:
#0 Command line code(1): random_int(0, 20)
#1 {main}
  thrown in Command line code on line 1

strace output:

getrandom(0xbde13510, 4, 0)             = -1 EFAULT (Bad address)
brk(0xb6587000)                         = 0xb6587000
writev(2, [{iov_base="", iov_len=0}, {iov_base="PHP Fatal error: 
Uncaught Excep"..., iov_len=206}], 2PHP Fatal error:  Uncaught
Exception: Could not gather sufficient random data in Command line
code:1
Stack trace:
#0 Command line code(1): random_int(0, 20)
#1 {main}
  thrown in Command line code on line 1) = 206
writev(2, [{iov_base="\n", iov_len=1}, {iov_base=NULL, iov_len=0}], 2

-- 
Edit bug report at https://bugs.php.net/bug.php?id=75409&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=75409&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=75409&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=75409&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=75409&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=75409&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=75409&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=75409&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=75409&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=75409&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=75409&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=75409&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=75409&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=75409&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75409&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=75409&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=75409&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=75409&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75409&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=75409&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=75409&r=mysqlcfg



Thread (7 messages)

« previous php.bugs (#211789) next »