Bug 1774471

Summary: Python os.urandom() is not FIPS compliant
Product: Red Hat Enterprise Linux 8 Reporter: Christian Heimes <cheimes>
Component: python3Assignee: Python Maintainers <python-maint>
Status: CLOSED ERRATA QA Contact: Lukáš Zachar <lzachar>
Severity: high Docs Contact:
Priority: unspecified    
Version: 8.2CC: abokovoy, cheimes, cstratak, jkejda, mkosek, pviktori, ssorce, torsava
Target Milestone: rcFlags: cheimes: needinfo-
Target Release: 8.2   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: python3-3.6.8-23.el8 Doc Type: No Doc Update
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-04-28 16:08:30 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1760850    
Attachments:
Description Flags
Experimental patch for Python master
none
Updated FIPS getrandom patch on top of Petr's FIPS branch none

Description Christian Heimes 2019-11-20 11:15:30 UTC
Description of problem:
Python's internal CSPRNG for hash randomization and os.urandom() use the Kernel DRBG via the getrandom() syscall. The Kernel RNG is not (yet) FIPS compliant.

os.urandom() is the preferred source for cryptographically secure random data. It is used a lot, amongst others by 389-DS/RHDS, IPA/IdM, and Dogtag/RHCS. It would take too much effort the modify all Python libraries and applications to use a FIPS compliant RNG. Instead Python should be modified to handle FIPS compliance internally.

Version-Release number of selected component (if applicable):
python3-3.6.8-22.el8

How reproducible:
always

Steps to Reproduce:
1. strace -egetrandom python3 -c "import os; os.urandom(8)"

Actual results:
getrandom("...", 24, GRND_NONBLOCK) = 24
getrandom("...", 8, 0) = 8


Expected results:
getrandom syscall is not used by Python directly.

Additional info:
There is an ongoing effort to make the Kernel's DRBG FIPS compliant. However it is not clear if the goal can be archived in time for RHEL 8.2. Python can use OpenSSL's DRBG through RAND_bytes() API. The DRBG in OpenSSL 1.1.1 is fork-safe.

Comment 1 Christian Heimes 2019-11-20 11:20:27 UTC
Created attachment 1638086 [details]
Experimental patch for Python master

The patch adds RAND_bytes() as preferred RNG source for Python.

A patched Python calls getrandom() three times when OpenSSL initializes its DRBG. There may be more calls under FIPS. os.urandom() does not call getrandom() any more.

$ strace -e getrandom ./python -c "import os; os.urandom(8); os.urandom(8); os.urandom(8)"
getrandom("...", 16, 0) = 16
getrandom("...", 16, 0) = 16
getrandom("...", 16, 0) = 16

Comment 3 Christian Heimes 2019-11-25 14:39:31 UTC
Created attachment 1639525 [details]
Updated FIPS getrandom patch on top of Petr's FIPS branch

https://github.com/encukou/cpython/compare/fips...tiran:fips_getrandom?expand=1

Comment 12 errata-xmlrpc 2020-04-28 16:08:30 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2020:1764