From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796359746; b=GlnT8mxrwJUzjiePs69KXqNMuPLGjSKhU4tRBJiLIOTrGgrLtgRr109+/w48cCy3OtUT KravQ+xuRizq/5n9ESR8xbwN9IHydTKLnTHnBvLZS+T2nQFeu6ElERNFaxyCD5ns+pn+w 3cJ81rGBmPyBDSPlCT/n5G8OLvGZRpQSwzP+ipU+zui/Ms3oifLPTiWL+ksHMdTOl2MTU 5AWKysYwEwnx1Z5qGxZM9qr2Ap+XiC7LVA2eUtxJWGKIApkZZKMEQEsZaJkxWWijfq72z KvH3VUz4BjZRMKHivHEsb1rwwu4cIdazgw9LAxRKnRHCr5Hp7wYQrDBmMTW4v5hc4IA== 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=vHEGM4M42W6s4Zv3cqvg7x1ek9G0M9SEdwL4Mt82ucVOApIVAOfpPMyEUUox/b9uvuEq L7V+H4kYspRxLWGrNSz5vEmHEqAywZDO+3doWBgUhJzYaJh4ysMvYxLdBfjVFIyt8AzZx Vhmz7wXisKSYJlH1GSOJftxSWuSQ7iSDa5renPwRakXhHvupcLx9Zhnxnc42FF7oeEgp2 TyPZ686xnjKZD1OPMTYT9H7FgkqiYom+JZpG6rq25zkIYIX+GxJ0JsOQanWcTcbaciVle OU2xyhm4F4tItFg0Ls76KZ+v3h7zaHdgsAj4w+S2FoU5svTNOGZR4d+rQRmrJfBzpvA== 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.216.42 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (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 1680C606A334 for ; Fri, 4 Dec 2026 04:49:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1680C606A334 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-pj1-f42.google.com with SMTP id 98e67ed59e1d1-3b3fb193c03so346314a91.2 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=paPNAHJUksWmMLY53Q+meckFVhUlzTtsD0Qhi3hSCUKgnCiTTIDzK1POEWdw4Cfmzw 899Au0Ws9pOZlgL4omfDkIfWGBksoyA9jafztR17he2Mu8AKhx3Ypd7r0OdzcYbt7Kiq ns6dgHB8NpTkyvA1dWbFGgqzB78ippmmBKZHWbIPHRepcZhl2Y8qRGJCoO1y3KI1UijU SukfQ7/Nm+cNGLQaLB/YkLtuoUmoD5TY/XQtxGe3I/TS3UvBLq6FptpyQ+2dBtTr6ITW kw5REZMt77W4xVyjuqt3l0JetLs1aFKduuhLFuJ3b8dfEdh6jNltXD1wzPvcmlS4AwII d7xg== X-Forwarded-Encrypted: i=1; AL+hErEmfQYpKBRIQwpIEohVg4yuJ+moe3wO/7TohBBZq+8rSYtuXrHtB0a7O1WXPMbj0YpRd0EPAzI=@vger.kernel.org X-Gm-Message-State: APuU4Z84NUpMKZlB/e54AYsPUwliQbU6di1H2238XfuzfMiynHKIrjO2 n1/5aCe36WNGsj4RlPWyAKz4i9paec6BORGsKYNWFIGHHcaGBJST9YZx X-Gm-Gg: AZFdTZfHB77qCCwKueds73lXb8Q09Eb2s3/iLs7nsmAjg5kVNW7nr1Bd/uCksl0Ddlx 8L7rjJa7dm+45Kb+HYSzK86B6nMoaQiy1EPZbiihMPffWv3iVgHYCRTCOpbbEwanbHUFqg6nq9w 4qKA+sdTp1nqbcJZdHIrdRHTwAJMgqrZNdf8iOv77lkgJog9hLCy8Wx2q9q65PqXBHricgkVD8h oVN1R3Z0GRIRyV29W4QHmWb+pWFk04g5rwEDKejCno3v6QebGCYTn/bXOqJcJd9tBEk2GxhGPcx VQAWROgKyEYjTPy7St7z8Tor+A5GvIRh0iJ+XQGTYflK4N/wtkSCexRA8Geutxt31tfIXA1zm+n XYwRdxnudneuQL5zO3irN1nZdP6XO7dSoLLWdFwMO0FaQPoTKXxcGcJjJLvTEmVr1fGEtXVKJJD NbNJ2ccChTtMCgfzsq7uDtpoRTaDmFVWvse75klYEmNx8ssfvgvCCiWB6dGSbdpl3FDM6eeejAE C7zzvLtMFnN2k69vDLwtUvk6+9ZHGk2QaQJ/U8TKUWlPWNPmRoVkOwUpvufYVEi2Xa/IYPCGAJd TYUBSKf4vWiBlNEUMIK60mKEcMQOwj6l2cFS6Ixr2DFIvRvaDvhGIKWM6FF82vEBJMYEO7YKnw= = 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: stable@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