CVE-2021-22901: curl 7.75.0 through 7.76.1 suffers from a use-after-free vulnerability resulting in already freed...
8.1
CVSS Score
3.1
Basic Information
CVE ID
GHSA ID
EPSS Score
0.50367%
CWE
Published
5/24/2022
Updated
3/27/2024
KEV Status
No
Technology
-
Technical Details
CVSS Vector
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H
Vulnerability Intelligence
Miggo AI
Root Cause Analysis
The vulnerability CVE-2021-22901 is a use-after-free in curl when handling TLS 1.3 session tickets with OpenSSL. The analysis of the patch commit 7f4a9a9b2a49547eae24d2e19bc5c346e9026479 reveals the following:
- The function
ossl_connect_step1inlib/vtls/openssl.c, prior to the patch, was responsible for storing a pointer to theCurl_easystructure (the transfer object, referred to asdata) in the SSL context usingSSL_set_ex_data. This was done to make the transfer object available to theossl_new_session_cbcallback. - The
ossl_new_session_cbfunction is an OpenSSL callback that gets triggered when a new session ticket arrives. This callback would then useSSL_get_ex_datato retrieve the storedCurl_easypointer. - The vulnerability occurred if a
Curl_easyobject was freed (e.g., after a transfer completed) before theossl_new_session_cbfor that SSL session was invoked. In such cases,ossl_new_session_cbwould access a dangling pointer, leading to a use-after-free. - The patch mitigates this by:
a. Refactoring the logic for associating the
Curl_easydata into a new functionossl_associate_connection. b. Introducing a new functionossl_disassociate_connectionwhich is responsible for clearing these stored pointers (setting them to NULL) from the SSL context. c. ModifyingCurl_detach_connnection(inlib/multi.c) to callCurl_ssl_detach_conn(which in turn callsossl_disassociate_connectionfor OpenSSL backend), ensuring that when a transfer is detached from a connection, the associated pointers in the SSL context are cleared, preventingossl_new_session_cbfrom accessing stale data.
Therefore, ossl_connect_step1 (in its pre-patch state) is identified as vulnerable because it set up the conditions for the UAF. ossl_new_session_cb is identified as the function where the UAF would manifest by attempting to use the freed memory. The patch evidence for ossl_connect_step1 is the removal of the direct SSL_set_ex_data calls, and for ossl_new_session_cb it's the explicit mention in comments related to the fix and the purpose of the newly added ossl_disassociate_connection function.