Skip to content

Commit 80fffed

Browse files
occiagregkh
authored andcommitted
rds: tcp: unregister sysctl before tearing down listen socket
[ Upstream commit 167e54c ] 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: 7f5611c ("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 <achender@kernel.org> Signed-off-by: Cen Zhang (Microsoft) <blbllhy@gmail.com> Link: https://patch.msgid.link/20260719210357.10179-1-blbllhy@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 653de66 commit 80fffed

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

net/rds/tcp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,13 +637,13 @@ static void __net_exit rds_tcp_exit_net(struct net *net)
637637
{
638638
struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid);
639639

640-
rds_tcp_kill_sock(net);
641-
642640
if (rtn->rds_tcp_sysctl)
643641
unregister_net_sysctl_table(rtn->rds_tcp_sysctl);
644642

645643
if (net != &init_net)
646644
kfree(rtn->ctl_table);
645+
646+
rds_tcp_kill_sock(net);
647647
}
648648

649649
static struct pernet_operations rds_tcp_net_ops = {

0 commit comments

Comments
 (0)