Bug 2040853

Summary: Double free due to incorrect fix for CVE-2021-3712
Product: Red Hat Enterprise Linux 7 Reporter: Sara Golemon <sara.golemon>
Component: opensslAssignee: Sahana Prasad <sahana>
Status: CLOSED DUPLICATE QA Contact: BaseOS QE Security Team <qe-baseos-security>
Severity: high Docs Contact:
Priority: unspecified    
Version: 7.9CC: orion, pasik
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-01-17 03:37:09 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:

Description Sara Golemon 2022-01-14 19:37:37 UTC
Description of problem:

The fix for CVE-2021-3712 (Ref: https://git.centos.org/rpms/openssl/blob/2906dac54f4739d3cad6c96ad5dd11fec982098b/f/SOURCES/openssl-1.0.2k-cve-2021-3712.patch#_304 ) incorrectly frees `emtmp` and destroys the target stack after *successfully* adding it to the stack.  When this stack is destroyed, the pointer is freed again, causing a fault.

The root cause seems to be a logic inversion where, prior to this patch, destruction and `return 0;` happens on `!sk_OPENSSL_STRING_push(*sk, emtmp)` whereas after the patch, it happens on `sk_OPENSSL_STRING_push(*sk, emtmp)` (note the lack of negation in the latter case.

Version-Release number of selected component (if applicable):
1.0.2k-22.el7_9 vs 1.0.2k-23.el7_9

How reproducible:
This was reported by a customer of ours (MongoDB) with OCSP enabled.

Steps to Reproduce:
1. Install MongoDB 4.4.latest with RHEL7 openssl-1.0.2k-23.el7_9
2. Startup mongod with OCSP enabled.
3. Crash.

Actual results:

No crash.

Expected results:

Crash due to double free.

Additional info:

Interrestingly, upstream sources do not try to free emtmp even in the event of failure, but I suspect that's either a leak, or intentionally ignoring the use of block allocated scratch space. (Ref: https://github.com/openssl/openssl/blob/081314d07705aa58912845c213a48414d8f616a9/crypto/x509v3/v3_utl.c#L621-L626 )

Comment 3 Sahana Prasad 2022-01-17 03:37:09 UTC

*** This bug has been marked as a duplicate of bug 2039993 ***