Re: [Python-Dev] [Python-checkins] cpython (3.5): Fix os.urandom() using getrandom() on Linux
Is this right? I thought we had decided that os.urandom should *not* fall back on getrandom on Linux? On Tue, Jun 14, 2016 at 02:36:27PM +0000, victor. stinner wrote:
https://hg.python.org/cpython/rev/e028e86a5b73 changeset: 102033:e028e86a5b73 branch: 3.5 parent: 102031:a36238de31ae user: Victor Stinner
date: Tue Jun 14 16:31:35 2016 +0200 summary: Fix os.urandom() using getrandom() on Linux Issue #27278: Fix os.urandom() implementation using getrandom() on Linux. Truncate size to INT_MAX and loop until we collected enough random bytes, instead of casting a directly Py_ssize_t to int.
files: Misc/NEWS | 4 ++++ Python/random.c | 2 +- 2 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -13,6 +13,10 @@ Library -------
+- Issue #27278: Fix os.urandom() implementation using getrandom() on Linux. + Truncate size to INT_MAX and loop until we collected enough random bytes, + instead of casting a directly Py_ssize_t to int. + - Issue #26386: Fixed ttk.TreeView selection operations with item id's containing spaces.
diff --git a/Python/random.c b/Python/random.c --- a/Python/random.c +++ b/Python/random.c @@ -143,7 +143,7 @@ to 1024 bytes */ n = Py_MIN(size, 1024); #else - n = size; + n = Py_MIN(size, INT_MAX); #endif
errno = 0;
-- Repository URL: https://hg.python.org/cpython
_______________________________________________ Python-checkins mailing list Python-checkins@python.org https://mail.python.org/mailman/listinfo/python-checkins
I think this is an issue unrelated to the big discussion from a little
while ago. The problem isn't that os.urandom() uses getrandom(), it's that
it calls it in a mode that may block.
2016-06-14 8:07 GMT-07:00 Steven D'Aprano
Is this right? I thought we had decided that os.urandom should *not* fall back on getrandom on Linux?
On Tue, Jun 14, 2016 at 02:36:27PM +0000, victor. stinner wrote:
https://hg.python.org/cpython/rev/e028e86a5b73 changeset: 102033:e028e86a5b73 branch: 3.5 parent: 102031:a36238de31ae user: Victor Stinner
date: Tue Jun 14 16:31:35 2016 +0200 summary: Fix os.urandom() using getrandom() on Linux Issue #27278: Fix os.urandom() implementation using getrandom() on Linux. Truncate size to INT_MAX and loop until we collected enough random bytes, instead of casting a directly Py_ssize_t to int.
files: Misc/NEWS | 4 ++++ Python/random.c | 2 +- 2 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -13,6 +13,10 @@ Library -------
+- Issue #27278: Fix os.urandom() implementation using getrandom() on Linux. + Truncate size to INT_MAX and loop until we collected enough random bytes, + instead of casting a directly Py_ssize_t to int. + - Issue #26386: Fixed ttk.TreeView selection operations with item id's containing spaces.
diff --git a/Python/random.c b/Python/random.c --- a/Python/random.c +++ b/Python/random.c @@ -143,7 +143,7 @@ to 1024 bytes */ n = Py_MIN(size, 1024); #else - n = size; + n = Py_MIN(size, INT_MAX); #endif
errno = 0;
-- Repository URL: https://hg.python.org/cpython
_______________________________________________ Python-checkins mailing list Python-checkins@python.org https://mail.python.org/mailman/listinfo/python-checkins
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/jelle.zijlstra%40gmail.co...
Le 14 juin 2016 5:28 PM, "Jelle Zijlstra"
The problem isn't that os.urandom() uses getrandom(), it's that it calls it in a mode that may block.
Except if it changed very recently, os.urandom() doesn't block anymore thanks to my previous change ;-) Victor
Sorry, I don't hve the bandwith to follow the huge discussion around random
in Python. If you want my help, please write a PEP to summarize the
discussion.
My change fixes an obvious bug. Even if the Python API changes, I don't
expect that all the C code will be removed.
Victor
Le 14 juin 2016 5:11 PM, "Steven D'Aprano"
Is this right? I thought we had decided that os.urandom should *not* fall back on getrandom on Linux?
On Tue, Jun 14, 2016 at 02:36:27PM +0000, victor. stinner wrote:
https://hg.python.org/cpython/rev/e028e86a5b73 changeset: 102033:e028e86a5b73 branch: 3.5 parent: 102031:a36238de31ae user: Victor Stinner
date: Tue Jun 14 16:31:35 2016 +0200 summary: Fix os.urandom() using getrandom() on Linux Issue #27278: Fix os.urandom() implementation using getrandom() on Linux. Truncate size to INT_MAX and loop until we collected enough random bytes, instead of casting a directly Py_ssize_t to int.
files: Misc/NEWS | 4 ++++ Python/random.c | 2 +- 2 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -13,6 +13,10 @@ Library -------
+- Issue #27278: Fix os.urandom() implementation using getrandom() on Linux. + Truncate size to INT_MAX and loop until we collected enough random bytes, + instead of casting a directly Py_ssize_t to int. + - Issue #26386: Fixed ttk.TreeView selection operations with item id's containing spaces.
diff --git a/Python/random.c b/Python/random.c --- a/Python/random.c +++ b/Python/random.c @@ -143,7 +143,7 @@ to 1024 bytes */ n = Py_MIN(size, 1024); #else - n = size; + n = Py_MIN(size, INT_MAX); #endif
errno = 0;
-- Repository URL: https://hg.python.org/cpython
_______________________________________________ Python-checkins mailing list Python-checkins@python.org https://mail.python.org/mailman/listinfo/python-checkins
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/victor.stinner%40gmail.co...
On 06/14/2016 08:07 AM, Steven D'Aprano wrote:
Is this right? I thought we had decided that os.urandom should *not* fall back on getrandom on Linux?
We decided that os.urandom() should not *block* on Linux. Which it doesn't; we now strictly call getrandom(GRND_NONBLOCK), which will never block. getrandom() is better because it's a system call, instead of reading from a file. So it's much less messy. If getrandom() wanted to block, instead it'll return EAGAIN, and we'll fail over to reading from /dev/urandom directly, just like we did in 3.4 and before. It's all working as intended, //arry/
participants (4)
-
Jelle Zijlstra
-
Larry Hastings
-
Steven D'Aprano
-
Victor Stinner