Text of github.com › curl › curl › issues › 23997 as Styx crawled it on Nov 18, 2026. The page may have changed since. Only its words are kept, without pictures or layout.

Open the live page

openldap: stale TLS sockbuf layer reads a freed easy handle when the connection closes · Issue #23997 · curl/curl · GitHub

Skip to content You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert openldap: stale TLS sockbuf layer reads a freed easy handle when the connection closes #23997 New issue Copy link New issue Copy link Closed Closed openldap: stale TLS sockbuf layer reads a freed easy handle when the connection closes #23997 Copy link Assignees Labels LDAP TLS vuln:NONE Vulnerability assessed and deemed insignificant Vulnerability assessed and deemed insignificant Description 007bsd opened on Nov 16, 2026 Issue body actions I did this lib/openldap.c installs its TLS sockbuf layer with ber_sockbuf_add_io() and stores the easy handle in sbiod_pvt .

It does this at connect, at the start of each transfer and in disconnect: curl/lib/openldap.c Line 561 in dbca115 ber_sockbuf_add_io ( sb , & ldapsb_tls , LBER_SBIOD_LEVEL_TRANSPORT , data )) curl/lib/openldap.c Line 1058 in dbca115 ber_sockbuf_add_io ( sb , & ldapsb_tls , LBER_SBIOD_LEVEL_TRANSPORT , data )) curl/lib/openldap.c Line 1092 in dbca115 ber_sockbuf_add_io ( sb , & ldapsb_tls , LBER_SBIOD_LEVEL_TRANSPORT , data )) { liblber's ber_sockbuf_add_io() does not replace an existing layer, it pushes a new one, and ldap_unbind_ext() calls the close function of every layer.

The layer added at connect time therefore keeps the pointer to the easy handle that connected, and ldapsb_tls_close() reads data->conn through it: curl/lib/openldap.c Lines 447 to 451 in dbca115 static int ldapsb_tls_close ( Sockbuf_IO_Desc * sbiod ) { struct Curl_easy * data = sbiod -> sbiod_pvt ; if ( data ) { struct connectdata * conn = data -> conn ; If that easy handle has been freed before the connection is closed, this is a use-after-free.

The path I found is a CONNECT_ONLY LDAPS transfer through a share that holds connections (both options are documented for this use): the connection stays in the share's pool after curl_easy_cleanup() and is closed later by curl_share_cleanup() . #include <curl/curl.h> #include <stdio.h> int main ( int argc , char * * argv ) { CURLSH * sh = curl_share_init (); CURL * e = curl_easy_init (); curl_share_setopt ( sh , CURLSHOPT_SHARE , CURL_LOCK_DATA_CONNECT ); curl_easy_setopt ( e , CURLOPT_URL , argv [ 1 ]); /* ldaps://localhost:8636/ */ curl_easy_setopt ( e , CURLOPT_CAINFO , argv [ 2 ]); curl_easy_setopt ( e , CURLOPT_CONNECT_ONLY , 1L ); curl_easy_setopt ( e , CURLOPT_SHARE , sh ); fprintf ( stderr , "perform: %d\n" , ( int ) curl_easy_perform ( e )); curl_easy_cleanup ( e ); /* easy handle freed, conn stays in the share */ curl_share_cleanup ( sh ); /* closes the conn */ return 0 ; } Run against a local LDAPS server that accepts the bind (below), with an ASan build of libcurl: perform: 0 ERROR: AddressSanitizer: heap-use-after-free READ of size 8 #0 ldapsb_tls_close lib/openldap.c:451 #1 ber_int_sb_close liblber/sockbuf.c:383 #2 ldap_free_connection libldap/request.c:817 #3 ldap_ld_free libldap/unbind.c:118 #4 ldap_unbind_ext libldap/unbind.c:52 #5 oldap_disconnect lib/openldap.c:1062 #6 cshutdn_run_conn_handler lib/cshutdn.c:107 #7 Curl_cshutdn_terminate lib/cshutdn.c:236 #8 cpool_discard_conn lib/conncache.c:230 #9 Curl_cpool_destroy lib/conncache.c:279 #10 share_destroy lib/curl_share.c:41 freed by: Curl_close lib/url.c <- curl_easy_cleanup Minimal LDAPS server used (answers Bind with success) openssl req -x509 -newkey rsa:2048 -nodes -keyout key.pem -out cert.pem -days 1 \ -subj /CN=localhost -addext subjectAltName=DNS:localhost python3 ldaps_server.py 8636 & ./poc ldaps://localhost:8636/ cert.pem #!/usr/bin/env python3 # Minimal LDAPS server: answers BindRequest and SearchRequest with success. import socket , ssl , sys , threading , os HERE = os . path . dirname ( os . path . abspath ( __file__ )) port = int ( sys . argv [ 1 ]) if len ( sys . argv ) > 1 else 8636 def rd_len ( b , i ): l = b [ i ]; i += 1 if l < 0x80 : return l , i n = l & 0x7f return int . from_bytes ( b [ i : i + n ], 'big' ), i + n def resp ( msgid , tag ): body = bytes ([ 0x0a , 1 , 0 , 4 , 0 , 4 , 0 ]) # resultCode success, "", "" op = bytes ([ tag , len ( body )]) + body mid = bytes ([ 2 , 1 , msgid ]) inner = mid + op return bytes ([ 0x30 , len ( inner )]) + inner def serve ( c ): buf = b'' try : while True : d = c . recv ( 4096 ) if not d : return buf += d while len ( buf ) > 2 and buf [ 0 ] == 0x30 : ln , i = rd_len ( buf , 1 ) if len ( buf ) < i + ln : break msg , buf = buf [: i + ln ], buf [ i + ln :] # msgid INTEGER assert msg [ i ] == 2 ml , j = rd_len ( msg , i + 1 ) msgid = int . from_bytes ( msg [ j : j + ml ], 'big' ) op = msg [ j + ml ] print ( 'op 0x%02x msgid %d' % ( op , msgid ), flush = True ) if op == 0x60 : # BindRequest c . sendall ( resp ( msgid , 0x61 )) elif op == 0x63 : # SearchRequest -> SearchResultDone c . sendall ( resp ( msgid , 0x65 )) elif op == 0x42 : # UnbindRequest return except Exception as e : print ( 'conn err' , e , flush = True ) finally : c . close () ctx = ssl .

SSLContext ( ssl . PROTOCOL_TLS_SERVER ) ctx . load_cert_chain ( os . path . join ( HERE , 'cert.pem' ), os . path . join ( HERE , 'key.pem' )) s = socket . socket (); s . setsockopt ( socket . SOL_SOCKET , socket . SO_REUSEADDR , 1 ) s . bind (( '127.0.0.1' , port )); s . listen ( 8 ) print ( 'listening' , port , flush = True ) while True : c , _ = s . accept () try : c = ctx . wrap_socket ( c , server_side = True ) except Exception as e : print ( 'tls err' , e , flush = True ); continue threading .

Thread ( target = serve , args = ( c ,), daemon = True ). start () Reproduced with 8.23.0 and master 9637d6b ( lib/openldap.c is unchanged on current master). An ordinary LDAPS transfer does not hit it, because the connection is closed while the handle is still alive. This may be a security issue (Low). Filing here per the template since I believe it is at most LOW. I expected the following No use-after-free. Removing the existing layer with ber_sockbuf_remove_io() before adding it again, or updating sbiod_pvt on the existing layer, would avoid the stale pointer. curl/libcurl version libcurl 8.23.0 and master 9637d6b , OpenSSL 3.5, OpenLDAP 2.6.10 operating system Linux x86_64 Activity bagder commented on Nov 16, 2026 bagder on Nov 16, 2026 Member More actions a CONNECT_ONLY LDAPS transfer I can't even figure out what a user would expect such a transfer to do so it probably does not work in more ways than this.

Which is also a hint that no one ever actually tried this... bagder added LDAP TLS vuln:NONE Vulnerability assessed and deemed insignificant Vulnerability assessed and deemed insignificant on Nov 16, 2026 bagder commented on Nov 17, 2026 bagder on Nov 17, 2026 Member More actions I decree not a vulnerability because applications and users don't do this. Still a bug. bagder self-assigned this on Nov 17, 2026 bagder added a commit that references this issue on Nov 17, 2026 openldap: refuse connect only for LDAPS This issue will close once commit d4ca9fb is merged into the 'master' branch. d4ca9fb bagder closed this as completed in e17e3aa on Nov 17, 2026 opensource-fork-sync added a commit that references this issue on Nov 17, 2026 openldap: refuse connect only for LDAPS This issue will close once commit e17e3aa is merged into the 'master' branch. e17e3aa Sign up for free to join this conversation on GitHub.

Already have an account? Sign in to comment Metadata Metadata Assignees bagder Labels LDAP TLS vuln:NONE Vulnerability assessed and deemed insignificant Vulnerability assessed and deemed insignificant Type No type Projects No projects Milestone No milestone Relationships None yet Development No branches or pull requests Issue actions You can’t perform that action at this time.