rds: tcp: unregister sysctl before tearing down listen socket
Subsystems (4)
PATCH v2 1/1 rds: tcp: unregister sysctl before tearing down listen socket
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.
---
v2:
- Add link to KASAN report and reproducer code.
- Add Reviewed-by tags.
net/rds/tcp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/rds/tcp.c +2 -2
@@ -655,13 +655,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 = {
Signature · 1 line
2.53.0
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Sun, 19 Jul 2026 17:03:57 -0400 you wrote:
rds_tcp_exit_net()frees the per-netns RDS TCP listen socket viards_tcp_kill_sock()before unregistering the per-netns sysctl table. Sincerds_tcp_skbuf_handler()derives the netns fromrtn->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:
[...]
Here is the summary with links:
- [net,v2] rds: tcp: unregister sysctl before tearing down listen socket
https://git.kernel.org/netdev/net/c/167e54c703cc
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html