mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chengfeng Ye <nicoyip.dev@gmail.com>
To: David Howells <dhowells@redhat.com>,
	Marc Dionne <marc.dionne@auristor.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>
Cc: linux-afs@lists.infradead.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Chengfeng Ye <nicoyip.dev@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH net] rxrpc: Serialize client connection IDR updates
Date: Sun, 27 Sep 2026 16:18:45 +0800	[thread overview]
Message-ID: <20260927081845.3696101-1-nicoyip.dev@gmail.com> (raw)

Client connection allocation runs in the local endpoint's I/O thread,
but the final connection reference can be dropped by another thread.
Connection cleanup then calls rxrpc_put_client_connection_id() directly
or from a workqueue, without synchronizing with the I/O thread.

The I/O thread can be traversing or updating local->conn_ids in
idr_alloc_cyclic() while a cleanup worker calls idr_remove() on the same
IDR. The removal can change or retire a radix-tree node still being used
by the allocator. Concurrent removals are also possible. These
unsynchronized updates can corrupt the IDR and crash the kernel.

KCSAN reported:

  BUG: KCSAN: data-race in node_tag_clear / radix_tree_delete_item

  read (marked) to 0xffff9d03804b9fd0 of 8 bytes by task 109 on cpu 1:
   radix_tree_delete_item+0x132/0x160
   idr_remove+0x32/0x50
   rxrpc_put_client_connection_id+0x53/0xe0
   rxrpc_kill_client_conn+0x7d/0x190
   rxrpc_clean_up_connection+0x193/0x370
   rxrpc_put_connection+0x3d9/0x3e0
   rxrpc_destroy_call+0x192/0x2e0
   process_one_work+0x325/0x710
   worker_thread+0x31d/0x5c0

  write to 0xffff9d03804b9fd0 of 8 bytes by task 97 on cpu 0:
   node_tag_clear+0x7a/0x110
   radix_tree_iter_tag_clear+0x47/0x60
   idr_alloc_u32+0x13e/0x1a0
   idr_alloc_cyclic+0x7a/0xf0
   rxrpc_connect_client_calls+0x375/0xa40
   rxrpc_io_thread+0x79c/0xe20

Serialize allocation and removal with the IDR's existing lock. Both
paths run in process context and allocation already uses GFP_ATOMIC,
so no additional lock or allocation changes are needed. RCU-protected
lookups remain unchanged.

Fixes: 9d35d880e0e4 ("rxrpc: Move client call connection to the I/O thread")
Cc: stable@vger.kernel.org
Signed-off-by: Chengfeng Ye <nicoyip.dev@gmail.com>
---
 net/rxrpc/conn_client.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/net/rxrpc/conn_client.c b/net/rxrpc/conn_client.c
index 48519f0de185..93e08a13a236 100644
--- a/net/rxrpc/conn_client.c
+++ b/net/rxrpc/conn_client.c
@@ -45,7 +45,9 @@ static void rxrpc_activate_bundle(struct rxrpc_bundle *bundle)
 static void rxrpc_put_client_connection_id(struct rxrpc_local *local,
 					   struct rxrpc_connection *conn)
 {
+	idr_lock(&local->conn_ids);
 	idr_remove(&local->conn_ids, conn->proto.cid >> RXRPC_CIDSHIFT);
+	idr_unlock(&local->conn_ids);
 }
 
 /*
@@ -162,8 +164,10 @@ rxrpc_alloc_client_connection(struct rxrpc_bundle *bundle)
 	if (!conn)
 		return ERR_PTR(-ENOMEM);
 
+	idr_lock(&local->conn_ids);
 	id = idr_alloc_cyclic(&local->conn_ids, conn, 1, 0x40000000,
 			      GFP_ATOMIC | __GFP_NOWARN);
+	idr_unlock(&local->conn_ids);
 	if (id < 0) {
 		kfree(conn);
 		return ERR_PTR(id);
-- 
2.43.0


                 reply	other threads:[~2026-09-27  8:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260927081845.3696101-1-nicoyip.dev@gmail.com \
    --to=nicoyip.dev@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dhowells@redhat.com \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-afs@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marc.dionne@auristor.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®