Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796359746; b=X47Pcns0WA3bqVmp4dR4rPdks7cn67h/LdhSxd4M+xSgu72Q14r2ZenjSSPCVmhNshWr Z1mrSHBJ2bc2zKMJP5JTE7Lgax7xUJIb6bPH1THuUw5wKstTIWHXZnUGyl/ET9kNoTAdt s+m8MUyr2jaHer3fd22vXj6/kJSKkJDPscBjOyTtmgHgonz3IC3LH1CWgGVwnwtTSgyZI iJN9xCnOWq3LMu2MRMTPbIol58RNDy5GxIDTZc5YsAwLR/U51tl0tV1lHtPCtZQleRDr+ ZfgoD92lbL6xeINvVSwqVEBNKu0JBLstcLUhohuss+0aLLErbpxu0fLA5eOBIK0ymDg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796359746; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=alImygKUhq7zaP4ieneV6WGMWzL+TMDErnhM258BC0I=; b=Qi07qaWzCdNg0YC5Gfui3K4308B/15AheB+9OhEKhjKz0LnVgnpjuMfD/HcFm/ydrbdl NsRBqiC6r91R938BJADYsHEKXaydrc/FR/54ytSGKrxH9E1tRUYM2g9hFYbrpCcqvVeGi kF26kMtNK5ImpvwTgftJUHvMmp1iUxbo0mNxJIF3tjzbRcS+L2TzL4F7NmLcmrikkNrjv MpmtnFbg2L7lB4ryBE9zq/G2N8kLJINYDP3sei8rPnPu7izM8MTw7z+ZnGkHByxiEIwub +7cBjJndc3/+UkApXPGvcSd/aVag7RxgVkQHcv/mWDCvO1eSQTcJ1T7Jl0zluPLBIgg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=rK1zTp1D; arc=none smtp.remote-ip=209.85.215.182 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0C7C7606A33E for ; Fri, 4 Dec 2026 04:49:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0C7C7606A33E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=rK1zTp1D Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-cdece95eca4so290945a12.1 for ; Thu, 03 Dec 2026 20:49:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796359745; x=1796964545; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=alImygKUhq7zaP4ieneV6WGMWzL+TMDErnhM258BC0I=; b=rK1zTp1DcB7VU1qwJ6LfIKXoXUdSG6qhnZahGAtPnPQUbHHPGLHopuXgDxuip1FQqM L82Nn9UVWU4BM9a892ZoGmCD9kj2b25fnx2hBpf52LAuT3tSIYQ+3XDd5fpfI2E2uoUF MqiNZ985Z30QtUuarMHOeiDR42pli4XseG/VR3oUwaIAyeXrF5fGVWNNxGyRuTghYWfB dhE29KpESIjEbr/FKwTHRe0RYaEpqzShPUi6V7CXQ3u1d1vuw77CDIRymXXd58P5DAsQ +Q4udYXlr+/3pix++1XB49wAw8RMp+YSP+Et7dMlqjDNs76hRyFXt/QB5nXPzTLbU6Xi U9vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796359745; x=1796964545; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=alImygKUhq7zaP4ieneV6WGMWzL+TMDErnhM258BC0I=; b=CWNfnW4He/FFlXok2cR1/Ko+odi2rRKggXwv2xzphlf/QQ4oXe8JZCV33KPLWcXTBh jgOzCwSOVBiP2L78Ev+Wm8B3SdsU24CIhk+yQ6MnSy8Q2SJ0Atbwrx3DBTsQhfyJsef4 trHrLC+SKZpW0MukdQrfYGgX/qGruWs9k+mMOAlrmdNJBt7ztFWoI1qVNOrt5/6dgOL4 F7vtECKSsgxBqjHMorr8dycNtkwvEX5fIoX1xDvZgjUPaSk/xatxkZ/w9Ol+EuY9q+ri h9aEhCyI+MUWQRTbKrBSERiQWklveaWqwS3WIUQVlYuAhF4aNiD1v+acfPlVNeoLQmA6 u+FQ== X-Forwarded-Encrypted: i=1; AL+hErGlLRrb8e3ppvNybLzfTw4B+rrxsh1crumsESEcVMWul3hNKkWxG4yIicXWnWgd6Pr823NurLE=@vger.kernel.org X-Gm-Message-State: APuU4Z+tdPSINepvxpc+zw7vQpR/EcYDBmST4us4whOifC/YSMD0fG+N 20zOBG1i/Yh6Ti1kJ5cGuxPfxswn/HD+0gzB7LzgZlm/VgIrB58bwcMc X-Gm-Gg: AZFdTZdWiPzIoSXqsFBy6nWwud9kF/3qkHVggT0N0c8k9rv9azjqOEwaQQdgyiuXdVe KpxQ2V9nw/Fq0WHN0MielVyOKYAyXsBw0XBxJUETAImIwQVfqsX0pymCbyuWtngl+3VoMQ6ZQqD cwTMvefZ8vzZGONjaoNTDKJxxHkZ7EYcEzv6EK+fB0P2a8Sl+Egtn41Ffl2hlgbzLCpzlCeu/De /B0RVVLPbKqxa9lGFMstGu/6QY72ej+Xf/HIctVLrUq9MyuVV8gUGNP+C3C2FyzixBkZ6x3v9RL sgEekvZK65Q2OOe1YSDy2AkFdbYvUdV40og1XHb/F+peROZ9pN3cXhPgb7UhOpnpE/TjDu1m8Rd NCdNFvRkc5nsTO4dMEx3VJK7xTOSFU3fdmjKLcAUD8fnmvje0dBNr3k7FOX3cyOjqqZoQDw7MZH UvwBd4FUe3txtSffvxyjdaf4t6DImgQah6dVy2jlYkqkEwgeS7fl2b472VHyVvB8wOGVRzQkve9 ycQQoqlpTEbS1DUore6bXcHgagzsmyMkshZDiZ0ZNECW1oaTmAd2rSrPE1pGsuYTtrpqlvCqvJh Ls3oavVqOkMXw1Ezn6SpkUBbtirLcYJHjysE2oLCc2RKsKwBPHOP8OSAvif1VENooVyh/x7tJA= = X-Received: by 2002:a17:90b:4ec6:b0:3ad:1b31:92d8 with SMTP id 98e67ed59e1d1-3b5e066c4fdmr671025a91.60.1796359745163; Thu, 03 Dec 2026 20:49:05 -0800 (PST) Received: from JIAPENGLIN-MC0.tencent.com ([43.132.141.21]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b5ddc36965sm1813079a91.8.2026.12.03.20.49.02 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 03 Dec 2026 20:49:04 -0800 (PST) From: Lin Jiapeng To: dhowells@redhat.com, marc.dionne@auristor.com Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, willemb@google.com, horms@kernel.org, linux-afs@lists.infradead.org, netdev@vger.kernel.org, Lin Jiapeng , TencentOS Corvus AI , stable@vger.kernel.org Subject: [PATCH net] rxrpc: Order service connection activation before state publication Date: Fri, 4 Dec 2026 12:48:29 +0800 Message-ID: <20261204044852.58297-1-ljp1205831794@gmail.com> X-Mailer: git-send-email 2.55.0 X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Lin Jiapeng RxRPC preallocates service connections on the reaper list while they are inactive and promotes them when a call arrives. TencentOS Corvus AI found that promotion can leave a connection with only its call reference, after which a later lookup accesses a freed rbtree node. A trigger-only harness reproduced a KASAN slab-use-after-free on net/main 5584a17feee0. Promotion stores the non-PREALLOC state before setting active to 1. If the reaper runs in between, it claims active 0 -> -1 and drops the list reference, but unpublish skips the rbtree erase because publication has not happened yet. The publisher then overwrites -1 with 1 and publishes the connection. Its final call put consequently frees an object that remains linked in the peer rbtree, and a subsequent lookup reads the freed proto.index_key. Adding only a cleanup-time unpublish would not prevent the active-state corruption or the reaper assertion. The unfixed kernel reports: [ 100.904322] BUG: KASAN: slab-use-after-free in rxrpc_find_service_conn_rcu+0x494/0x520 [ 100.905401] Read of size 8 at addr ff110001067f2000 by task krxrpcio/54000/117 [ 100.906475] CPU: 0 UID: 0 PID: 117 Comm: krxrpcio/54000 Not tainted 7.4.0-rc4 #3 PREEMPT(full) [ 100.907266] Call Trace: [ 100.909811] rxrpc_find_service_conn_rcu+0x494/0x520 [ 100.910098] rxrpc_input_packet.constprop.0+0x1349/0x2290 [ 100.911293] rxrpc_io_thread+0xb9e/0x1730 [ 100.913361] kthread+0x385/0x490 [ 100.914057] ret_from_fork+0x656/0xa90 [ 100.915749] ret_from_fork_asm+0x1a/0x30 [ 100.916520] Allocated by task 107: [ 100.917647] rxrpc_alloc_connection+0x9d/0x710 [ 100.917921] rxrpc_prealloc_service_connection+0x26/0x390 [ 100.918206] rxrpc_service_prealloc_one+0x2c7/0xfb0 [ 100.918416] rxrpc_user_charge_accept+0xbc/0xf0 [ 100.920528] Freed by task 0: [ 100.921678] rxrpc_rcu_free_connection+0x16c/0x210 [ 100.922014] rcu_core+0x671/0x15f0 [ 100.922199] handle_softirqs+0x23d/0x9d0 [ 100.927196] The buggy address belongs to the object at ff110001067f2000 [ 100.927196] which belongs to the cache kmalloc-2k of size 2048 [ 100.927413] The buggy address is located 0 bytes inside of [ 100.927413] freed 2048-byte region [ff110001067f2000, ff110001067f2800) Move activation ahead of the state transition and use atomic_xchg(), whose full ordering makes active=1 visible before the non-PREALLOC state. Before the transition the reaper skips PREALLOC; afterwards it either sees active=1 or its final atomic_try_cmpxchg() fails even if its first active read was an old zero. No new failure path is needed, and publication, reference ownership and normal active-count handling remain unchanged. Reproducing requires an SMP x86_64 guest with CONFIG_AF_RXRPC=y, CONFIG_PROC_FS=y and KASAN enabled. The validated process creates AF_RXRPC services on loopback as an unprivileged user with no capabilities, lets the preallocated connections age, races incoming calls against the reaper and then releases and probes the connections. Both kernels used the same 20 ms test-only activation delay and 10-second expiry. The unfixed kernel produced the report above, while the patched kernel completed 512 activation attempts without a premature claim or UAF and passed the normal release-and-lookup control. Fixes: 3cec055c5695 ("rxrpc: Don't hold a ref for connection workqueue") Reported-by: TencentOS Corvus AI Signed-off-by: Lin Jiapeng Cc: stable@vger.kernel.org --- net/rxrpc/conn_service.c | 7 +++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/rxrpc/conn_service.c b/net/rxrpc/conn_service.c index 39c908a3ca6e..572f0b4abb7e 100644 --- a/net/rxrpc/conn_service.c +++ b/net/rxrpc/conn_service.c @@ -161,6 +161,10 @@ void rxrpc_new_incoming_connection(struct rxrpc_sock *rx, conn->security_ix = sp->hdr.securityIndex; conn->out_clientflag = 0; conn->security = sec; + + /* Activate before changing state, with full ordering for the reaper. */ + atomic_xchg(&conn->active, 1); + if (conn->security_ix) conn->state = RXRPC_CONN_SERVICE_UNSECURED; else @@ -174,8 +178,6 @@ void rxrpc_new_incoming_connection(struct rxrpc_sock *rx, conn->service_id == rx->service_upgrade.from) conn->service_id = rx->service_upgrade.to; - atomic_set(&conn->active, 1); - /* Make the connection a target for incoming packets. */ rxrpc_publish_service_conn(conn->peer, conn); } base-commit: 5584a17feee004afa77ffb0df938011d7239de87 -- 2.43.0