From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE96D407597; Thu, 30 Jul 2026 15:11:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785424265; cv=none; b=sF6P4JJdCUVpf2jR4ABiQFG6OxXBAFCwpNZ1M2i0PxVlF78oeOs4iieVg3XoN8zaY/cMgMIFhKzc/UAcz3F2JtkqAN0YeuF10lh+CBz7DWGEr3o5/MHwlTXnUJJ+SEEPbWj1K4aP+o6iBVfcvYEWmUwTOvtLTjii7NVpNLOf3Zo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785424265; c=relaxed/simple; bh=T/qr3jKjdPVUzR2eJpWcZsRt+ZHTSzNhPYUUCB0j0dg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ay0WUVoO7GP+wT5l4484RFK7F4KdmvT5wYSFrLzZ3yZHF9Tfn7OOvMUuwMXVsCeE3CApYu/3FzoQ++CG8+5K7Zg/WT7mZ2IMvp8Q5mFS/DRr9aLmYUEd0GLcag+vQW6AV6EVnp5+lHLP8qZdJmrxZAM5JoujlAPPS/Ywgdpfzlc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=bA7T153x; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="bA7T153x" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B42A41F000E9; Thu, 30 Jul 2026 15:10:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1785424256; bh=xzIMDTfepaTkR0AZpWtn7sH31lut6PPgao47OgPkpck=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=bA7T153xX5gLc71s4XSlNetN5kv05DY5brhtPuZJu7c9pigF4uDBO2RkEz3/PeNtr XDBBQ1QH9ugV0WPAVbxvax2ZuootVZrhjxTxlhuO62ykOeS5s+phDrKZmRDrBnWFC7 0FzmBPnIOtnur9nOx6oBw1dO9TXwEZyIvnuG2dv0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, AutonomousCodeSecurity@microsoft.com, Allison Henderson , "Cen Zhang (Microsoft)" , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.18 313/675] rds: tcp: unregister sysctl before tearing down listen socket Date: Thu, 30 Jul 2026 16:10:43 +0200 Message-ID: <20260730141451.778446747@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260730141445.110192266@linuxfoundation.org> References: <20260730141445.110192266@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Cen Zhang (Microsoft) [ Upstream commit 167e54c703ccd4fa028feb568b0d1002020cff86 ] rds_tcp_exit_net() frees the per-netns RDS TCP listen socket via rds_tcp_kill_sock() before unregistering the per-netns sysctl table. Since rds_tcp_skbuf_handler() derives the netns from rtn->rds_tcp_listen_sock->sk, a concurrent sysctl write can race with netns teardown and dereference the freed socket/sk. KASAN reports the race as: BUG: KASAN: slab-use-after-free in rds_tcp_skbuf_handler+0x2aa/0x2e0 rds_tcp_skbuf_handler net/rds/tcp.c:721 proc_sys_call_handler fs/proc/proc_sysctl.c vfs_write fs/read_write.c __x64_sys_pwrite64 fs/read_write.c Fix this by unregistering the RDS TCP sysctl table before calling rds_tcp_kill_sock(). unregister_net_sysctl_table() prevents new sysctl handlers from starting and waits for in-flight handlers to finish, so the listen socket can then be released safely. The fix was tested against the linked reproducer. Fixes: 7f5611cbc487 ("rds: sysctl: rds_tcp_{rcv,snd}buf: avoid using current->nsproxy") Reported-by: AutonomousCodeSecurity@microsoft.com Link: https://lore.kernel.org/all/20260719203718.9680-1-blbllhy@gmail.com Reviewed-by: Allison Henderson Signed-off-by: Cen Zhang (Microsoft) Link: https://patch.msgid.link/20260719210357.10179-1-blbllhy@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/rds/tcp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/rds/tcp.c b/net/rds/tcp.c index b66dfcc3efaa0f..06a2d8d48bbacf 100644 --- a/net/rds/tcp.c +++ b/net/rds/tcp.c @@ -637,13 +637,13 @@ static void __net_exit rds_tcp_exit_net(struct net *net) { struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid); - rds_tcp_kill_sock(net); - if (rtn->rds_tcp_sysctl) unregister_net_sysctl_table(rtn->rds_tcp_sysctl); if (net != &init_net) kfree(rtn->ctl_table); + + rds_tcp_kill_sock(net); } static struct pernet_operations rds_tcp_net_ops = { -- 2.53.0