public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [rpms/curl] f44: Resolves: CVE-2026-19931 - Negotiate ambient user conn reuse
@ 2026-10-08 13:39 Jan Macku
0 siblings, 0 replies; only message in thread
From: Jan Macku @ 2026-10-08 13:39 UTC (permalink / raw)
To: git-commits
A new commit has been pushed.
Repo : rpms/curl
Branch : f44
Commit : 03b84d9b58144742fd85f94c66b055062b5998e3
Author : Jan Macku <jamacku@redhat.com>
Date : 2026-10-08T14:21:25+02:00
Stats : +1623/-1 in 2 file(s)
URL : https://src.fedoraproject.org/rpms/curl/c/03b84d9b58144742fd85f94c66b055062b5998e3?branch=f44
Log:
Resolves: CVE-2026-19931 - Negotiate ambient user conn reuse
Co-authored-by: Cursor <cursoragent@cursor.com>
---
diff --git a/0029-curl-8.18.0-CVE-2026-19931.patch b/0029-curl-8.18.0-CVE-2026-19931.patch
new file mode 100644
index 0000000..e5e191c
--- /dev/null
+++ b/0029-curl-8.18.0-CVE-2026-19931.patch
@@ -0,0 +1,1616 @@
+From 219c2096e3d597dbb540b0fbb6ec2e9dfaaa2ec3 Mon Sep 17 00:00:00 2001
+From: Jan Macku <jamacku@redhat.com>
+Date: Thu, 8 Oct 2026 10:10:56 +0200
+Subject: [PATCH] connections: use admin handles only for maintenance
+
+Maintenance tasks like connection upkeep, liveliness checks and cache
+eviction must only run on an admin handle, not the application transfer
+from the calling context.
+
+Then application transfers will get only attached to the connections
+they actually work on. This makes `data->state.lastconnect_id`
+meaningful for checks if a subsequent address is finding the previous
+connection again.
+
+One thing led to another:
+- add Curl_get_admin(data), to obtain an admin handle for
+ an application handle, inheriting some properties for
+ connection operation.
+- rename `Curl_easy *data` parameter to `Curl_easy *admin`
+ where only admin handles should be passed. Add DEBUGASSERTs
+ in the called function.
+- add Curl_share_lock_share(), Curl_share_unlock_share()
+ so it possible to operate on a share without the passed
+ easy handle having the share set.
+ This catches a case where a shared needed to be locked
+ but was not before. Adjust test1554 results.
+
+Fixes #22567
+Reported-by: cybertron10 on github
+Closes #22572
+
+(cherry picked from commit 7103a93b05bc69ea98ed9d05d02fa9eeba533f2f)
+Co-authored-by: Cursor <cursoragent@cursor.com>
+---
+ lib/conncache.c | 190 ++++++++++++++++++++++++++++----------------
+ lib/conncache.h | 23 +++---
+ lib/cshutdn.c | 166 +++++++++++++++++++-------------------
+ lib/cshutdn.h | 28 +++----
+ lib/curl_share.c | 28 +++++--
+ lib/curl_share.h | 8 ++
+ lib/curl_trc.c | 3 +-
+ lib/easy.c | 9 +--
+ lib/getinfo.c | 3 +-
+ lib/multi.c | 28 ++++---
+ lib/multiif.h | 3 +-
+ lib/url.c | 44 ++++++++--
+ lib/url.h | 6 ++
+ lib/urldata.h | 4 +-
+ tests/data/test1554 | 2 +
+ 15 files changed, 325 insertions(+), 220 deletions(-)
+
+diff --git a/lib/conncache.c b/lib/conncache.c
+index 1a3dba7f63..a152f95b60 100644
+--- a/lib/conncache.c
++++ b/lib/conncache.c
+@@ -45,7 +45,7 @@
+ do { \
+ if(c) { \
+ if(CURL_SHARE_KEEP_CONNECT((c)->share)) \
+- Curl_share_lock((d), CURL_LOCK_DATA_CONNECT, \
++ Curl_share_lock_share((c)->share, (d), CURL_LOCK_DATA_CONNECT, \
+ CURL_LOCK_ACCESS_SINGLE); \
+ DEBUGASSERT(!(c)->locked); \
+ (c)->locked = TRUE; \
+@@ -58,7 +58,7 @@
+ DEBUGASSERT((c)->locked); \
+ (c)->locked = FALSE; \
+ if(CURL_SHARE_KEEP_CONNECT((c)->share)) \
+- Curl_share_unlock((d), CURL_LOCK_DATA_CONNECT); \
++ Curl_share_unlock_share((c)->share, (d), CURL_LOCK_DATA_CONNECT); \
+ } \
+ } while(0)
+
+@@ -74,6 +74,15 @@ static void cpool_discard_conn(struct cpool *cpool,
+ struct connectdata *conn,
+ bool aborted);
+
++static void cpool_conn_close(struct cpool *cpool,
++ struct Curl_easy *data,
++ struct connectdata *conn,
++ bool aborted);
++
++static void cpool_evict_conn(struct cpool *cpool,
++ struct Curl_easy *admin,
++ struct connectdata *conn);
++
+ static struct cpool_bundle *cpool_bundle_create(const char *dest)
+ {
+ struct cpool_bundle *bundle;
+@@ -119,16 +128,12 @@ static void cpool_bundle_free_entry(void *freethis)
+ }
+
+ void Curl_cpool_init(struct cpool *cpool,
+- struct Curl_easy *idata,
+ struct Curl_share *share,
+ size_t size)
+ {
+ Curl_hash_init(&cpool->dest2bundle, size, Curl_hash_str,
+ curlx_str_key_compare, cpool_bundle_free_entry);
+
+- DEBUGASSERT(idata);
+-
+- cpool->idata = idata;
+ cpool->share = share;
+ cpool->initialised = TRUE;
+ }
+@@ -189,25 +194,25 @@ static void cpool_remove_conn(struct cpool *cpool,
+ }
+ }
+
+-void Curl_cpool_destroy(struct cpool *cpool)
++void Curl_cpool_destroy(struct cpool *cpool, struct Curl_easy *admin)
+ {
+- if(cpool && cpool->initialised && cpool->idata) {
++ if(cpool && cpool->initialised && admin) {
+ struct connectdata *conn;
+ SIGPIPE_VARIABLE(pipe_st);
+
+- CURL_TRC_M(cpool->idata, "%s[CPOOL] destroy, %zu connections",
++ CURL_TRC_M(admin, "%s[CPOOL] destroy, %zu connections",
+ cpool->share ? "[SHARE] " : "", cpool->num_conn);
+ /* Move all connections to the shutdown list */
+ sigpipe_init(&pipe_st);
+- CPOOL_LOCK(cpool, cpool->idata);
++ CPOOL_LOCK(cpool, admin);
+ conn = cpool_get_first(cpool);
+ while(conn) {
+ cpool_remove_conn(cpool, conn);
+- sigpipe_apply(cpool->idata, &pipe_st);
+- cpool_discard_conn(cpool, cpool->idata, conn, FALSE);
++ sigpipe_apply(admin, &pipe_st);
++ cpool_discard_conn(cpool, admin, conn, FALSE);
+ conn = cpool_get_first(cpool);
+ }
+- CPOOL_UNLOCK(cpool, cpool->idata);
++ CPOOL_UNLOCK(cpool, admin);
+ sigpipe_restore(&pipe_st);
+ Curl_hash_destroy(&cpool->dest2bundle);
+ }
+@@ -226,6 +231,11 @@ static struct cpool *cpool_get_instance(struct Curl_easy *data)
+ return NULL;
+ }
+
++struct cpool *Curl_cpool_get_instance(struct Curl_easy *data)
++{
++ return cpool_get_instance(data);
++}
++
+ void Curl_cpool_xfer_init(struct Curl_easy *data)
+ {
+ struct cpool *cpool = cpool_get_instance(data);
+@@ -327,10 +337,28 @@ static struct connectdata *cpool_get_oldest_idle(struct cpool *cpool,
+ return oldest_idle;
+ }
+
++/* Evict an idle connection to make room in the pool. A pool owned by
++ * a share has no multi that could perform a controlled shutdown of the
++ * connection; terminate it right away. Otherwise, hand it to the
++ * transfer's multi for shutdown. Expects the pool to be locked. */
++static void cpool_evict_conn(struct cpool *cpool,
++ struct Curl_easy *admin,
++ struct connectdata *conn)
++{
++ if(cpool->share) {
++ cpool_remove_conn(cpool, conn);
++ Curl_cshutdn_terminate(admin, conn, TRUE);
++ }
++ else
++ cpool_conn_close(cpool, admin, conn, FALSE);
++}
++
+ int Curl_cpool_check_limits(struct Curl_easy *data,
+ struct connectdata *conn)
+ {
+ struct cpool *cpool = cpool_get_instance(data);
++ struct cshutdn *cshutdn = Curl_cshutdn_get(data);
++ struct Curl_easy *admin;
+ struct cpool_bundle *bundle;
+ size_t dest_limit = 0;
+ size_t total_limit = 0;
+@@ -340,25 +368,26 @@ int Curl_cpool_check_limits(struct Curl_easy *data,
+ if(!cpool)
+ return CPOOL_LIMIT_OK;
+
+- if(cpool->idata->multi) {
+- dest_limit = cpool->idata->multi->max_host_connections;
+- total_limit = cpool->idata->multi->max_total_connections;
++ if(data->multi) {
++ dest_limit = data->multi->max_host_connections;
++ total_limit = data->multi->max_total_connections;
+ }
+
+ if(!dest_limit && !total_limit)
+ return CPOOL_LIMIT_OK;
+
+- CPOOL_LOCK(cpool, cpool->idata);
++ admin = Curl_get_admin(data);
++ CPOOL_LOCK(cpool, admin);
+ if(dest_limit) {
+ size_t live;
+
+ bundle = cpool_find_bundle(cpool, conn);
+ live = bundle ? Curl_llist_count(&bundle->conns) : 0;
+- shutdowns = Curl_cshutdn_dest_count(data, conn->destination);
++ shutdowns = Curl_cshutdn_dest_count(cshutdn, conn->destination);
+ while((live + shutdowns) >= dest_limit) {
+ if(shutdowns) {
+ /* close one connection in shutdown right away, if we can */
+- if(!Curl_cshutdn_close_oldest(data, conn->destination))
++ if(!Curl_cshutdn_close_oldest(cshutdn, conn->destination))
+ break;
+ }
+ else if(!bundle)
+@@ -372,17 +401,17 @@ int Curl_cpool_check_limits(struct Curl_easy *data,
+ if(!oldest_idle)
+ break;
+ /* disconnect the old conn and continue */
+- CURL_TRC_M(data, "Discarding connection #%" FMT_OFF_T
++ CURL_TRC_M(admin, "Discarding connection #%" FMT_OFF_T
+ " from %zu to reach destination limit of %zu",
+ oldest_idle->connection_id,
+ Curl_llist_count(&bundle->conns), dest_limit);
+- Curl_conn_terminate(cpool->idata, oldest_idle, FALSE);
++ cpool_evict_conn(cpool, admin, oldest_idle);
+
+ /* in case the bundle was destroyed in disconnect, look it up again */
+ bundle = cpool_find_bundle(cpool, conn);
+ live = bundle ? Curl_llist_count(&bundle->conns) : 0;
+ }
+- shutdowns = Curl_cshutdn_dest_count(cpool->idata, conn->destination);
++ shutdowns = Curl_cshutdn_dest_count(cshutdn, conn->destination);
+ }
+ if((live + shutdowns) >= dest_limit) {
+ result = CPOOL_LIMIT_DEST;
+@@ -391,11 +420,11 @@ int Curl_cpool_check_limits(struct Curl_easy *data,
+ }
+
+ if(total_limit) {
+- shutdowns = Curl_cshutdn_count(cpool->idata);
++ shutdowns = Curl_cshutdn_count(cshutdn);
+ while((cpool->num_conn + shutdowns) >= total_limit) {
+ if(shutdowns) {
+ /* close one connection in shutdown right away, if we can */
+- if(!Curl_cshutdn_close_oldest(data, NULL))
++ if(!Curl_cshutdn_close_oldest(cshutdn, NULL))
+ break;
+ }
+ else {
+@@ -404,13 +433,13 @@ int Curl_cpool_check_limits(struct Curl_easy *data,
+ if(!oldest_idle)
+ break;
+ /* disconnect the old conn and continue */
+- CURL_TRC_M(data, "Discarding connection #%"
++ CURL_TRC_M(admin, "Discarding connection #%"
+ FMT_OFF_T " from %zu to reach total "
+ "limit of %zu",
+ oldest_idle->connection_id, cpool->num_conn, total_limit);
+- Curl_conn_terminate(cpool->idata, oldest_idle, FALSE);
++ cpool_evict_conn(cpool, admin, oldest_idle);
+ }
+- shutdowns = Curl_cshutdn_count(cpool->idata);
++ shutdowns = Curl_cshutdn_count(cshutdn);
+ }
+ if((cpool->num_conn + shutdowns) >= total_limit) {
+ result = CPOOL_LIMIT_TOTAL;
+@@ -419,7 +448,7 @@ int Curl_cpool_check_limits(struct Curl_easy *data,
+ }
+
+ out:
+- CPOOL_UNLOCK(cpool, cpool->idata);
++ CPOOL_UNLOCK(cpool, admin);
+ return result;
+ }
+
+@@ -472,7 +501,8 @@ out:
+ static bool cpool_foreach(struct Curl_easy *data,
+ struct cpool *cpool,
+ void *param,
+- int (*func)(struct Curl_easy *data,
++ int (*func)(struct cpool *cpool,
++ struct Curl_easy *data,
+ struct connectdata *conn, void *param))
+ {
+ struct Curl_hash_iterator iter;
+@@ -496,7 +526,7 @@ static bool cpool_foreach(struct Curl_easy *data,
+ struct connectdata *conn = Curl_node_elem(curr);
+ curr = Curl_node_next(curr);
+
+- if(func(data, conn, param) == 1) {
++ if(func(cpool, data, conn, param) == 1) {
+ return TRUE;
+ }
+ }
+@@ -533,8 +563,11 @@ bool Curl_cpool_conn_now_idle(struct Curl_easy *data,
+ if(cpool && maxconnects) {
+ /* may be called form a callback already under lock */
+ bool do_lock = !CPOOL_IS_LOCKED(cpool);
++ struct Curl_easy *admin;
++
++ admin = Curl_get_admin(data);
+ if(do_lock)
+- CPOOL_LOCK(cpool, data);
++ CPOOL_LOCK(cpool, admin);
+ if(cpool->num_conn > maxconnects) {
+ infof(data, "Connection pool is full, closing the oldest of %zu/%u",
+ cpool->num_conn, maxconnects);
+@@ -542,11 +575,11 @@ bool Curl_cpool_conn_now_idle(struct Curl_easy *data,
+ oldest_idle = cpool_get_oldest_idle(cpool, Curl_pgrs_now(data));
+ kept = (oldest_idle != conn);
+ if(oldest_idle) {
+- Curl_conn_terminate(data, oldest_idle, FALSE);
++ cpool_evict_conn(cpool, admin, oldest_idle);
+ }
+ }
+ if(do_lock)
+- CPOOL_UNLOCK(cpool, data);
++ CPOOL_UNLOCK(cpool, admin);
+ }
+
+ return kept;
+@@ -597,6 +630,8 @@ static void cpool_discard_conn(struct cpool *cpool,
+ struct connectdata *conn,
+ bool aborted)
+ {
++ struct cshutdn *cshutdn;
++ struct Curl_easy *admin;
+ bool done = FALSE;
+
+ DEBUGASSERT(data);
+@@ -604,12 +639,13 @@ static void cpool_discard_conn(struct cpool *cpool,
+ DEBUGASSERT(cpool);
+ DEBUGASSERT(!conn->bits.in_cpool);
+
++ admin = Curl_get_admin(data);
+ /*
+ * If this connection is not marked to force-close, leave it open if there
+ * are other users of it
+ */
+ if(CONN_INUSE(conn) && !aborted) {
+- CURL_TRC_M(data, "[CPOOL] not discarding #%" FMT_OFF_T
++ CURL_TRC_M(admin, "[CPOOL] not discarding #%" FMT_OFF_T
+ " still in use by %u transfers", conn->connection_id,
+ conn->attached_xfers);
+ return;
+@@ -630,20 +666,22 @@ static void cpool_discard_conn(struct cpool *cpool,
+ done = TRUE;
+ if(!done) {
+ /* Attempt to shutdown the connection right away. */
+- Curl_cshutdn_run_once(cpool->idata, conn, &done);
++ Curl_conn_shutdown_once(admin, conn, &done);
+ }
+
+- if(done || !data->multi)
+- Curl_cshutdn_terminate(cpool->idata, conn, FALSE);
++ cshutdn = Curl_cshutdn_get(data);
++ if(done || !cshutdn)
++ Curl_cshutdn_terminate(admin, conn, FALSE);
+ else
+- Curl_cshutdn_add(&data->multi->cshutdn, conn, cpool->num_conn);
++ Curl_cshutdn_add(cshutdn, conn, cpool->num_conn);
+ }
+
+-void Curl_conn_terminate(struct Curl_easy *data,
+- struct connectdata *conn,
+- bool aborted)
++static void cpool_conn_close(struct cpool *cpool,
++ struct Curl_easy *data,
++ struct connectdata *conn,
++ bool aborted)
+ {
+- struct cpool *cpool = cpool_get_instance(data);
++ struct Curl_easy *admin;
+ bool do_lock;
+
+ DEBUGASSERT(cpool);
+@@ -661,9 +699,10 @@ void Curl_conn_terminate(struct Curl_easy *data,
+
+ /* This method may be called while we are under lock, e.g. from a
+ * user callback in find. */
++ admin = Curl_get_admin(data);
+ do_lock = !CPOOL_IS_LOCKED(cpool);
+ if(do_lock)
+- CPOOL_LOCK(cpool, data);
++ CPOOL_LOCK(cpool, admin);
+
+ if(conn->bits.in_cpool) {
+ cpool_remove_conn(cpool, conn);
+@@ -684,11 +723,19 @@ void Curl_conn_terminate(struct Curl_easy *data,
+ else {
+ /* No multi available, terminate */
+ infof(data, "closing connection #%" FMT_OFF_T, conn->connection_id);
+- Curl_cshutdn_terminate(cpool->idata, conn, !aborted);
++ Curl_cshutdn_terminate(admin, conn, !aborted);
+ }
+
+ if(do_lock)
+- CPOOL_UNLOCK(cpool, data);
++ CPOOL_UNLOCK(cpool, admin);
++}
++
++void Curl_conn_terminate(struct Curl_easy *data,
++ struct connectdata *conn,
++ bool aborted)
++{
++ struct cpool *cpool = cpool_get_instance(data);
++ cpool_conn_close(cpool, data, conn, aborted);
+ }
+
+ struct cpool_reaper_ctx {
+@@ -696,7 +743,8 @@ struct cpool_reaper_ctx {
+ size_t reaped;
+ };
+
+-static int cpool_reap_dead_cb(struct Curl_easy *data,
++static int cpool_reap_dead_cb(struct cpool *cpool,
++ struct Curl_easy *admin,
+ struct connectdata *conn, void *param)
+ {
+ struct cpool_reaper_ctx *reaper = param;
+@@ -704,12 +752,12 @@ static int cpool_reap_dead_cb(struct Curl_easy *data,
+
+ if(!terminate) {
+ reaper->checked++;
+- terminate = Curl_conn_seems_dead(conn, data);
++ terminate = Curl_conn_seems_dead(conn, admin);
+ }
+ if(terminate) {
+ /* stop the iteration here, pass back the connection that was pruned */
+ reaper->reaped++;
+- Curl_conn_terminate(data, conn, FALSE);
++ cpool_conn_close(cpool, admin, conn, FALSE);
+ return 1;
+ }
+ return 0; /* continue iteration */
+@@ -722,31 +770,35 @@ static int cpool_reap_dead_cb(struct Curl_easy *data,
+ *
+ * When called, this transfer has no connection attached.
+ */
+-void Curl_cpool_prune_dead(struct Curl_easy *data)
++void Curl_cpool_prune_dead(struct cpool *cpool,
++ struct Curl_easy *data)
+ {
+- struct cpool *cpool = cpool_get_instance(data);
++ struct Curl_easy *admin;
+ struct cpool_reaper_ctx reaper;
+ timediff_t elapsed;
+
+ if(!cpool)
+ return;
+
++ admin = Curl_get_admin(data);
+ memset(&reaper, 0, sizeof(reaper));
+- CPOOL_LOCK(cpool, data);
++ CPOOL_LOCK(cpool, admin);
+ elapsed = curlx_ptimediff_ms(Curl_pgrs_now(data), &cpool->last_cleanup);
+
+ if(elapsed >= 1000L) {
+- while(cpool_foreach(data, cpool, &reaper, cpool_reap_dead_cb))
++ while(cpool_foreach(admin, cpool, &reaper, cpool_reap_dead_cb))
+ ;
+ cpool->last_cleanup = *Curl_pgrs_now(data);
+ }
+- CPOOL_UNLOCK(cpool, data);
++ CPOOL_UNLOCK(cpool, admin);
+ }
+
+-static int conn_upkeep(struct Curl_easy *data,
++static int conn_upkeep(struct cpool *cpool,
++ struct Curl_easy *data,
+ struct connectdata *conn,
+ void *param)
+ {
++ (void)cpool;
+ (void)param;
+ Curl_conn_upkeep(data, conn);
+ return 0; /* continue iteration */
+@@ -770,10 +822,12 @@ struct cpool_find_ctx {
+ struct connectdata *conn;
+ };
+
+-static int cpool_find_conn(struct Curl_easy *data,
++static int cpool_find_conn(struct cpool *cpool,
++ struct Curl_easy *data,
+ struct connectdata *conn, void *param)
+ {
+ struct cpool_find_ctx *fctx = param;
++ (void)cpool;
+ (void)data;
+ if(conn->connection_id == fctx->id) {
+ fctx->conn = conn;
+@@ -804,10 +858,12 @@ struct cpool_do_conn_ctx {
+ void *cbdata;
+ };
+
+-static int cpool_do_conn(struct Curl_easy *data,
++static int cpool_do_conn(struct cpool *cpool,
++ struct Curl_easy *data,
+ struct connectdata *conn, void *param)
+ {
+ struct cpool_do_conn_ctx *dctx = param;
++ (void)cpool;
+ (void)data;
+ if(conn->connection_id == dctx->id) {
+ dctx->cb(conn, data, dctx->cbdata);
+@@ -846,37 +902,37 @@ void Curl_cpool_do_locked(struct Curl_easy *data,
+ cb(conn, data, cbdata);
+ }
+
+-static int cpool_mark_stale(struct Curl_easy *data,
++static int cpool_mark_stale(struct cpool *cpool,
++ struct Curl_easy *data,
+ struct connectdata *conn, void *param)
+ {
++ (void)cpool;
+ (void)data;
+ (void)param;
+ conn->bits.no_reuse = TRUE;
+ return 0;
+ }
+
+-static int cpool_reap_no_reuse(struct Curl_easy *data,
++static int cpool_reap_no_reuse(struct cpool *cpool,
++ struct Curl_easy *admin,
+ struct connectdata *conn, void *param)
+ {
+- (void)data;
+ (void)param;
+ if(!CONN_INUSE(conn) && conn->bits.no_reuse) {
+- Curl_conn_terminate(data, conn, FALSE);
++ cpool_conn_close(cpool, admin, conn, FALSE);
+ return 1;
+ }
+ return 0; /* continue iteration */
+ }
+
+-void Curl_cpool_nw_changed(struct Curl_easy *data)
++void Curl_cpool_nw_changed(struct cpool *cpool, struct Curl_easy *admin)
+ {
+- struct cpool *cpool = cpool_get_instance(data);
+-
+ if(cpool) {
+- CPOOL_LOCK(cpool, data);
+- cpool_foreach(data, cpool, NULL, cpool_mark_stale);
+- while(cpool_foreach(data, cpool, NULL, cpool_reap_no_reuse))
++ CPOOL_LOCK(cpool, admin);
++ cpool_foreach(admin, cpool, NULL, cpool_mark_stale);
++ while(cpool_foreach(admin, cpool, NULL, cpool_reap_no_reuse))
+ ;
+- CPOOL_UNLOCK(cpool, data);
++ CPOOL_UNLOCK(cpool, admin);
+ }
+ }
+
+diff --git a/lib/conncache.h b/lib/conncache.h
+index 9b392af05c..4acefb0f9e 100644
+--- a/lib/conncache.h
++++ b/lib/conncache.h
+@@ -34,7 +34,7 @@ struct Curl_multi;
+ struct Curl_share;
+
+ /**
+- * Terminate the connection, e.g. close and destroy.
++ * Close and destroy the connection.
+ * If the connection is in a cpool, remove it.
+ * If a `cshutdn` is available (e.g. data has a multi handle),
+ * pass the connection to that for controlled shutdown.
+@@ -43,8 +43,8 @@ struct Curl_share;
+ * `data` should not be attached to a connection.
+ */
+ void Curl_conn_terminate(struct Curl_easy *data,
+- struct connectdata *conn,
+- bool aborted);
++ struct connectdata *conn,
++ bool aborted);
+
+ struct cpool {
+ /* the pooled connections, bundled per destination */
+@@ -53,22 +53,24 @@ struct cpool {
+ curl_off_t next_connection_id;
+ curl_off_t next_easy_id;
+ struct curltime last_cleanup;
+- struct Curl_easy *idata; /* internal handle for maintenance */
+ struct Curl_share *share; /* != NULL if pool belongs to share */
+ BIT(locked);
+ BIT(initialised);
+ };
+
++/* Get connection pool instance for data or NULL if none exists */
++struct cpool *Curl_cpool_get_instance(struct Curl_easy *data);
++
+ /* Init the pool, pass multi only if pool is owned by it.
+ * Cannot fail.
+ */
+ void Curl_cpool_init(struct cpool *cpool,
+- struct Curl_easy *idata,
+ struct Curl_share *share,
+ size_t size);
+
+ /* Destroy all connections and free all members */
+-void Curl_cpool_destroy(struct cpool *connc);
++void Curl_cpool_destroy(struct cpool *cpool,
++ struct Curl_easy *admin);
+
+ /* Init the transfer to be used within its connection pool.
+ * Assigns `data->id`. */
+@@ -126,13 +128,12 @@ bool Curl_cpool_conn_now_idle(struct Curl_easy *data,
+ struct connectdata *conn);
+
+ /**
+- * This function scans the data's connection pool for half-open/dead
++ * Scans the connection pool for half-open/dead
+ * connections, closes and removes them.
+ * The cleanup is done at most once per second.
+- *
+- * When called, this transfer has no connection attached.
+ */
+-void Curl_cpool_prune_dead(struct Curl_easy *data);
++void Curl_cpool_prune_dead(struct cpool *cpool,
++ struct Curl_easy *data);
+
+ /**
+ * Perform upkeep actions on connections in the transfer's pool.
+@@ -162,6 +163,6 @@ void Curl_cpool_do_locked(struct Curl_easy *data,
+ Curl_cpool_conn_do_cb *cb, void *cbdata);
+
+ /* Close all unused connections, prevent reuse of existing ones. */
+-void Curl_cpool_nw_changed(struct Curl_easy *data);
++void Curl_cpool_nw_changed(struct cpool *cpool, struct Curl_easy *admin);
+
+ #endif /* HEADER_CURL_CONNCACHE_H */
+diff --git a/lib/cshutdn.c b/lib/cshutdn.c
+index 84e5b2a116..5610e7070b 100644
+--- a/lib/cshutdn.c
++++ b/lib/cshutdn.c
+@@ -38,6 +38,13 @@
+ #include "curlx/strparse.h"
+
+
++struct cshutdn *Curl_cshutdn_get(struct Curl_easy *data)
++{
++ if(data && data->multi)
++ return &data->multi->cshutdn;
++ return NULL;
++}
++
+ static void cshutdn_run_conn_handler(struct Curl_easy *data,
+ struct connectdata *conn)
+ {
+@@ -103,22 +110,22 @@ static void cshutdn_run_once(struct Curl_easy *data,
+ conn->bits.shutdown_filters = TRUE;
+ }
+
+-void Curl_cshutdn_run_once(struct Curl_easy *data,
++void Curl_conn_shutdown_once(struct Curl_easy *admin,
+ struct connectdata *conn,
+ bool *done)
+ {
+- DEBUGASSERT(!data->conn);
+- Curl_attach_connection(data, conn);
+- cshutdn_run_once(data, conn, done);
+- CURL_TRC_M(data, "[SHUTDOWN] shutdown, done=%d", *done);
+- Curl_detach_connection(data);
++ DEBUGASSERT(!admin->conn);
++ DEBUGASSERT(!admin->mid);
++ Curl_attach_connection(admin, conn, FALSE);
++ cshutdn_run_once(admin, conn, done);
++ CURL_TRC_M(admin, "[SHUTDOWN] shutdown, done=%d", *done);
++ Curl_detach_connection(admin);
+ }
+
+-void Curl_cshutdn_terminate(struct Curl_easy *data,
++void Curl_cshutdn_terminate(struct Curl_easy *admin,
+ struct connectdata *conn,
+ bool do_shutdown)
+ {
+- struct Curl_easy *admin = data;
+ bool done;
+
+ /* there must be a connection to close */
+@@ -126,16 +133,10 @@ void Curl_cshutdn_terminate(struct Curl_easy *data,
+ /* it must be removed from the connection pool */
+ DEBUGASSERT(!conn->bits.in_cpool);
+ /* the transfer must be detached from the connection */
+- DEBUGASSERT(data && !data->conn);
+-
+- /* If we can obtain an internal admin handle, use that to attach
+- * and terminate the connection. Some protocol will try to mess with
+- * `data` during shutdown and we do not want that with a `data` from
+- * the application. */
+- if(data->multi && data->multi->admin)
+- admin = data->multi->admin;
++ DEBUGASSERT(admin && !admin->conn);
++ DEBUGASSERT(!admin->mid);
+
+- Curl_attach_connection(admin, conn);
++ Curl_attach_connection(admin, conn, FALSE);
+
+ cshutdn_run_conn_handler(admin, conn);
+ if(do_shutdown) {
+@@ -150,18 +151,17 @@ void Curl_cshutdn_terminate(struct Curl_easy *data,
+ Curl_conn_close(admin, FIRSTSOCKET);
+ Curl_detach_connection(admin);
+
+- if(data->multi)
+- Curl_multi_ev_conn_done(data->multi, data, conn);
++ if(admin->multi)
++ Curl_multi_ev_conn_done(admin->multi, admin, conn);
+ Curl_conn_free(admin, conn);
+
+- if(data->multi) {
+- CURL_TRC_M(data, "[SHUTDOWN] trigger multi connchanged");
+- Curl_multi_connchanged(data->multi);
++ if(admin->multi) {
++ CURL_TRC_M(admin, "[SHUTDOWN] trigger multi connchanged");
++ Curl_multi_connchanged(admin->multi);
+ }
+ }
+
+ static bool cshutdn_destroy_oldest(struct cshutdn *cshutdn,
+- struct Curl_easy *data,
+ const char *destination)
+ {
+ struct Curl_llist_node *e;
+@@ -180,20 +180,19 @@ static bool cshutdn_destroy_oldest(struct cshutdn *cshutdn,
+ conn = Curl_node_elem(e);
+ Curl_node_remove(e);
+ sigpipe_init(&pipe_st);
+- sigpipe_apply(data, &pipe_st);
+- Curl_cshutdn_terminate(data, conn, FALSE);
++ sigpipe_apply(cshutdn->multi->admin, &pipe_st);
++ Curl_cshutdn_terminate(cshutdn->multi->admin, conn, FALSE);
+ sigpipe_restore(&pipe_st);
+ return TRUE;
+ }
+ return FALSE;
+ }
+
+-bool Curl_cshutdn_close_oldest(struct Curl_easy *data,
++bool Curl_cshutdn_close_oldest(struct cshutdn *cshutdn,
+ const char *destination)
+ {
+- if(data && data->multi) {
+- struct cshutdn *csd = &data->multi->cshutdn;
+- return cshutdn_destroy_oldest(csd, data, destination);
++ if(cshutdn) {
++ return cshutdn_destroy_oldest(cshutdn, destination);
+ }
+ return FALSE;
+ }
+@@ -201,7 +200,6 @@ bool Curl_cshutdn_close_oldest(struct Curl_easy *data,
+ #define NUM_POLLS_ON_STACK 10
+
+ static CURLcode cshutdn_wait(struct cshutdn *cshutdn,
+- struct Curl_easy *data,
+ int timeout_ms)
+ {
+ struct pollfd a_few_on_stack[NUM_POLLS_ON_STACK];
+@@ -210,7 +208,7 @@ static CURLcode cshutdn_wait(struct cshutdn *cshutdn,
+
+ Curl_pollfds_init(&cpfds, a_few_on_stack, NUM_POLLS_ON_STACK);
+
+- result = Curl_cshutdn_add_pollfds(cshutdn, data, &cpfds);
++ result = Curl_cshutdn_add_pollfds(cshutdn, &cpfds);
+ if(result)
+ goto out;
+
+@@ -222,7 +220,7 @@ out:
+ }
+
+ static void cshutdn_perform(struct cshutdn *cshutdn,
+- struct Curl_easy *data)
++ struct Curl_easy *admin)
+ {
+ struct Curl_llist_node *e = Curl_llist_head(&cshutdn->list);
+ struct Curl_llist_node *enext;
+@@ -233,20 +231,20 @@ static void cshutdn_perform(struct cshutdn *cshutdn,
+ if(!e)
+ return;
+
+- CURL_TRC_M(data, "[SHUTDOWN] perform on %zu connections",
++ CURL_TRC_M(admin, "[SHUTDOWN] perform on %zu connections",
+ Curl_llist_count(&cshutdn->list));
+ while(e) {
+ enext = Curl_node_next(e);
+ conn = Curl_node_elem(e);
+- Curl_cshutdn_run_once(data, conn, &done);
++ Curl_conn_shutdown_once(admin, conn, &done);
+ if(done) {
+ Curl_node_remove(e);
+- Curl_cshutdn_terminate(data, conn, FALSE);
++ Curl_cshutdn_terminate(admin, conn, FALSE);
+ }
+ else {
+ /* idata has one timer list, but maybe more than one connection.
+ * Set EXPIRE_SHUTDOWN to the smallest time left for all. */
+- ms = Curl_conn_shutdown_timeleft(data, conn);
++ ms = Curl_conn_shutdown_timeleft(admin, conn);
+ if(ms && ms < next_expire_ms)
+ next_expire_ms = ms;
+ }
+@@ -254,46 +252,43 @@ static void cshutdn_perform(struct cshutdn *cshutdn,
+ }
+
+ if(next_expire_ms)
+- Curl_expire_ex(data, next_expire_ms, EXPIRE_SHUTDOWN);
++ Curl_expire_ex(admin, next_expire_ms, EXPIRE_SHUTDOWN);
+ }
+
+ static void cshutdn_terminate_all(struct cshutdn *cshutdn,
+- struct Curl_easy *data,
+ int timeout_ms)
+ {
+- struct curltime started = *Curl_pgrs_now(data);
++ struct Curl_easy *admin = cshutdn->multi->admin;
++ struct curltime started = *Curl_pgrs_now(admin);
+ struct Curl_llist_node *e;
+ SIGPIPE_VARIABLE(pipe_st);
+
+- DEBUGASSERT(cshutdn);
+- DEBUGASSERT(data);
+-
+- CURL_TRC_M(data, "[SHUTDOWN] shutdown all");
++ CURL_TRC_M(admin, "[SHUTDOWN] shutdown all");
+ sigpipe_init(&pipe_st);
+- sigpipe_apply(data, &pipe_st);
++ sigpipe_apply(admin, &pipe_st);
+
+ while(Curl_llist_head(&cshutdn->list)) {
+ timediff_t spent_ms;
+ int remain_ms;
+
+- cshutdn_perform(cshutdn, data);
++ cshutdn_perform(cshutdn, admin);
+
+ if(!Curl_llist_head(&cshutdn->list)) {
+- CURL_TRC_M(data, "[SHUTDOWN] shutdown finished cleanly");
++ CURL_TRC_M(admin, "[SHUTDOWN] shutdown finished cleanly");
+ break;
+ }
+
+ /* wait for activity, timeout or "nothing" */
+- spent_ms = curlx_ptimediff_ms(Curl_pgrs_now(data), &started);
++ spent_ms = curlx_ptimediff_ms(Curl_pgrs_now(admin), &started);
+ if(spent_ms >= (timediff_t)timeout_ms) {
+- CURL_TRC_M(data, "[SHUTDOWN] shutdown finished, %s",
++ CURL_TRC_M(admin, "[SHUTDOWN] shutdown finished, %s",
+ (timeout_ms > 0) ? "timeout" : "best effort done");
+ break;
+ }
+
+ remain_ms = timeout_ms - (int)spent_ms;
+- if(cshutdn_wait(cshutdn, data, remain_ms)) {
+- CURL_TRC_M(data, "[SHUTDOWN] shutdown finished, aborted");
++ if(cshutdn_wait(cshutdn, remain_ms)) {
++ CURL_TRC_M(admin, "[SHUTDOWN] shutdown finished, aborted");
+ break;
+ }
+ }
+@@ -303,7 +298,7 @@ static void cshutdn_terminate_all(struct cshutdn *cshutdn,
+ while(e) {
+ struct connectdata *conn = Curl_node_elem(e);
+ Curl_node_remove(e);
+- Curl_cshutdn_terminate(data, conn, FALSE);
++ Curl_cshutdn_terminate(admin, conn, FALSE);
+ e = Curl_llist_head(&cshutdn->list);
+ }
+ DEBUGASSERT(!Curl_llist_count(&cshutdn->list));
+@@ -322,9 +317,9 @@ int Curl_cshutdn_init(struct cshutdn *cshutdn,
+ }
+
+ void Curl_cshutdn_destroy(struct cshutdn *cshutdn,
+- struct Curl_easy *data)
++ struct Curl_easy *admin)
+ {
+- if(cshutdn->initialised && data) {
++ if(cshutdn->initialised && admin) {
+ int timeout_ms = 0;
+ /* Just for testing, run graceful shutdown */
+ #ifdef DEBUGBUILD
+@@ -338,29 +333,27 @@ void Curl_cshutdn_destroy(struct cshutdn *cshutdn,
+ }
+ #endif
+
+- CURL_TRC_M(data, "[SHUTDOWN] destroy, %zu connections, timeout=%dms",
++ CURL_TRC_M(admin, "[SHUTDOWN] destroy, %zu connections, timeout=%dms",
+ Curl_llist_count(&cshutdn->list), timeout_ms);
+- cshutdn_terminate_all(cshutdn, data, timeout_ms);
++ cshutdn_terminate_all(cshutdn, timeout_ms);
+ }
+ cshutdn->multi = NULL;
+ }
+
+-size_t Curl_cshutdn_count(struct Curl_easy *data)
++size_t Curl_cshutdn_count(struct cshutdn *cshutdn)
+ {
+- if(data && data->multi) {
+- struct cshutdn *csd = &data->multi->cshutdn;
+- return Curl_llist_count(&csd->list);
++ if(cshutdn) {
++ return Curl_llist_count(&cshutdn->list);
+ }
+ return 0;
+ }
+
+-size_t Curl_cshutdn_dest_count(struct Curl_easy *data,
++size_t Curl_cshutdn_dest_count(struct cshutdn *cshutdn,
+ const char *destination)
+ {
+- if(data && data->multi) {
+- struct cshutdn *csd = &data->multi->cshutdn;
++ if(cshutdn) {
+ size_t n = 0;
+- struct Curl_llist_node *e = Curl_llist_head(&csd->list);
++ struct Curl_llist_node *e = Curl_llist_head(&cshutdn->list);
+ while(e) {
+ struct connectdata *conn = Curl_node_elem(e);
+ if(!strcmp(destination, conn->destination))
+@@ -373,7 +366,7 @@ size_t Curl_cshutdn_dest_count(struct Curl_easy *data,
+ }
+
+ static CURLMcode cshutdn_update_ev(struct cshutdn *cshutdn,
+- struct Curl_easy *data,
++ struct Curl_easy *admin,
+ struct connectdata *conn)
+ {
+ CURLMcode mresult;
+@@ -381,9 +374,9 @@ static CURLMcode cshutdn_update_ev(struct cshutdn *cshutdn,
+ DEBUGASSERT(cshutdn);
+ DEBUGASSERT(cshutdn->multi->socket_cb);
+
+- Curl_attach_connection(data, conn);
+- mresult = Curl_multi_ev_assess_conn(cshutdn->multi, data, conn);
+- Curl_detach_connection(data);
++ Curl_attach_connection(admin, conn, FALSE);
++ mresult = Curl_multi_ev_assess_conn(cshutdn->multi, admin, conn);
++ Curl_detach_connection(admin);
+ return mresult;
+ }
+
+@@ -400,7 +393,7 @@ void Curl_cshutdn_add(struct cshutdn *cshutdn,
+ (conns_in_pool + Curl_llist_count(&cshutdn->list)))) {
+ CURL_TRC_M(data, "[SHUTDOWN] discarding oldest shutdown connection "
+ "due to connection limit of %zu", max_total);
+- cshutdn_destroy_oldest(cshutdn, data, NULL);
++ cshutdn_destroy_oldest(cshutdn, NULL);
+ }
+
+ if(cshutdn->multi->socket_cb) {
+@@ -419,7 +412,7 @@ void Curl_cshutdn_add(struct cshutdn *cshutdn,
+ }
+
+ static void cshutdn_multi_socket(struct cshutdn *cshutdn,
+- struct Curl_easy *data,
++ struct Curl_easy *admin,
+ curl_socket_t s)
+ {
+ struct Curl_llist_node *e;
+@@ -431,10 +424,10 @@ static void cshutdn_multi_socket(struct cshutdn *cshutdn,
+ while(e) {
+ conn = Curl_node_elem(e);
+ if(s == conn->sock[FIRSTSOCKET] || s == conn->sock[SECONDARYSOCKET]) {
+- Curl_cshutdn_run_once(data, conn, &done);
+- if(done || cshutdn_update_ev(cshutdn, data, conn)) {
++ Curl_conn_shutdown_once(admin, conn, &done);
++ if(done || cshutdn_update_ev(cshutdn, admin, conn)) {
+ Curl_node_remove(e);
+- Curl_cshutdn_terminate(data, conn, FALSE);
++ Curl_cshutdn_terminate(admin, conn, FALSE);
+ }
+ break;
+ }
+@@ -446,21 +439,22 @@ void Curl_cshutdn_perform(struct cshutdn *cshutdn,
+ struct Curl_easy *data,
+ curl_socket_t s)
+ {
++ struct Curl_easy *admin = Curl_get_admin(data);
+ if((s == CURL_SOCKET_TIMEOUT) || (!cshutdn->multi->socket_cb))
+- cshutdn_perform(cshutdn, data);
++ cshutdn_perform(cshutdn, admin);
+ else
+- cshutdn_multi_socket(cshutdn, data, s);
++ cshutdn_multi_socket(cshutdn, admin, s);
+ }
+
+ /* return fd_set info about the shutdown connections */
+ void Curl_cshutdn_setfds(struct cshutdn *cshutdn,
+- struct Curl_easy *data,
+ fd_set *read_fd_set, fd_set *write_fd_set,
+ int *maxfd)
+ {
+ if(Curl_llist_head(&cshutdn->list)) {
+ struct Curl_llist_node *e;
+ struct easy_pollset ps;
++ struct Curl_easy *admin = cshutdn->multi->admin;
+
+ Curl_pollset_init(&ps);
+ for(e = Curl_llist_head(&cshutdn->list); e; e = Curl_node_next(e)) {
+@@ -469,9 +463,9 @@ void Curl_cshutdn_setfds(struct cshutdn *cshutdn,
+ CURLcode result;
+
+ Curl_pollset_reset(&ps);
+- Curl_attach_connection(data, conn);
+- result = Curl_conn_adjust_pollset(data, conn, &ps);
+- Curl_detach_connection(data);
++ Curl_attach_connection(admin, conn, FALSE);
++ result = Curl_conn_adjust_pollset(admin, conn, &ps);
++ Curl_detach_connection(admin);
+
+ if(result)
+ continue;
+@@ -502,7 +496,6 @@ void Curl_cshutdn_setfds(struct cshutdn *cshutdn,
+
+ /* return information about the shutdown connections */
+ unsigned int Curl_cshutdn_add_waitfds(struct cshutdn *cshutdn,
+- struct Curl_easy *data,
+ struct Curl_waitfds *cwfds)
+ {
+ unsigned int need = 0;
+@@ -511,15 +504,16 @@ unsigned int Curl_cshutdn_add_waitfds(struct cshutdn *cshutdn,
+ struct Curl_llist_node *e;
+ struct easy_pollset ps;
+ struct connectdata *conn;
++ struct Curl_easy *admin = cshutdn->multi->admin;
+ CURLcode result;
+
+ Curl_pollset_init(&ps);
+ for(e = Curl_llist_head(&cshutdn->list); e; e = Curl_node_next(e)) {
+ conn = Curl_node_elem(e);
+ Curl_pollset_reset(&ps);
+- Curl_attach_connection(data, conn);
+- result = Curl_conn_adjust_pollset(data, conn, &ps);
+- Curl_detach_connection(data);
++ Curl_attach_connection(admin, conn, FALSE);
++ result = Curl_conn_adjust_pollset(admin, conn, &ps);
++ Curl_detach_connection(admin);
+
+ if(!result)
+ need += Curl_waitfds_add_ps(cwfds, &ps);
+@@ -530,7 +524,6 @@ unsigned int Curl_cshutdn_add_waitfds(struct cshutdn *cshutdn,
+ }
+
+ CURLcode Curl_cshutdn_add_pollfds(struct cshutdn *cshutdn,
+- struct Curl_easy *data,
+ struct curl_pollfds *cpfds)
+ {
+ CURLcode result = CURLE_OK;
+@@ -539,14 +532,15 @@ CURLcode Curl_cshutdn_add_pollfds(struct cshutdn *cshutdn,
+ struct Curl_llist_node *e;
+ struct easy_pollset ps;
+ struct connectdata *conn;
++ struct Curl_easy *admin = cshutdn->multi->admin;
+
+ Curl_pollset_init(&ps);
+ for(e = Curl_llist_head(&cshutdn->list); e; e = Curl_node_next(e)) {
+ conn = Curl_node_elem(e);
+ Curl_pollset_reset(&ps);
+- Curl_attach_connection(data, conn);
+- result = Curl_conn_adjust_pollset(data, conn, &ps);
+- Curl_detach_connection(data);
++ Curl_attach_connection(admin, conn, FALSE);
++ result = Curl_conn_adjust_pollset(admin, conn, &ps);
++ Curl_detach_connection(admin);
+
+ if(!result)
+ result = Curl_pollfds_add_ps(cpfds, &ps);
+diff --git a/lib/cshutdn.h b/lib/cshutdn.h
+index 0a15d39f1c..71b99a4e5a 100644
+--- a/lib/cshutdn.h
++++ b/lib/cshutdn.h
+@@ -32,20 +32,20 @@ struct Curl_multi;
+ struct Curl_share;
+
+ /* Run the shutdown of the connection once.
+- * Will shortly attach/detach `data` to `conn` while doing so.
++ * Shortly attach/detach the admin handle to `conn` while doing so.
+ * `done` will be set TRUE if any error was encountered or if
+ * the connection was shut down completely. */
+-void Curl_cshutdn_run_once(struct Curl_easy *data,
+- struct connectdata *conn,
+- bool *done);
++void Curl_conn_shutdown_once(struct Curl_easy *admin,
++ struct connectdata *conn,
++ bool *done);
+
+ /* Terminates the connection, e.g. closes and destroys it.
+ * If `run_shutdown` is TRUE, the shutdown will be run once before
+ * terminating it.
+ * Takes ownership of `conn`. */
+-void Curl_cshutdn_terminate(struct Curl_easy *data,
+- struct connectdata *conn,
+- bool run_shutdown);
++void Curl_cshutdn_terminate(struct Curl_easy *admin,
++ struct connectdata *conn,
++ bool do_shutdown);
+
+ /* A `cshutdown` is always owned by a multi handle to maintain
+ * the connections to be shut down. It registers timers and
+@@ -56,25 +56,28 @@ struct cshutdn {
+ BIT(initialised);
+ };
+
++/* Get the cshutdn instance relevant for `data` or NULL if there is none */
++struct cshutdn *Curl_cshutdn_get(struct Curl_easy *data);
++
+ /* Init as part of the given multi handle. */
+ int Curl_cshutdn_init(struct cshutdn *cshutdn,
+ struct Curl_multi *multi);
+
+ /* Terminate all remaining connections and free resources. */
+ void Curl_cshutdn_destroy(struct cshutdn *cshutdn,
+- struct Curl_easy *data);
++ struct Curl_easy *admin);
+
+ /* Number of connections being shut down. */
+-size_t Curl_cshutdn_count(struct Curl_easy *data);
++size_t Curl_cshutdn_count(struct cshutdn *cshutdn);
+
+ /* Number of connections to the destination being shut down. */
+-size_t Curl_cshutdn_dest_count(struct Curl_easy *data,
++size_t Curl_cshutdn_dest_count(struct cshutdn *cshutdn,
+ const char *destination);
+
+ /* Close the oldest connection in shutdown to destination or,
+ * when destination is NULL for any destination.
+ * Return TRUE if a connection has been closed. */
+-bool Curl_cshutdn_close_oldest(struct Curl_easy *data,
++bool Curl_cshutdn_close_oldest(struct cshutdn *cshutdn,
+ const char *destination);
+
+ /* Add a connection to have it shut down. Will terminate the oldest
+@@ -85,15 +88,12 @@ void Curl_cshutdn_add(struct cshutdn *cshutdn,
+
+ /* Add sockets and POLLIN/OUT flags for connections being shut down. */
+ CURLcode Curl_cshutdn_add_pollfds(struct cshutdn *cshutdn,
+- struct Curl_easy *data,
+ struct curl_pollfds *cpfds);
+
+ unsigned int Curl_cshutdn_add_waitfds(struct cshutdn *cshutdn,
+- struct Curl_easy *data,
+ struct Curl_waitfds *cwfds);
+
+ void Curl_cshutdn_setfds(struct cshutdn *cshutdn,
+- struct Curl_easy *data,
+ fd_set *read_fd_set, fd_set *write_fd_set,
+ int *maxfd);
+
+diff --git a/lib/curl_share.c b/lib/curl_share.c
+index 3ff2755684..426e85a8ae 100644
+--- a/lib/curl_share.c
++++ b/lib/curl_share.c
+@@ -31,6 +31,7 @@
+ #include "hsts.h"
+ #include "url.h"
+
++
+ CURLSH *curl_share_init(void)
+ {
+ struct Curl_share *share = curlx_calloc(1, sizeof(struct Curl_share));
+@@ -128,7 +129,7 @@ CURLSHcode curl_share_setopt(CURLSH *sh, CURLSHoption option, ...)
+ case CURL_LOCK_DATA_CONNECT:
+ /* It is safe to set this option several times on a share. */
+ if(!share->cpool.initialised) {
+- Curl_cpool_init(&share->cpool, share->admin, share, 103);
++ Curl_cpool_init(&share->cpool, share, 103);
+ }
+ break;
+
+@@ -236,7 +237,7 @@ CURLSHcode curl_share_cleanup(CURLSH *sh)
+ }
+
+ if(share->specifier & (1 << CURL_LOCK_DATA_CONNECT)) {
+- Curl_cpool_destroy(&share->cpool);
++ Curl_cpool_destroy(&share->cpool, share->admin);
+ }
+
+ Curl_dnscache_destroy(&share->dnscache);
+@@ -267,11 +268,11 @@ CURLSHcode curl_share_cleanup(CURLSH *sh)
+ return CURLSHE_OK;
+ }
+
+-CURLSHcode Curl_share_lock(struct Curl_easy *data, curl_lock_data type,
+- curl_lock_access accesstype)
++CURLSHcode Curl_share_lock_share(struct Curl_share *share,
++ struct Curl_easy *data,
++ curl_lock_data type,
++ curl_lock_access accesstype)
+ {
+- struct Curl_share *share = data->share;
+-
+ if(!share)
+ return CURLSHE_INVALID;
+
+@@ -284,10 +285,16 @@ CURLSHcode Curl_share_lock(struct Curl_easy *data, curl_lock_data type,
+ return CURLSHE_OK;
+ }
+
+-CURLSHcode Curl_share_unlock(struct Curl_easy *data, curl_lock_data type)
++CURLSHcode Curl_share_lock(struct Curl_easy *data, curl_lock_data type,
++ curl_lock_access accesstype)
+ {
+- struct Curl_share *share = data->share;
++ return Curl_share_lock_share(data->share, data, type, accesstype);
++}
+
++CURLSHcode Curl_share_unlock_share(struct Curl_share *share,
++ struct Curl_easy *data,
++ curl_lock_data type)
++{
+ if(!share)
+ return CURLSHE_INVALID;
+
+@@ -298,3 +305,8 @@ CURLSHcode Curl_share_unlock(struct Curl_easy *data, curl_lock_data type)
+
+ return CURLSHE_OK;
+ }
++
++CURLSHcode Curl_share_unlock(struct Curl_easy *data, curl_lock_data type)
++{
++ return Curl_share_unlock_share(data->share, data, type);
++}
+diff --git a/lib/curl_share.h b/lib/curl_share.h
+index fcd9e32980..9a4fdba392 100644
+--- a/lib/curl_share.h
++++ b/lib/curl_share.h
+@@ -69,6 +69,14 @@ CURLSHcode Curl_share_lock(struct Curl_easy *, curl_lock_data,
+ curl_lock_access);
+ CURLSHcode Curl_share_unlock(struct Curl_easy *, curl_lock_data);
+
++CURLSHcode Curl_share_lock_share(struct Curl_share *share,
++ struct Curl_easy *data,
++ curl_lock_data type,
++ curl_lock_access accesstype);
++CURLSHcode Curl_share_unlock_share(struct Curl_share *share,
++ struct Curl_easy *data,
++ curl_lock_data type);
++
+ /* convenience macro to check if this handle is using a shared SSL spool */
+ #define CURL_SHARE_ssl_scache(data) (data->share && \
+ (data->share->specifier & \
+diff --git a/lib/curl_trc.c b/lib/curl_trc.c
+index 565d1b45f0..6be80f0910 100644
+--- a/lib/curl_trc.c
++++ b/lib/curl_trc.c
+@@ -90,8 +90,7 @@ static struct curl_trc_feat Curl_trc_feat_ids = {
+
+ static size_t trc_print_ids(struct Curl_easy *data, char *buf, size_t maxlen)
+ {
+- curl_off_t cid = data->conn ?
+- data->conn->connection_id : data->state.recent_conn_id;
++ curl_off_t cid = data->state.lastconnect_id;
+ if(data->id >= 0) {
+ if(cid >= 0)
+ return curl_msnprintf(buf, maxlen, CURL_TRC_FMT_IDSDC, data->id, cid);
+diff --git a/lib/easy.c b/lib/easy.c
+index 398b20edd1..dc6a83617f 100644
+--- a/lib/easy.c
++++ b/lib/easy.c
+@@ -977,7 +977,6 @@ CURL *curl_easy_duphandle(CURL *d)
+
+ /* the connection pool is setup on demand */
+ outcurl->state.lastconnect_id = -1;
+- outcurl->state.recent_conn_id = -1;
+ outcurl->id = -1;
+ outcurl->mid = UINT32_MAX;
+ outcurl->master_mid = UINT32_MAX;
+@@ -1109,7 +1108,7 @@ void curl_easy_reset(CURL *d)
+
+ data->progress.hide = TRUE;
+ data->state.current_speed = -1; /* init to negative == impossible */
+- data->state.recent_conn_id = -1; /* clear remembered connection id */
++ data->state.lastconnect_id = -1; /* clear remembered connection id */
+
+ /* zero out authentication data: */
+ memset(&data->state.authhost, 0, sizeof(struct auth));
+@@ -1240,7 +1239,7 @@ CURLcode curl_easy_recv(CURL *d, void *buffer, size_t buflen, size_t *n)
+ if(!data->conn)
+ /* on first invoke, the transfer has been detached from the connection and
+ needs to be reattached */
+- Curl_attach_connection(data, c);
++ Curl_attach_connection(data, c, TRUE);
+
+ *n = 0;
+ return Curl_conn_recv(data, FIRSTSOCKET, buffer, buflen, n);
+@@ -1259,7 +1258,7 @@ CURLcode Curl_connect_only_attach(struct Curl_easy *data)
+ if(!data->conn)
+ /* on first invoke, the transfer has been detached from the connection and
+ needs to be reattached */
+- Curl_attach_connection(data, c);
++ Curl_attach_connection(data, c, TRUE);
+
+ return CURLE_OK;
+ }
+@@ -1285,7 +1284,7 @@ CURLcode Curl_senddata(struct Curl_easy *data, const void *buffer,
+ if(!data->conn)
+ /* on first invoke, the transfer has been detached from the connection and
+ needs to be reattached */
+- Curl_attach_connection(data, c);
++ Curl_attach_connection(data, c, TRUE);
+
+ sigpipe_ignore(data, &pipe_st);
+ result = Curl_conn_send(data, FIRSTSOCKET, buffer, buflen, FALSE, n);
+diff --git a/lib/getinfo.c b/lib/getinfo.c
+index e094ffd134..67b9eeb76c 100644
+--- a/lib/getinfo.c
++++ b/lib/getinfo.c
+@@ -463,8 +463,7 @@ static CURLcode getinfo_offt(struct Curl_easy *data, CURLINFO info,
+ *param_offt = data->id;
+ break;
+ case CURLINFO_CONN_ID:
+- *param_offt = data->conn ?
+- data->conn->connection_id : data->state.recent_conn_id;
++ *param_offt = data->state.lastconnect_id;
+ break;
+ case CURLINFO_EARLYDATA_SENT_T:
+ *param_offt = data->progress.earlydata_sent;
+diff --git a/lib/multi.c b/lib/multi.c
+index 6db86abda2..7691c92629 100644
+--- a/lib/multi.c
++++ b/lib/multi.c
+@@ -280,7 +280,7 @@ struct Curl_multi *Curl_multi_handle(uint32_t xfer_table_size,
+ if(Curl_cshutdn_init(&multi->cshutdn, multi))
+ goto error;
+
+- Curl_cpool_init(&multi->cpool, multi->admin, NULL, chashsize);
++ Curl_cpool_init(&multi->cpool, NULL, chashsize);
+
+ #ifdef USE_SSL
+ if(Curl_ssl_scache_create(sesssize, 2, &multi->ssl_scache))
+@@ -307,7 +307,7 @@ error:
+ Curl_multi_ev_cleanup(multi);
+ Curl_hash_destroy(&multi->proto_hash);
+ Curl_dnscache_destroy(&multi->dnscache);
+- Curl_cpool_destroy(&multi->cpool);
++ Curl_cpool_destroy(&multi->cpool, multi->admin);
+ Curl_cshutdn_destroy(&multi->cshutdn, multi->admin);
+ #ifdef USE_SSL
+ Curl_ssl_scache_destroy(multi->ssl_scache);
+@@ -617,7 +617,6 @@ static void multi_done_locked(struct connectdata *conn,
+ }
+
+ data->state.done = TRUE; /* called just now! */
+- data->state.recent_conn_id = conn->connection_id;
+
+ Curl_resolv_unlink(data, &data->state.dns[0]); /* done with this */
+ Curl_resolv_unlink(data, &data->state.dns[1]);
+@@ -646,7 +645,6 @@ static void multi_done_locked(struct connectdata *conn,
+ /* the connection is no longer in use by any transfer */
+ if(Curl_cpool_conn_now_idle(data, conn)) {
+ /* connection kept in the cpool */
+- data->state.lastconnect_id = conn->connection_id;
+ #ifndef CURL_DISABLE_VERBOSE_STRINGS
+ infof(data, "Connection #%" FMT_OFF_T " to host %s:%d left intact",
+ conn->connection_id, host, port);
+@@ -654,7 +652,6 @@ static void multi_done_locked(struct connectdata *conn,
+ }
+ else {
+ /* connection was removed from the cpool and destroyed. */
+- data->state.lastconnect_id = -1;
+ }
+ }
+ }
+@@ -917,16 +914,21 @@ void Curl_detach_connection(struct Curl_easy *data)
+ /*
+ * Curl_attach_connection() attaches this transfer to this connection.
+ *
+- * This is the only function that should assign data->conn
++ * This is the only function that should assign data->conn.
++ * `matched == TRUE` means the transfer's properties match this
++ * connection and it is not a temporary attach for maintenance.
+ */
+ void Curl_attach_connection(struct Curl_easy *data,
+- struct connectdata *conn)
++ struct connectdata *conn,
++ bool matched)
+ {
+ DEBUGASSERT(data);
+ DEBUGASSERT(!data->conn);
+ DEBUGASSERT(conn);
+ DEBUGASSERT(conn->attached_xfers < UINT32_MAX);
+ data->conn = conn;
++ if(matched)
++ data->state.lastconnect_id = conn->connection_id;
+ conn->attached_xfers++;
+ /* all attached transfers must be from the same multi */
+ if(!conn->attached_multi)
+@@ -1259,7 +1261,7 @@ CURLMcode curl_multi_fdset(CURLM *m,
+ } while(Curl_uint32_bset_next(&multi->process, mid, &mid));
+ }
+
+- Curl_cshutdn_setfds(&multi->cshutdn, multi->admin,
++ Curl_cshutdn_setfds(&multi->cshutdn,
+ read_fd_set, write_fd_set, &this_max_fd);
+
+ *max_fd = this_max_fd;
+@@ -1305,7 +1307,7 @@ CURLMcode curl_multi_waitfds(CURLM *m,
+ } while(Curl_uint32_bset_next(&multi->process, mid, &mid));
+ }
+
+- need += Curl_cshutdn_add_waitfds(&multi->cshutdn, multi->admin, &cwfds);
++ need += Curl_cshutdn_add_waitfds(&multi->cshutdn, &cwfds);
+
+ if(need != cwfds.n && ufds)
+ mresult = CURLM_OUT_OF_MEMORY;
+@@ -1392,7 +1394,7 @@ static CURLMcode multi_wait(struct Curl_multi *multi,
+ } while(Curl_uint32_bset_next(&multi->process, mid, &mid));
+ }
+
+- if(Curl_cshutdn_add_pollfds(&multi->cshutdn, multi->admin, &cpfds)) {
++ if(Curl_cshutdn_add_pollfds(&multi->cshutdn, &cpfds)) {
+ mresult = CURLM_OUT_OF_MEMORY;
+ goto out;
+ }
+@@ -1717,7 +1719,7 @@ CURLMcode Curl_multi_add_perform(struct Curl_multi *multi,
+
+ /* take this handle to the perform state right away */
+ multistate(data, MSTATE_PERFORMING);
+- Curl_attach_connection(data, conn);
++ Curl_attach_connection(data, conn, TRUE);
+ k->keepon |= KEEP_RECV; /* setup to receive! */
+ }
+ return mresult;
+@@ -2893,7 +2895,7 @@ CURLMcode curl_multi_cleanup(CURLM *m)
+ } while(Curl_uint32_tbl_next(&multi->xfers, mid, &mid, &entry));
+ }
+
+- Curl_cpool_destroy(&multi->cpool);
++ Curl_cpool_destroy(&multi->cpool, multi->admin);
+ Curl_cshutdn_destroy(&multi->cshutdn, multi->admin);
+ if(multi->admin) {
+ CURL_TRC_M(multi->admin, "multi_cleanup, closing admin handle, done");
+@@ -3277,7 +3279,7 @@ CURLMcode curl_multi_setopt(CURLM *m, CURLMoption option, ...)
+ Curl_dnscache_clear(multi->admin);
+ }
+ if(val & CURLMNWC_CLEAR_CONNS) {
+- Curl_cpool_nw_changed(multi->admin);
++ Curl_cpool_nw_changed(&multi->cpool, multi->admin);
+ }
+ break;
+ }
+diff --git a/lib/multiif.h b/lib/multiif.h
+index f368639857..9054dc6a66 100644
+--- a/lib/multiif.h
++++ b/lib/multiif.h
+@@ -34,7 +34,8 @@ void Curl_expire_clear(struct Curl_easy *data);
+ void Curl_expire_done(struct Curl_easy *data, expire_id id);
+ CURLMcode Curl_update_timer(struct Curl_multi *multi) WARN_UNUSED_RESULT;
+ void Curl_attach_connection(struct Curl_easy *data,
+- struct connectdata *conn);
++ struct connectdata *conn,
++ bool matched);
+ void Curl_detach_connection(struct Curl_easy *data);
+ bool Curl_multiplex_wanted(const struct Curl_multi *multi);
+ void Curl_set_in_callback(struct Curl_easy *data, bool value);
+diff --git a/lib/url.c b/lib/url.c
+index c3fb1439ca..6e42ca0ec4 100644
+--- a/lib/url.c
++++ b/lib/url.c
+@@ -482,7 +482,7 @@ CURLcode Curl_open(struct Curl_easy **curl)
+ data->magic = CURLEASY_MAGIC_NUMBER;
+ /* most recent connection is not yet defined */
+ data->state.lastconnect_id = -1;
+- data->state.recent_conn_id = -1;
++ data->state.lastconnect_id = -1;
+ /* and not assigned an id yet */
+ data->id = -1;
+ data->mid = UINT32_MAX;
+@@ -658,7 +658,7 @@ bool Curl_conn_seems_dead(struct connectdata *conn,
+
+ /* briefly attach the connection to this transfer for the purpose of
+ checking it */
+- Curl_attach_connection(data, conn);
++ Curl_attach_connection(data, conn, FALSE);
+
+ state = conn->handler->connection_check(data, conn, CONNCHECK_ISDEAD);
+ dead = (state & CONNRESULT_DEAD);
+@@ -668,7 +668,7 @@ bool Curl_conn_seems_dead(struct connectdata *conn,
+ else {
+ bool input_pending = FALSE;
+
+- Curl_attach_connection(data, conn);
++ Curl_attach_connection(data, conn, FALSE);
+ dead = !Curl_conn_is_alive(data, conn, &input_pending);
+ if(input_pending) {
+ /* For reuse, we want a "clean" connection state. The includes
+@@ -704,7 +704,7 @@ CURLcode Curl_conn_upkeep(struct Curl_easy *data,
+ return result;
+
+ /* briefly attach for action */
+- Curl_attach_connection(data, conn);
++ Curl_attach_connection(data, conn, FALSE);
+ if(conn->handler->connection_check) {
+ /* Do a protocol-specific keepalive check on the connection. */
+ unsigned int rc;
+@@ -1306,7 +1306,7 @@ static bool url_match_result(bool result, void *userdata)
+ if(match->found) {
+ /* Attach it now while still under lock, so the connection does
+ * no longer appear idle and can be reaped. */
+- Curl_attach_connection(match->data, match->found);
++ Curl_attach_connection(match->data, match->found, TRUE);
+ return TRUE;
+ }
+ else if(match->seen_single_use_conn && !match->seen_multiplex_conn) {
+@@ -3656,8 +3656,8 @@ static CURLcode create_conn(struct Curl_easy *data,
+ goto out;
+
+ /* Setup a "faked" transfer that will do nothing */
+- Curl_attach_connection(data, conn);
+ result = Curl_cpool_add(data, conn);
++ Curl_attach_connection(data, conn, TRUE);
+ if(!result) {
+ /* Setup whatever necessary for a resumed transfer */
+ result = setup_range(data);
+@@ -3688,7 +3688,10 @@ static CURLcode create_conn(struct Curl_easy *data,
+ if(result)
+ goto out;
+
+- Curl_cpool_prune_dead(data);
++ {
++ struct cpool *cpool = Curl_cpool_get_instance(data);
++ Curl_cpool_prune_dead(cpool, data);
++ }
+
+ /*************************************************************
+ * Check the current list of connections to see if we can
+@@ -3795,8 +3798,8 @@ static CURLcode create_conn(struct Curl_easy *data,
+ goto out;
+ }
+
+- Curl_attach_connection(data, conn);
+ result = Curl_cpool_add(data, conn);
++ Curl_attach_connection(data, conn, TRUE);
+ if(result)
+ goto out;
+ }
+@@ -4021,6 +4024,31 @@ CURLcode Curl_1st_err(CURLcode r1, CURLcode r2)
+ return r1 ? r1 : r2;
+ }
+
++struct Curl_easy *Curl_get_admin(struct Curl_easy *data)
++{
++ struct Curl_easy *admin;
++
++ if(!data->mid) /* already an admin handle */
++ admin = data;
++ else if(data->multi)
++ admin = data->multi->admin;
++ else if(data->multi_easy)
++ admin = data->multi_easy->admin;
++ else {
++ DEBUGASSERT(0); /* we do not want this. does it happen? */
++ admin = data;
++ }
++ if(admin != data) {
++ admin->set.conn_max_idle_ms = data->set.conn_max_idle_ms;
++ admin->set.conn_max_age_ms = data->set.conn_max_age_ms;
++ admin->set.upkeep_interval_ms = data->set.upkeep_interval_ms;
++ admin->set.timeout = data->set.timeout;
++ admin->set.server_response_timeout = data->set.server_response_timeout;
++ admin->set.no_signal = data->set.no_signal;
++ }
++ return admin;
++}
++
+ CURLcode Curl_1st_fatal(CURLcode r1, CURLcode r2)
+ {
+ if(r1 && (r1 != CURLE_AGAIN))
+diff --git a/lib/url.h b/lib/url.h
+index ddac784e75..3796a1f899 100644
+--- a/lib/url.h
++++ b/lib/url.h
+@@ -75,6 +75,12 @@ const struct Curl_handler *Curl_get_scheme_handler(const char *scheme);
+ const struct Curl_handler *Curl_getn_scheme_handler(const char *scheme,
+ size_t len);
+
++/* Get an admin handle for internal operations from the given
++ * easy handle, if possible. The admin handle inherits certain
++ * properties from `data`. If no admin handle is available (not multi
++ * or share attached), the easy handle itself is returned. */
++struct Curl_easy *Curl_get_admin(struct Curl_easy *data);
++
+ #define CURL_DEFAULT_PROXY_PORT 1080 /* default proxy port unless specified */
+ #define CURL_DEFAULT_HTTPS_PROXY_PORT 443 /* default https proxy port unless
+ specified */
+diff --git a/lib/urldata.h b/lib/urldata.h
+index 318dfdb84c..1e527826ca 100644
+--- a/lib/urldata.h
++++ b/lib/urldata.h
+@@ -931,9 +931,7 @@ struct UrlState {
+ /* buffers to store authentication data in, as parsed from input options */
+ struct curltime keeps_speed; /* for the progress meter really */
+
+- curl_off_t lastconnect_id; /* The last connection, -1 if undefined */
+- curl_off_t recent_conn_id; /* The most recent connection used, might no
+- * longer exist */
++ curl_off_t lastconnect_id; /* The last assigned connection or -1 */
+ struct dynbuf headerb; /* buffer to store headers in */
+ struct curl_slist *hstslist; /* list of HSTS files set by
+ curl_easy_setopt(HSTS) calls */
+diff --git a/tests/data/test1554 b/tests/data/test1554
+index fa071b09b2..f87b23371e 100644
+--- a/tests/data/test1554
++++ b/tests/data/test1554
+@@ -68,7 +68,9 @@ run 1: foobar and so on fun!
+ -] Mutex lock SHARE
+ [- Mutex unlock SHARE
+ -] Mutex lock SHARE
+-[- Mutex unlock SHARE
++-] Mutex lock CONNECT
++[- Mutex unlock CONNECT
++[- Mutex unlock SHARE
+ </datacheck>
+ </reply>
+
+--
+2.56.0
+
diff --git a/curl.spec b/curl.spec
index 05601cb..2706295 100644
--- a/curl.spec
+++ b/curl.spec
@@ -12,7 +12,7 @@
Summary: A utility for getting files from remote servers (FTP, HTTP, and others)
Name: curl
Version: 8.18.0
-Release: 12%{?dist}
+Release: 13%{?dist}
License: curl
Source0: https://curl.se/download/%{name}-%{version_no_tilde}.tar.xz
Source1: https://curl.se/download/%{name}-%{version_no_tilde}.tar.xz.asc
@@ -108,6 +108,9 @@ Patch027: 0027-curl-8.18.0-CVE-2026-80255.patch
# Fix OpenSSL provider use-after-free (CVE-2026-80229)
Patch028: 0028-curl-8.18.0-CVE-2026-80229.patch
+# Fix Negotiate ambient user conn reuse (CVE-2026-19931)
+Patch029: 0029-curl-8.18.0-CVE-2026-19931.patch
+
# patch making libcurl multilib ready
Patch101: 0101-curl-7.32.0-multilib.patch
@@ -534,6 +537,9 @@ rm -f ${RPM_BUILD_ROOT}%{_mandir}/man1/wcurl.1*
%{_libdir}/libcurl.so.4.[0-9].[0-9].minimal
%changelog
+* Thu Oct 08 2026 Jan Macku <jamacku@redhat.com> - 8.18.0-13
+- Fix Negotiate ambient user conn reuse (CVE-2026-19931)
+
* Tue Oct 06 2026 Jan Macku <jamacku@redhat.com> - 8.18.0-12
- Fix secure cookie attribute bypass with tab (CVE-2026-80255)
- Fix OpenSSL provider use-after-free (CVE-2026-80229)
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-08 13:39 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-08 13:39 [rpms/curl] f44: Resolves: CVE-2026-19931 - Negotiate ambient user conn reuse Jan Macku
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox