[issue21207] urandom persistent fd - not re-openned after fd close
Steven Hiscocks added the comment: Issue where I hit this is in Fail2Ban: https://github.com/fail2ban/fail2ban/issues/687 Lines of code where this occurs: https://github.com/fail2ban/fail2ban/blob/1c65b946171c3bbc626ddcd9320ea2515018677b/fail2ban/server/server.py#L518-530 There are other examples of closing file descriptors in other packages which create daemon processes, as well as code snippets about, as it is typical behaviour to close files. (http://en.wikipedia.org/wiki/Daemon_%28computing%29#Creation) -- ___ Python tracker <http://bugs.python.org/issue21207> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21207] urandom persistent fd - not re-openned after fd close
Steven Hiscocks added the comment: Just to add for those interested: a possible work around solution is using "os.path.sameopenfile" to check fds against another known fd for urandom. And for those wish to have a bit of fun (and maybe a security consideration): python -c "import os;os.urandom(1);os.closerange(3,256);fd = open('/dev/zero');print(os.urandom(10))" b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' -- ___ Python tracker <http://bugs.python.org/issue21207> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21207] urandom persistent fd - not re-openned after fd close
Steven Hiscocks added the comment: I agree in part, but it's quite common to close fd's in some cases like in a child process after using "os.fork()". There is no way, as far as I'm aware, to identify which fd is associated with /dev/urandom to keep it open; or anyway to reopen it such that other libraries which depend on it can use it (for example "tempfile.TemporaryFile"). -- ___ Python tracker <http://bugs.python.org/issue21207> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21207] urandom persistent fd - not re-openned after fd close
New submission from Steven Hiscocks: I've seen an issue with using urandom on Python 3.4. I've traced down to fd being closed (not by core CPython, but by third party library code). After this, access to urandom fails. I assume this is related to persistent fd for urandom in http://bugs.python.org/issue18756 $ python -c "import os;os.urandom(1);os.closerange(3,256);os.urandom(1)" Traceback (most recent call last): File "", line 1, in OSError: [Errno 9] Bad file descriptor -- messages: 215973 nosy: kwirk priority: normal severity: normal status: open title: urandom persistent fd - not re-openned after fd close type: crash versions: Python 3.4 ___ Python tracker <http://bugs.python.org/issue21207> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com