Skip to content
Race condition Disclosed report Advanced

Race condition on global `gss_context` during SOCKS5 GSS-API negotiation in libcurl

Concurrent SOCKS5 GSS-API authentications in libcurl share a file-scope global GSS context without synchronisation, producing a data race. The reporter claims this could cause a process crash or denial of service and authentication failures under load, but did not demonstrate memory disclosure or code execution.

giant_anteater Follow

Originally disclosed on HackerOne

  • Disclosed after 2 days

Summary:

Concurrent SOCKS5 GSS-API authentications share a file-scope global gss_context without synchronization, causing data races and undefined behavior.

  • Global context defined at:
static gss_ctx_id_t gss_context = GSS_C_NO_CONTEXT;
  • Passed by address into the GSS init routine per negotiation:
gss_major_status = Curl_gss_init_sec_context(data,
                                             &gss_minor_status,
                                             &gss_context,
                                             server,
                                             &Curl_krb5_mech_oid,
                                             NULL,
                                             gss_token,
                                             &gss_send_token,
                                             TRUE,
                                             &gss_ret_flags);

Using Helgrind with libcurl’s DEBUGBUILD GSS stub (CURL_STUB_GSS_CREDS=KRB5) to avoid libkrb5-internal noise, I observed a reproducible data race that directly references the global symbol gss_context:

  • Helgrind evidence (from docker_helgrind.log):
==XXXX== Possible data race during read of size 8 at ...
==XXXX==    at 0x1CEFC0: stub_gss_init_sec_context (curl_gssapi.c:126)
==XXXX==    by 0x1CEE43: Curl_gss_init_sec_context (curl_gssapi.c:329)
==XXXX==    by 0x1BCB3B: Curl_SOCKS5_gssapi_negotiate (socks_gssapi.c:184)
...
==XXXX== This conflicts with a previous write of size 8 by thread #Y
==XXXX==    at 0x1CF4A4: stub_gss_init_sec_context (curl_gssapi.c:264)
==XXXX==    by 0x1CEE43: Curl_gss_init_sec_context (curl_gssapi.c:329)
==XXXX==    by 0x1BCB3B: Curl_SOCKS5_gssapi_negotiate (socks_gssapi.c:184)
==XXXX==  Address ... is 0 bytes inside data symbol "gss_context"

[AI assistance was used to orchestrate the build/run environment and tooling and to help with report writing. All findings, code locations, and outputs cited below were directly observed and verified from the built code and runtime logs.]

Affected version

  • Built from current master (configure summary reported: curl version: 8.17.0-DEV) in an Ubuntu 24.04 (arm64) container
  • GSS-API provider: MIT Kerberos (system libgssapi_krb5), and also tested with curl’s DEBUGBUILD GSS stub via CURL_STUB_GSS_CREDS=KRB5

Steps To Reproduce:

  1. Start an Ubuntu container and install prerequisites:
Bash
docker run --rm -it -v "$PWD":/src -w /src ubuntu:24.04 bash -lc '
  set -euo pipefail
  export DEBIAN_FRONTEND=noninteractive
  apt-get update -qq
  apt-get install -y -qq clang make autoconf automake libtool pkg-config libkrb5-dev python3 valgrind > /dev/null
  update-ca-certificates > /dev/null 2>&1 || true
'
  1. Configure and build libcurl (Debug, GSS-API, minimal deps):
Bash
docker run --rm -it -v "$PWD":/src -w /src ubuntu:24.04 bash -lc '
  set -euo pipefail
  if [ -f Makefile ]; then make distclean || true; fi
  if [ -x ./buildconf ]; then ./buildconf; else autoreconf -fi; fi
  export CC=clang CFLAGS="-O0 -g -fno-omit-frame-pointer" LDFLAGS=""
  ./configure --enable-debug --with-gssapi --disable-shared \
    --without-ssl --without-libidn2 --without-libpsl --without-libssh2 \
    --without-brotli --without-zstd --without-nghttp2 --without-nghttp3 --without-ngtcp2
  make -j"$(nproc)"
'
  1. Launch a minimal SOCKS5 proxy that selects GSS-API (method 1):
Bash
docker run --rm -it -v "$PWD":/src -w /src ubuntu:24.04 bash -lc '
  set -euo pipefail
  cat > proxy.py <<PY
import socket, threading, struct

def handle(c):
    try:
        data=c.recv(262)
        if len(data)<3: return
        c.sendall(b"\x05\x01")
        hdr=c.recv(4)
        if len(hdr)<4: return
        ln=struct.unpack("!H", hdr[2:4])[0]
        _=c.recv(ln)
        c.sendall(b"\x01\x01\x00\x01D")
        hdr=c.recv(4)
        if len(hdr)<4: return
        ln=struct.unpack("!H", hdr[2:4])[0]
        _=c.recv(ln)
        c.sendall(b"\x01\x02\x00\x01\x00")
    finally:
        try: c.close()
        except: pass

s=socket.socket(); s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
s.bind(("0.0.0.0",1081)); s.listen()
print("listening 0.0.0.0 1081", flush=True)
while True:
    c,_=s.accept()
    threading.Thread(target=handle,args=(c,),daemon=True).start()
PY
  python3 proxy.py &
  sleep 1
'
  1. Build the multithreaded PoC using libcurl:
Bash
docker run --rm -it -v "$PWD":/src -w /src ubuntu:24.04 bash -lc '
  set -euo pipefail
  cat > test_gss_race.c <<C
#include <pthread.h>
#include <curl/curl.h>
static void *worker(void *u){
  CURL *e=curl_easy_init();
  curl_easy_setopt(e,CURLOPT_URL,(char*)u);
  curl_easy_setopt(e,CURLOPT_PROXY,"socks5://127.0.0.1:1081");
  curl_easy_setopt(e,CURLOPT_SOCKS5_GSSAPI_SERVICE,"rcmd");
  curl_easy_setopt(e,CURLOPT_SOCKS5_AUTH,(long)CURLAUTH_GSSAPI);
  for(int i=0;i<50;++i) curl_easy_perform(e);
  curl_easy_cleanup(e);
  return 0;
}
int main(void){
  curl_global_init(CURL_GLOBAL_DEFAULT);
  enum { N=16 }; pthread_t th[N];
  for(int i=0;i<N;++i) pthread_create(&th[i],0,worker,"http://example.com");
  for(int i=0;i<N;++i) pthread_join(th[i],0);
  curl_global_cleanup();
  return 0;
}
C
  clang -O0 -g -Iinclude test_gss_race.c -Llib/.libs -lcurl -lgssapi_krb5 -lpthread -o test_gss_race
'
  1. Run under Helgrind with curl’s DEBUGBUILD GSS stub to surface races in curl (and reduce libkrb5 noise):
Bash
docker run --rm -it -v "$PWD":/src -w /src ubuntu:24.04 bash -lc '
  set -euo pipefail
  export CURL_STUB_GSS_CREDS=KRB5
  valgrind --tool=helgrind --quiet --fair-sched=try ./test_gss_race | tee docker_helgrind.log
'
  1. Verify the race report mentions the global symbol gss_context and the call site in socks_gssapi.c:
  • Look for lines similar to:
Possible data race ...
... Curl_SOCKS5_gssapi_negotiate (socks_gssapi.c:184)
... Address ... is 0 bytes inside data symbol "gss_context"

Supporting Material/References:

  • Source code location of the shared global:
static gss_ctx_id_t gss_context = GSS_C_NO_CONTEXT;
  • Call site passing the shared global by address into the GSS routine:
gss_major_status = Curl_gss_init_sec_context(data,
                                             &gss_minor_status,
                                             &gss_context,
                                             server,
                                             &Curl_krb5_mech_oid,
                                             NULL,
                                             gss_token,
                                             &gss_send_token,
                                             TRUE,
                                             &gss_ret_flags);
  • Helgrind log excerpt (from my run) demonstrating the race on gss_context:
==XXXX== Possible data race during read of size 8 ...
==XXXX==    at 0x1CEFC0: stub_gss_init_sec_context (curl_gssapi.c:126)
==XXXX==    by 0x1CEE43: Curl_gss_init_sec_context (curl_gssapi.c:329)
==XXXX==    by 0x1BCB3B: Curl_SOCKS5_gssapi_negotiate (socks_gssapi.c:184)
...
==XXXX== This conflicts with a previous write ...
==XXXX==    at 0x1CF4A4: stub_gss_init_sec_context (curl_gssapi.c:264)
==XXXX==    by 0x1CEE43: Curl_gss_init_sec_context (curl_gssapi.c:329)
==XXXX==    by 0x1BCB3B: Curl_SOCKS5_gssapi_negotiate (socks_gssapi.c:184)
==XXXX==  Address ... is 0 bytes inside data symbol "gss_context"

Impact

Summary:

The shared global gss_context is accessed and modified concurrently across connections without synchronization. This presents a realistic risk of:

  • Process crash / denial of service due to undefined behavior and races in GSS context handling
  • Authentication failures or misbehavior during SOCKS5 proxy negotiation under load

I did not observe or claim memory disclosure or RCE, the verified impact is concurrency-related instability (DoS/UB) when multiple handles/authentications run concurrently.

The original report as published on HackerOne, by giant_anteater. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 8 min read.

Context

libcurl supports reaching a target through a SOCKS5 proxy that requires GSS-API (Kerberos) authentication. When a transfer is configured with CURLOPT_PROXY pointing at a socks5:// proxy and CURLOPT_SOCKS5_AUTH set to CURLAUTH_GSSAPI, the SOCKS5 handler in lib/socks_gssapi.c performs the GSS-API negotiation with the proxy before the actual connection is made. The service principal name is taken from CURLOPT_SOCKS5_GSSAPI_SERVICE.

The negotiation needs a GSS security context. In this code the context is not stored per connection or per easy handle: it is a single file-scope static variable shared by every negotiation in the process.

Setup

The report was produced against a build from current master, whose configure summary reported curl version: 8.17.0-DEV, inside an Ubuntu 24.04 (arm64) container. Two GSS-API providers were used: the system MIT Kerberos library (libgssapi_krb5), and curl's own DEBUGBUILD GSS stub, selected with CURL_STUB_GSS_CREDS=KRB5. The stub was used to keep libkrb5-internal noise out of the race detector output so that races inside curl itself are visible.

The tooling is Valgrind's Helgrind thread-error detector, plus clang, make, autoconf/automake/libtool, pkg-config, libkrb5-dev and python3. A small Python SOCKS5 server stands in for the proxy, and a small C program drives concurrent libcurl transfers through it.

The report notes that AI assistance was used to orchestrate the build and run environment and tooling and to help with report writing, and states that all findings, code locations and outputs cited were directly observed and verified from the built code and runtime logs.

Finding it

The starting point is the declaration of the shared context in curl/lib/socks_gssapi.c:

C
static gss_ctx_id_t gss_context = GSS_C_NO_CONTEXT;

That variable is then passed by address into the GSS init routine on every negotiation:

C
gss_major_status = Curl_gss_init_sec_context(data,
                                             &gss_minor_status,
                                             &gss_context,
                                             server,
                                             &Curl_krb5_mech_oid,
                                             NULL,
                                             gss_token,
                                             &gss_send_token,
                                             TRUE,
                                             &gss_ret_flags);

Because the address of a single global is handed to a routine that reads and writes the context, two threads negotiating at the same time operate on the same object with no synchronisation. That is the shape of a data race, and the researcher confirmed it with Helgrind rather than relying on inspection alone. The Helgrind output directly names the global symbol gss_context and the call site in socks_gssapi.c:

Text
==XXXX== Possible data race during read of size 8 at ...
==XXXX==    at 0x1CEFC0: stub_gss_init_sec_context (curl_gssapi.c:126)
==XXXX==    by 0x1CEE43: Curl_gss_init_sec_context (curl_gssapi.c:329)
==XXXX==    by 0x1BCB3B: Curl_SOCKS5_gssapi_negotiate (socks_gssapi.c:184)
...
==XXXX== This conflicts with a previous write of size 8 by thread #Y
==XXXX==    at 0x1CF4A4: stub_gss_init_sec_context (curl_gssapi.c:264)
==XXXX==    by 0x1CEE43: Curl_gss_init_sec_context (curl_gssapi.c:329)
==XXXX==    by 0x1BCB3B: Curl_SOCKS5_gssapi_negotiate (socks_gssapi.c:184)
==XXXX==  Address ... is 0 bytes inside data symbol "gss_context"

The read at curl_gssapi.c:126 and the conflicting write at curl_gssapi.c:264 both arrive through Curl_gss_init_sec_context and Curl_SOCKS5_gssapi_negotiate, and the address reported is zero bytes inside the gss_context data symbol, so the race is on the shared context itself and not on some unrelated allocation.

Exploitation

The reproduction is a full build-and-run recipe. Each step runs in a fresh Ubuntu 24.04 container with the working directory mounted at /src.

Step 1: install prerequisites

Bash
docker run --rm -it -v "$PWD":/src -w /src ubuntu:24.04 bash -lc '
  set -euo pipefail
  export DEBIAN_FRONTEND=noninteractive
  apt-get update -qq
  apt-get install -y -qq clang make autoconf automake libtool pkg-config libkrb5-dev python3 valgrind > /dev/null
  update-ca-certificates > /dev/null 2>&1 || true
'

This installs the compiler, the autotools chain, the Kerberos development headers, Python for the proxy and Valgrind for Helgrind.

Step 2: configure and build libcurl

Bash
docker run --rm -it -v "$PWD":/src -w /src ubuntu:24.04 bash -lc '
  set -euo pipefail
  if [ -f Makefile ]; then make distclean || true; fi
  if [ -x ./buildconf ]; then ./buildconf; else autoreconf -fi; fi
  export CC=clang CFLAGS="-O0 -g -fno-omit-frame-pointer" LDFLAGS=""
  ./configure --enable-debug --with-gssapi --disable-shared \
    --without-ssl --without-libidn2 --without-libpsl --without-libssh2 \
    --without-brotli --without-zstd --without-nghttp2 --without-nghttp3 --without-ngtcp2
  make -j"$(nproc)"
'

The build is a debug build with GSS-API enabled and a static library (--disable-shared), with the optional dependencies switched off to keep the build minimal. -O0 -g -fno-omit-frame-pointer keeps the binaries easy to read in the debugger and in Valgrind output.

Step 3: start a minimal SOCKS5 proxy that selects GSS-API

Bash
docker run --rm -it -v "$PWD":/src -w /src ubuntu:24.04 bash -lc '
  set -euo pipefail
  cat > proxy.py <<PY
import socket, threading, struct

def handle(c):
    try:
        data=c.recv(262)
        if len(data)<3: return
        c.sendall(b"\x05\x01")
        hdr=c.recv(4)
        if len(hdr)<4: return
        ln=struct.unpack("!H", hdr[2:4])[0]
        _=c.recv(ln)
        c.sendall(b"\x01\x01\x00\x01D")
        hdr=c.recv(4)
        if len(hdr)<4: return
        ln=struct.unpack("!H", hdr[2:4])[0]
        _=c.recv(ln)
        c.sendall(b"\x01\x02\x00\x01\x00")
    finally:
        try: c.close()
        except: pass

s=socket.socket(); s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
s.bind(("[redacted]",1081)); s.listen()
print("listening [redacted] 1081", flush=True)
while True:
    c,_=s.accept()
    threading.Thread(target=handle,args=(c,),daemon=True).start()
PY
  python3 proxy.py &
  sleep 1
'

The proxy listens on port 1081 and answers the SOCKS5 method negotiation with \x05\x01. It then reads the request header and address and sends a reply, then reads another header and length and sends a second reply. It then reads the next header and length and sends a second reply. The point is not to proxy anything real: it is to drive libcurl far enough into Curl_SOCKS5_gssapi_negotiate that the GSS init routine is called, repeatedly and concurrently.

Step 4: build the multithreaded PoC

Bash
docker run --rm -it -v "$PWD":/src -w /src ubuntu:24.04 bash -lc '
  set -euo pipefail
  cat > test_gss_race.c <<C
#include <pthread.h>
#include <curl/curl.h>
static void *worker(void *u){
  CURL *e=curl_easy_init();
  curl_easy_setopt(e,CURLOPT_URL,(char*)u);
  curl_easy_setopt(e,CURLOPT_PROXY,"socks5://[redacted]:1081");
  curl_easy_setopt(e,CURLOPT_SOCKS5_GSSAPI_SERVICE,"rcmd");
  curl_easy_setopt(e,CURLOPT_SOCKS5_AUTH,(long)CURLAUTH_GSSAPI);
  for(int i=0;i<50;++i) curl_easy_perform(e);
  curl_easy_cleanup(e);
  return 0;
}
int main(void){
  curl_global_init(CURL_GLOBAL_DEFAULT);
  enum { N=16 }; pthread_t th[N];
  for(int i=0;i<N;++i) pthread_create(&th[i],0,worker,"http://example.com");
  for(int i=0;i<N;++i) pthread_join(th[i],0);
  curl_global_cleanup();
  return 0;
}
C
  clang -O0 -g -Iinclude test_gss_race.c -Llib/.libs -lcurl -lgssapi_krb5 -lpthread -o test_gss_race
'

Each of 16 threads creates its own easy handle, points it at the local SOCKS5 proxy, sets the GSS-API service name to rcmd and forces GSS-API authentication with CURLAUTH_GSSAPI, then performs 50 transfers. Sixteen handles negotiating at once against the same process-wide gss_context is what turns the shared global into an observable race. The program is linked against the freshly built static libcurl and against libgssapi_krb5.

Step 5: run under Helgrind with the GSS stub

Bash
docker run --rm -it -v "$PWD":/src -w /src ubuntu:24.04 bash -lc '
  set -euo pipefail
  export CURL_STUB_GSS_CREDS=KRB5
  valgrind --tool=helgrind --quiet --fair-sched=try ./test_gss_race | tee docker_helgrind.log
'

CURL_STUB_GSS_CREDS=KRB5 selects curl's DEBUGBUILD GSS stub, which removes libkrb5-internal noise from the report. The run uses --fair-sched=try, and the output is saved to docker_helgrind.log. The output is saved to docker_helgrind.log.

Step 6: confirm the race points at the global

Look in the log for lines similar to:

Text
Possible data race ...
... Curl_SOCKS5_gssapi_negotiate (socks_gssapi.c:184)
... Address ... is 0 bytes inside data symbol "gss_context"

The two things that matter are the call site in socks_gssapi.c and the address being inside the gss_context data symbol. Both appear in the run, which is what makes this a confirmed race on the shared context rather than a generic threading warning.

Root cause

gss_context is a file-scope static in lib/socks_gssapi.c, initialised to GSS_C_NO_CONTEXT. Every SOCKS5 GSS-API negotiation in the process passes &gss_context into Curl_gss_init_sec_context, which forwards it to the GSS implementation. The GSS init routine reads the existing context and writes the updated one back through that pointer. When two connections negotiate concurrently, one thread's write and another thread's read of the same eight-byte object are unordered, which is a data race and therefore undefined behaviour in C.

The design offers no per-handle or per-connection storage for the context and no lock around the shared one, so nothing in the code prevents the overlap. The race detector output shows the read and the conflicting write both reached through Curl_SOCKS5_gssapi_negotiate, confirming that the two sides of the race are two concurrent negotiations.

Impact

The report describes the verified impact as concurrency-related instability when multiple handles or authentications run concurrently. Specifically, it lists a realistic risk of a process crash or denial of service caused by undefined behaviour and races in GSS context handling, and of authentication failures or misbehaviour during SOCKS5 proxy negotiation under load.

The researcher explicitly did not observe or claim memory disclosure or remote code execution. The impact is bounded to instability and failed or incorrect authentication in a process that performs concurrent SOCKS5 GSS-API negotiations.

Fix

The report does not describe a fix or a patch. The report does not describe a fix or a patch, and does not state which approach was taken.

Variants to test

  • Other protocol handlers that keep GSS or authentication state in file-scope statics. A positive result is a Helgrind or ThreadSanitizer report whose address falls inside a named data symbol and whose stack passes through the negotiation function for that protocol.
  • The same SOCKS5 GSS-API path with more threads and more iterations than the 16 by 50 used here. A positive result is the same gss_context race appearing more often, or additional races on neighbouring state in the same file.
  • The same path against a real MIT Kerberos setup rather than the DEBUGBUILD stub. A positive result is a race report that still names curl frames, or observable authentication failures or crashes under concurrent load.
  • Anywhere a library hands the address of a process-wide object to a callback or third-party routine that both reads and writes it. A positive result is a detector report showing a read in one thread conflicting with a write in another on that object.
  • Running the same concurrent workload under ThreadSanitizer as a second opinion. A positive result is a matching race report on the same symbol and call site.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 18 min read.

What happened, in plain words

Imagine a shared office kitchen with one kettle and no rota. Two people decide at the same moment to fill it, switch it on and pour. Each one assumes they are the only user. Sometimes it works, sometimes the water goes everywhere, and nobody can predict which. The kettle is fine on its own; the problem is that it is shared without any rule about taking turns.

This report is about the same kind of problem inside a piece of software called libcurl. libcurl is a library: a bundle of ready-made code that other programs call when they need to talk over a network. It is the engine behind the curl command-line tool and inside countless applications, so a bug here can affect a lot of software at once.

libcurl can be told to reach a website through a proxy. A proxy is a middleman server: instead of connecting to the destination directly, your program connects to the proxy and asks it to make the connection on your behalf. Some proxies want proof of who you are before they agree. One way to prove it is a system called GSS-API, which in practice usually means Kerberos, an authentication system common in company networks. When libcurl talks to such a proxy, it performs a short back-and-forth conversation to prove its identity. That conversation is called a negotiation, and the state it builds up along the way is called a context.

The bug: libcurl keeps that context in one single place shared by the whole program, rather than giving each connection its own. If two connections negotiate at the same time, they both read and write the same shared object with no rule about taking turns. In programming terms that is a race condition, and in the C language it is undefined behaviour: the language makes no promise about what happens, so anything from a wrong answer to a crash is possible.

The researcher who wrote the report did not just read the code and guess. They built libcurl from source, wrote a small test program that opens many connections at once, and ran it under a tool called Helgrind that watches for exactly this kind of simultaneous access. Helgrind produced a report naming the shared variable directly. The verified impact is instability: crashes or failed logins when many connections negotiate at the same time. The researcher explicitly did not claim that an attacker could read other people's data or run their own code.

The pieces involved

Before the steps, here are the moving parts, because the report uses all of them.

  • libcurl: the library that does the network talking. The report is filed against its source code on GitHub.
  • SOCKS5: a protocol for talking to a proxy. Your program sends the proxy a short message saying "please connect me to this address", and the proxy does it. SOCKS5 has a step where the two sides agree on how (or whether) to authenticate.
  • GSS-API / Kerberos: the authentication system used in that step. The proxy and the client prove their identities to each other using tickets issued by a central authority, a bit like showing a stamped pass rather than a password.
  • Easy handle: libcurl's per-transfer object. You create one, set options on it, perform the transfer, and clean it up. It is meant to be independent of other handles.
  • Thread: a way for one program to do several things at once. Each thread runs its own sequence of instructions, and threads share the program's memory. That sharing is what makes races possible.
  • Data race: two threads touch the same memory at the same time, at least one of them writing, with nothing coordinating them. The result is unpredictable.
  • Helgrind: a tool built into Valgrind (a suite of debugging tools) that detects data races by watching how threads access memory.
  • Docker container: a disposable, isolated mini-computer inside your computer. The report runs every step in a fresh Ubuntu 24.04 container so the environment is reproducible.

Context: how the feature works

When a program tells libcurl to use a socks5:// proxy and to authenticate with GSS-API, libcurl's SOCKS5 handler in the file lib/socks_gssapi.c runs the GSS-API negotiation with the proxy before the real connection is made. The name of the service it asks the proxy for comes from an option called CURLOPT_SOCKS5_GSSAPI_SERVICE.

The negotiation needs a GSS security context. In this code, that context is not stored per connection or per easy handle. It is a single file-scope static variable: a variable declared once for the whole file, shared by every negotiation happening anywhere in the program.

Setup: what was built and why

The report was produced against a build from the current development branch (master), whose configure summary reported curl version: 8.17.0-DEV, inside an Ubuntu 24.04 (arm64) container. Two GSS-API providers were used: the system MIT Kerberos library (libgssapi_krb5), and curl's own debug-build GSS stub, selected with the environment variable CURL_STUB_GSS_CREDS=KRB5. The stub is curl's DEBUGBUILD GSS stub. It was used to keep noise from inside the real Kerberos library out of the race detector's output, so that races inside curl itself are visible.

The tooling is Valgrind's Helgrind thread-error detector, plus clang (a C compiler), make, autoconf/automake/libtool (tools that prepare source code for building), pkg-config, libkrb5-dev (Kerberos development files) and python3. A small Python SOCKS5 server stands in for the proxy, and a small C program drives many libcurl transfers through it at once.

The report notes that AI assistance was used to orchestrate the build and run environment and tooling and to help with report writing, and states that all findings, code locations and outputs cited were directly observed and verified from the built code and runtime logs.

Finding it

The starting point is the declaration of the shared context in curl/lib/socks_gssapi.c:

C
static gss_ctx_id_t gss_context = GSS_C_NO_CONTEXT;

Line by line:

  • static means this variable belongs to the file, not to any one function or connection. Every piece of code in that file sees the same one.
  • gss_ctx_id_t is the type of a GSS security context: a handle to the state of an authentication conversation.
  • gss_context is the variable's name.
  • = GSS_C_NO_CONTEXT sets it to the special "no context yet" value, the equivalent of an empty slot.

That variable is then passed by address into the GSS init routine on every negotiation:

C
gss_major_status = Curl_gss_init_sec_context(data,
                                             &gss_minor_status,
                                             &gss_context,
                                             server,
                                             &Curl_krb5_mech_oid,
                                             NULL,
                                             gss_token,
                                             &gss_send_token,
                                             TRUE,
                                             &gss_ret_flags);

Line by line:

  • gss_major_status = stores the overall result of the call.
  • Curl_gss_init_sec_context( is curl's wrapper around the GSS "initialise a security context" routine.
  • data is curl's own per-transfer state.
  • &gss_minor_status passes the address of a variable where a more detailed status code will be written. The & means "the address of", so the function can write into it.
  • &gss_context passes the address of the shared global. This is the heart of the problem: the routine will read the existing context and write the updated one back through this pointer, and it is the same pointer for every connection.
  • server is the name of the service being asked for.
  • &Curl_krb5_mech_oid says which authentication mechanism to use (Kerberos).
  • NULL is a placeholder for an optional input token.
  • gss_token is the token received from the proxy.
  • &gss_send_token is where the token to send back will be stored.
  • TRUE asks for mutual authentication: both sides prove who they are.
  • &gss_ret_flags receives flags describing what the context supports.

Because the address of a single global is handed to a routine that reads and writes the context, two threads negotiating at the same time operate on the same object with no synchronisation. That is the shape of a data race, and the researcher confirmed it with Helgrind rather than relying on inspection alone. The Helgrind output directly names the global symbol gss_context and the call site in socks_gssapi.c:

Text
==XXXX== Possible data race during read of size 8 at ...
==XXXX==    at 0x1CEFC0: stub_gss_init_sec_context (curl_gssapi.c:126)
==XXXX==    by 0x1CEE43: Curl_gss_init_sec_context (curl_gssapi.c:329)
==XXXX==    by 0x1BCB3B: Curl_SOCKS5_gssapi_negotiate (socks_gssapi.c:184)
...
==XXXX== This conflicts with a previous write of size 8 by thread #Y
==XXXX==    at 0x1CF4A4: stub_gss_init_sec_context (curl_gssapi.c:264)
==XXXX==    by 0x1CEE43: Curl_gss_init_sec_context (curl_gssapi.c:329)
==XXXX==    by 0x1BCB3B: Curl_SOCKS5_gssapi_negotiate (socks_gssapi.c:184)
==XXXX==  Address ... is 0 bytes inside data symbol "gss_context"

How to read this output:

  • Possible data race during read of size 8 means one thread read eight bytes of memory while another thread was writing the same eight bytes, with nothing ordering the two.
  • The at line is where the read happened: inside the stub's context-init function at line 126 of curl_gssapi.c.
  • The by lines are the chain of callers: curl's wrapper at line 329, called from the SOCKS5 negotiation function at line 184 of socks_gssapi.c.
  • This conflicts with a previous write of size 8 by thread #Y is the other side of the race: a different thread wrote those same eight bytes, at line 264 of the stub.
  • Address ... is 0 bytes inside data symbol "gss_context" is the clincher: the memory in question is the very start of the shared variable itself, not some unrelated allocation.

The read at curl_gssapi.c:126 and the conflicting write at curl_gssapi.c:264 both arrive through Curl_gss_init_sec_context and Curl_SOCKS5_gssapi_negotiate, so the race is on the shared context itself.

Reproducing it step by step

The reproduction is a full build-and-run recipe. Each step runs in a fresh Ubuntu 24.04 container with the working directory mounted at /src.

Step 1: install prerequisites

Bash
docker run --rm -it -v "$PWD":/src -w /src ubuntu:24.04 bash -lc '
  set -euo pipefail
  export DEBIAN_FRONTEND=noninteractive
  apt-get update -qq
  apt-get install -y -qq clang make autoconf automake libtool pkg-config libkrb5-dev python3 valgrind > /dev/null
  update-ca-certificates > /dev/null 2>&1 || true
'

Line by line:

  • docker run --rm -it starts a container, removes it when done (--rm), and gives you an interactive terminal (-it).
  • -v "$PWD":/src makes your current folder appear inside the container as /src, so files you create there survive the container.
  • -w /src sets the working directory inside the container.
  • ubuntu:24.04 is the image: a clean Ubuntu system.
  • bash -lc '...' runs the quoted commands in a login shell.
  • set -euo pipefail makes the script stop on any error, which keeps failures obvious.
  • export DEBIAN_FRONTEND=noninteractive stops package installation from asking questions.
  • apt-get update -qq refreshes the package list quietly.
  • apt-get install -y -qq ... installs the compiler, the autotools chain, the Kerberos development headers, Python for the proxy and Valgrind for Helgrind, with output discarded.
  • update-ca-certificates refreshes the system's list of trusted certificate authorities, with errors ignored.

Why: everything later depends on these tools existing, so they are installed first in a known-clean system.

Step 2: configure and build libcurl

Bash
docker run --rm -it -v "$PWD":/src -w /src ubuntu:24.04 bash -lc '
  set -euo pipefail
  if [ -f Makefile ]; then make distclean || true; fi
  if [ -x ./buildconf ]; then ./buildconf; else autoreconf -fi; fi
  export CC=clang CFLAGS="-O0 -g -fno-omit-frame-pointer" LDFLAGS=""
  ./configure --enable-debug --with-gssapi --disable-shared \
    --without-ssl --without-libidn2 --without-libpsl --without-libssh2 \
    --without-brotli --without-zstd --without-nghttp2 --without-nghttp3 --without-ngtcp2
  make -j"$(nproc)"
'

Line by line:

  • if [ -f Makefile ]; then make distclean || true; fi cleans up any previous build so the result is fresh.
  • if [ -x ./buildconf ]; then ./buildconf; else autoreconf -fi; fi regenerates the build scripts, using curl's own helper if present and the standard autotools command otherwise.
  • export CC=clang CFLAGS="-O0 -g -fno-omit-frame-pointer" LDFLAGS="" chooses the clang compiler, turns off optimisation (-O0), keeps debugging information (-g) and keeps stack frames intact (-fno-omit-frame-pointer). All three make the binaries easy to read in Valgrind output.
  • ./configure --enable-debug --with-gssapi --disable-shared ... prepares the build: debug mode on, GSS-API support on, a static library (no shared library), and the optional dependencies switched off to keep the build minimal.
  • make -j"$(nproc)" compiles using all available processor cores.

Why: you need a build you can inspect and that contains the GSS-API code path, without unrelated features adding noise.

Step 3: start a minimal SOCKS5 proxy that selects GSS-API

Bash
docker run --rm -it -v "$PWD":/src -w /src ubuntu:24.04 bash -lc '
  set -euo pipefail
  cat > proxy.py <<PY
import socket, threading, struct

def handle(c):
    try:
        data=c.recv(262)
        if len(data)<3: return
        c.sendall(b"\x05\x01")
        hdr=c.recv(4)
        if len(hdr)<4: return
        ln=struct.unpack("!H", hdr[2:4])[0]
        _=c.recv(ln)
        c.sendall(b"\x01\x01\x00\x01D")
        hdr=c.recv(4)
        if len(hdr)<4: return
        ln=struct.unpack("!H", hdr[2:4])[0]
        _=c.recv(ln)
        c.sendall(b"\x01\x02\x00\x01\x00")
    finally:
        try: c.close()
        except: pass

s=socket.socket(); s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
s.bind(("[redacted]",1081)); s.listen()
print("listening [redacted] 1081", flush=True)
while True:
    c,_=s.accept()
    threading.Thread(target=handle,args=(c,),daemon=True).start()
PY
  python3 proxy.py &
  sleep 1
'

Line by line:

  • cat > proxy.py <<PY ... PY writes the Python program between the markers into a file called proxy.py.
  • import socket, threading, struct loads Python's networking, threading and binary-packing modules.
  • def handle(c): defines what to do with one incoming connection c.
  • data=c.recv(262) reads the client's opening message (up to 262 bytes).
  • if len(data)<3: return gives up if the message is too short to be valid.
  • c.sendall(b"\x05\x01") replies with two bytes, \x05 and \x01.
  • hdr=c.recv(4) reads the next four-byte header.
  • ln=struct.unpack("!H", hdr[2:4])[0] reads the last two header bytes as a big-endian number, the length of the address that follows.
  • _=c.recv(ln) reads and discards that address.
  • c.sendall(b"\x01\x01\x00\x01D") sends a reply.
  • The next four lines repeat the same pattern: read a header, read a length, read the body, then c.sendall(b"\x01\x02\x00\x01\x00") sends a second reply.
  • finally: try: c.close() except: pass closes the connection whatever happened.
  • s=socket.socket(); s.setsockopt(...) creates a listening socket and allows the address to be reused quickly.
  • s.bind(("[redacted]",1081)); s.listen() listens on port 1081 on all network interfaces.
  • while True: c,_=s.accept() accepts connections forever, and threading.Thread(...).start() handles each one in its own thread.
  • python3 proxy.py & runs the proxy in the background, and sleep 1 waits a moment for it to start.

Why: the proxy does not need to forward anything real. Its job is to answer the SOCKS5 handshake in a way that makes libcurl call the GSS init routine, repeatedly and concurrently.

Step 4: build the multithreaded PoC

Bash
docker run --rm -it -v "$PWD":/src -w /src ubuntu:24.04 bash -lc '
  set -euo pipefail
  cat > test_gss_race.c <<C
#include <pthread.h>
#include <curl/curl.h>
static void *worker(void *u){
  CURL *e=curl_easy_init();
  curl_easy_setopt(e,CURLOPT_URL,(char*)u);
  curl_easy_setopt(e,CURLOPT_PROXY,"socks5://[redacted]:1081");
  curl_easy_setopt(e,CURLOPT_SOCKS5_GSSAPI_SERVICE,"rcmd");
  curl_easy_setopt(e,CURLOPT_SOCKS5_AUTH,(long)CURLAUTH_GSSAPI);
  for(int i=0;i<50;++i) curl_easy_perform(e);
  curl_easy_cleanup(e);
  return 0;
}
int main(void){
  curl_global_init(CURL_GLOBAL_DEFAULT);
  enum { N=16 }; pthread_t th[N];
  for(int i=0;i<N;++i) pthread_create(&th[i],0,worker,"http://example.com");
  for(int i=0;i<N;++i) pthread_join(th[i],0);
  curl_global_cleanup();
  return 0;
}
C
  clang -O0 -g -Iinclude test_gss_race.c -Llib/.libs -lcurl -lgssapi_krb5 -lpthread -o test_gss_race
'

Line by line:

  • #include <pthread.h> and #include <curl/curl.h> bring in the threading library and libcurl's functions.
  • static void *worker(void *u){ defines the function each thread runs; u is the URL it was given.
  • CURL *e=curl_easy_init(); creates a fresh easy handle, so each thread has its own transfer object.
  • curl_easy_setopt(e,CURLOPT_URL,(char*)u); sets the destination URL.
  • curl_easy_setopt(e,CURLOPT_PROXY,"socks5://[redacted]:1081"); points the transfer at the local SOCKS5 proxy.
  • curl_easy_setopt(e,CURLOPT_SOCKS5_GSSAPI_SERVICE,"rcmd"); sets the GSS-API service name to rcmd.
  • curl_easy_setopt(e,CURLOPT_SOCKS5_AUTH,(long)CURLAUTH_GSSAPI); forces GSS-API authentication for the proxy.
  • for(int i=0;i<50;++i) curl_easy_perform(e); performs 50 transfers, giving plenty of chances for overlap.
  • curl_easy_cleanup(e); frees the handle.
  • int main(void){ starts the program.
  • curl_global_init(CURL_GLOBAL_DEFAULT); initialises libcurl once for the whole process.
  • enum { N=16 }; pthread_t th[N]; declares 16 thread identifiers.
  • for(int i=0;i<N;++i) pthread_create(&th[i],0,worker,"http://example.com"); starts 16 threads, all running worker against the same URL.
  • for(int i=0;i<N;++i) pthread_join(th[i],0); waits for all 16 to finish.
  • curl_global_cleanup(); tidies up libcurl.
  • The clang line compiles the program, linking against the freshly built static libcurl (-Llib/.libs -lcurl), Kerberos (-lgssapi_krb5) and the threading library (-lpthread), producing a binary called test_gss_race.

Why: 16 handles negotiating at once against the same process-wide gss_context is what turns the shared global into an observable race. One connection alone would never show it.

Step 5: run under Helgrind with the GSS stub

Bash
docker run --rm -it -v "$PWD":/src -w /src ubuntu:24.04 bash -lc '
  set -euo pipefail
  export CURL_STUB_GSS_CREDS=KRB5
  valgrind --tool=helgrind --quiet --fair-sched=try ./test_gss_race | tee docker_helgrind.log
'

Line by line:

  • export CURL_STUB_GSS_CREDS=KRB5 selects curl's debug-build GSS stub, which removes noise from inside the real Kerberos library.
  • valgrind --tool=helgrind runs the program under the Helgrind race detector.
  • --quiet hides Valgrind's usual startup chatter so the race reports stand out.
  • --fair-sched=try is passed to Helgrind.
  • ./test_gss_race is the program from step 4.
  • | tee docker_helgrind.log shows the output on screen and saves a copy to docker_helgrind.log.

Why: this is the moment of proof. The detector watches every memory access by every thread and reports pairs that conflict.

Step 6: confirm the race points at the global

Look in the log for lines similar to:

Text
Possible data race ...
... Curl_SOCKS5_gssapi_negotiate (socks_gssapi.c:184)
... Address ... is 0 bytes inside data symbol "gss_context"

Line by line:

  • Possible data race ... is Helgrind's headline for a conflicting pair of accesses.
  • ... Curl_SOCKS5_gssapi_negotiate (socks_gssapi.c:184) shows the call stack passes through the SOCKS5 negotiation function, so the race happens during proxy authentication.
  • ... Address ... is 0 bytes inside data symbol "gss_context" shows the memory involved is the shared variable itself.

The two things that matter are the call site in socks_gssapi.c and the address being inside the gss_context data symbol. Both appear in the run, which is what makes this a confirmed race on the shared context rather than a generic threading warning.

Root cause

gss_context is a file-scope static in lib/socks_gssapi.c, initialised to GSS_C_NO_CONTEXT. Every SOCKS5 GSS-API negotiation in the process passes &gss_context into Curl_gss_init_sec_context, which forwards it to the GSS implementation. The GSS init routine reads the existing context and writes the updated one back through that pointer. When two connections negotiate concurrently, one thread's write and another thread's read of the same eight-byte object are unordered, which is a data race and therefore undefined behaviour in C.

The design offers no per-handle or per-connection storage for the context and no lock around the shared one, so nothing in the code prevents the overlap. The race detector output shows the read and the conflicting write both reached through Curl_SOCKS5_gssapi_negotiate, confirming that the two sides of the race are two concurrent negotiations.

Impact

The report describes the verified impact as concurrency-related instability when multiple handles or authentications run concurrently. Specifically, it lists a realistic risk of a process crash or denial of service caused by undefined behaviour and races in GSS context handling, and of authentication failures or misbehaviour during SOCKS5 proxy negotiation under load.

The researcher explicitly did not observe or claim memory disclosure or remote code execution. The impact is bounded to instability and failed or incorrect authentication in a process that performs concurrent SOCKS5 GSS-API negotiations.

Fix

The report does not describe a fix or a patch. The report does not describe a fix or a patch, and does not state which approach was taken.

Variants to test

  • Other protocol handlers that keep GSS or authentication state in file-scope statics. A positive result is a Helgrind or ThreadSanitizer report whose address falls inside a named data symbol and whose stack passes through the negotiation function for that protocol.
  • The same SOCKS5 GSS-API path with more threads and more iterations than the 16 by 50 used here. A positive result is the same gss_context race appearing more often, or additional races on neighbouring state in the same file.
  • The same path against a real MIT Kerberos setup rather than the debug-build stub. A positive result is a race report that still names curl frames, or observable authentication failures or crashes under concurrent load.
  • Anywhere a library hands the address of a process-wide object to a callback or third-party routine that both reads and writes it. A positive result is a detector report showing a read in one thread conflicting with a write in another on that object.
  • Running the same concurrent workload under ThreadSanitizer as a second opinion. A positive result is a matching race report on the same symbol and call site.

Glossary

  • libcurl: a library of ready-made code that programs use to make network transfers; the engine behind the curl tool.
  • Proxy: a middleman server that makes network connections on your behalf.
  • SOCKS5: a protocol for asking a proxy to connect somewhere for you.
  • GSS-API: a standard interface for authentication systems; here it is used to prove identity to a proxy.
  • Kerberos: an authentication system, common in company networks, that issues tickets to prove identity.
  • Negotiation: the back-and-forth conversation in which two sides agree on how to authenticate.
  • Context: the state built up during an authentication conversation.
  • Easy handle: libcurl's object representing one transfer, created with curl_easy_init.
  • Thread: an independent sequence of instructions running inside the same program, sharing its memory.
  • Race condition: a bug where the result depends on the unpredictable timing of two or more threads.
  • Data race: two threads accessing the same memory at the same time, at least one writing, with no coordination.
  • Undefined behaviour: a situation the C language makes no promises about; anything can happen, including crashes.
  • File-scope static: a variable declared once for a whole source file and shared by all code in it.
  • Helgrind: a Valgrind tool that detects data races by watching thread memory accesses.
  • Valgrind: a suite of debugging and analysis tools for compiled programs.
  • ThreadSanitizer: another race-detection tool, used as a second opinion.
  • Docker container: an isolated, disposable mini-system running inside your computer.
  • Denial of service (DoS): making a program or service unusable, for example by crashing it.
  • Remote code execution (RCE): an attacker running their own code on a victim's machine; not claimed here.
  • Memory disclosure: leaking the contents of memory to someone who should not see it; not claimed here.
  • PoC (proof of concept): a small program that demonstrates a bug really happens.
  • Call site: the place in the code where a function is called.
  • Symbol: the name a compiled program gives to a variable or function, used in debugger and tool output.

More by giant_anteater

View all

93 more disclosed reports, best first.

More from curl

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.