Bug 1685940

Summary: libisc doesn't initialize entropy pool for ssl context
Product: Red Hat Enterprise Linux 7 Reporter: Pavel Zhukov <pzhukov>
Component: bindAssignee: Petr Menšík <pemensik>
Status: CLOSED ERRATA QA Contact: Petr Sklenar <psklenar>
Severity: high Docs Contact:
Priority: high    
Version: 7.7CC: pemensik, psklenar, qe-baseos-daemons, thozza
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: bind-9.11.4-4.P2.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: 1668682 Environment:
Last Closed: 2019-08-06 12:39:42 UTC Type: ---
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: 1613174, 1823749    

Description Pavel Zhukov 2019-03-06 11:04:15 UTC
+++ This bug was initially created as a clone of Bug #1668682 +++

Description of problem:


Version-Release number of selected component (if applicable):
bind-export-libs-9.11.4-15.P2.el8.x86_64


How reproducible:
100%

Steps to Reproduce:
1. configure dhcpd to use ldaps
2. try to connect to any ssl server


Actual results:
Error: Cannot login into ldap server 127.0.0.1:636: Can't contact LDAP server

# openssl s_server -accept 636 -CAfile ca/ca.crt -key server/server.key  -cert server/server.crt  -debug
Using default temp DH parameters
ACCEPT
yuread from 0x564b3cafc0b0 [0x564b3cb0ac43] (5 bytes => 0 (0x0))
ERROR
shutting down SSL
CONNECTION CLOSED


Expected results:
SSL connection successfully established

Additional info:
Breakpoint 4, dst__entropy_getdata (buf=0x5555558f6cd0, len=16, pseudo=pseudo@entry=isc_boolean_false) at ../../../lib/dns/dst_api.c:1985
1985	dst__entropy_getdata(void *buf, unsigned int len, isc_boolean_t pseudo) {
(gdb) list
1980			return (ISC_R_NOSPACE);
1981		return (ISC_R_SUCCESS);
1982	}
1983	
1984	isc_result_t
1985	dst__entropy_getdata(void *buf, unsigned int len, isc_boolean_t pseudo) {
1986		unsigned int flags = dst_entropy_flags;
1987	
1988		if (dst_entropy_pool == NULL)
1989			return (ISC_R_FAILURE);
(gdb) n
1988		if (dst_entropy_pool == NULL)
(gdb) p dst_entropy_pool
$3 = (isc_entropy_t *) 0x0

--- Additional comment from Petr Menšík on 2019-01-23 15:32:53 UTC ---

This issue was fixed already in Fedora, when backported patch prepared to solve bug #1622060. It includes also entropy pool creation , which is feeded into initialized dst_lib_init.

Base reason for this behaviour is bind library overrides random generator in OpenSSL with its own entropy generator. It does however also in case dst__openssl_init() called from dns_lib_init() call, which is called from dhcp. In this case, it does not create and initialize entropy pool, but resets OpenSSL random generator to wrappers around internal entropy pool. That returns error if random data are requested. Which is not usually true in DHCP, it never calls RAND_bytes() directly or by wrapper function from ISC library. But it is called from SSL setup in OpenLDAP linked to the same binary.

Fix of bug #1622060 skips resetting OpenSSL random generator with custom one from BIND library, which also prevents this issue. Random data are always provided by default RAND_OpenSSL() implementation.

--- Additional comment from Petr Menšík on 2019-01-23 16:30:02 UTC ---

Disadvantage of current patch triggered another error in Fedora, in bug #1663318. It checks whether there is enough entropy on startup. This can prevent dhclient to initialize soon after installation, where not enough entropy was gathered. I solved that by disabling OpenSSL random generator for DHCP. That might be unwanted for TLS contexts created by LDAP. I could not find any call to random data from DHCP itself. TLS data used by LDAP might not be generated with true random data.

I think check for enough random entropy should be disabled when initialized from DHCP, but not API is prepared for it now. Could reuse eflags for entropy flags for such indication.

--- Additional comment from Petr Menšík on 2019-01-23 18:21 UTC ---

I think more simple solution should be used. With addition to ISC_PLATFORM_CRYPTORANDOM support patch, RAND_status check just should be disabled when built without threads for DHCP.

Alternative solution is to replace #ifndef ISC_PLATFORM_CRYPTORANDOM with #ifndef ISC_PLATFORM_USETHREADS in lib/dns/openssl_link.c, skipping OpenSSL random numbers reset. Other parts would not be touched.

--- Additional comment from Petr Menšík on 2019-01-23 19:31 UTC ---

Comment 2 Pavel Zhukov 2019-03-06 11:05:40 UTC
Unfortunately with bind rebase dhcp is not able to initialize ssl connection still. The reason is null entropy pool (same as in RHEL8 bz#1668682 )

Comment 9 Petr Menšík 2019-03-18 11:33:17 UTC
*** Bug 1668398 has been marked as a duplicate of this bug. ***

Comment 12 errata-xmlrpc 2019-08-06 12:39:42 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-2019:2057