tcp/rds: Fix use-after-free around kernel TCP reqsk.
Subsystems (6)
v2 cover tcp/rds: Fix use-after-free around kernel TCP reqsk.
syzkaller reported an warning of netns ref tracker for RDS TCP listener, which commit 740ea3c4a0b2 ("tcp: Clean up kernel listener's reqsk in inet_twsk_purge()") partially fixed.
This series fixes the bug in the partial fix, reverts the partial fix, and fixes the root cause on the RDS side.
Changes:
v2:
* Add patch 1, 3, 5
* Use __sock_create() instead of converting socket
* Drop Sowmini from CC as it's bounced (patchwork may complain)
v1: https://lore.kernel.org/netdev/[email protected]/
Kuniyuki Iwashima (5):
tcp: Restart iteration after removing reqsk in inet_twsk_purge(). Revert "tcp: Clean up kernel listener's reqsk in inet_twsk_purge()"
net: Convert @kern of __sock_create() to enum.
rds: tcp: Fix use-after-free of net in reqsk_timer_handler().
tcp: Add assertion for reqsk->rsk_listener->sk_net_refcnt.
include/linux/net.h | 6 ++++++ net/core/sock.c | 2 +- net/ipv4/inet_timewait_sock.c | 14 +------------- net/ipv4/tcp_input.c | 2 ++ net/ipv4/tcp_minisocks.c | 9 ++++----- net/rds/tcp_listen.c | 4 ++-- net/socket.c | 11 ++++++----- 7 files changed, 22 insertions(+), 26 deletions(-)
Signature · 1 line
2.30.2
PATCH v2 1/5 tcp: Restart iteration after removing reqsk in inet_twsk_purge().
Commit 740ea3c4a0b2 ("tcp: Clean up kernel listener's reqsk in inet_twsk_purge()") added changes in inet_twsk_purge() to purge reqsk in per-netns ehash during netns dismantle.
inet_csk_reqsk_queue_drop_and_put() will remove reqsk from per-netns ehash, but the iteration uses sk_nulls_for_each_rcu(), which is not safe.
After removing reqsk, we need to restart iteration.
Note that we need not check net->ns.count here because per-netns ehash does not have reqsk in other live netns.
This change will be removed by the following patch.
--- net/ipv4/inet_timewait_sock.c | 2 ++ 1 file changed, 2 insertions(+)
net/ipv4/inet_timewait_sock.c +2 -0
@@ -287,6 +287,8 @@ void inet_twsk_purge(struct inet_hashinfo *hashinfo, int family)struct request_sock *req =inet_reqsk (sk);inet_csk_reqsk_queue_drop_and_put (req->rsk_listener, req); + + goto restart; }continue ;
Signature · 1 line
2.30.2
PATCH v2 2/5 Revert "tcp: Clean up kernel listener's reqsk in inet_twsk_purge()"
In reply to Kuniyuki IwashimaThis reverts commit 740ea3c4a0b2e326b23d7cdf05472a0e92aa39bc.
The change actually fixed a use-after-free of struct net by kernel listener's reqsk in per-netns ehash.
However, the fix was incomplete, as the same issue exists for the global ehash.
We should have fixed it on the RDS side without slowing down netns dismantle for the normal TCP use case.
The following patches will fix the issue on the RDS side.
--- net/ipv4/inet_timewait_sock.c | 16 +--------------- net/ipv4/tcp_minisocks.c | 9 ++++----- 2 files changed, 5 insertions(+), 20 deletions(-)
net/ipv4/inet_timewait_sock.c +1 -15
@@ -277,22 +277,8 @@ void inet_twsk_purge(struct inet_hashinfo *hashinfo, int family)rcu_read_lock (); restart:sk_nulls_for_each_rcu (sk, node, &head->chain) { -if (sk->sk_state !=TCP_TIME_WAIT ) { -/* A kernel listener socket might not hold refcnt for net, -* so reqsk_timer_handler() could be fired after net is -* freed. Userspace listener and reqsk never exist here. -*/ -if (unlikely (sk->sk_state ==TCP_NEW_SYN_RECV && - hashinfo->pernet)) { -struct request_sock *req =inet_reqsk (sk); - -inet_csk_reqsk_queue_drop_and_put (req->rsk_listener, req); - - goto restart; - } - +if (sk->sk_state !=TCP_TIME_WAIT )continue ; - } tw =inet_twsk (sk); if ((tw->tw_family != family) ||
net/ipv4/tcp_minisocks.c +4 -5
@@ -394,14 +394,13 @@ void tcp_twsk_purge(struct list_head *net_exit_list, int family)struct net *net;list_for_each_entry (net, net_exit_list, exit_list) { +/* The last refcount is decremented in tcp_sk_exit_batch() */ +if (refcount_read (&net->ipv4.tcp_death_row.tw_refcount) ==1 ) +continue ; +if (net->ipv4.tcp_death_row.hashinfo->pernet) { -/* Even if tw_refcount == 1, we must clean up kernel reqsk */ inet_twsk_purge (net->ipv4.tcp_death_row.hashinfo, family); }else if (!purged_once) { -/* The last refcount is decremented in tcp_sk_exit_batch() */ -if (refcount_read (&net->ipv4.tcp_death_row.tw_refcount) ==1 ) -continue ; -inet_twsk_purge (&tcp_hashinfo, family); purged_once = true; }
Signature · 1 line
2.30.2
PATCH v2 3/5 net: Convert @kern of __sock_create() to enum.
In reply to Kuniyuki IwashimaHistorically, syzbot has reported many use-after-free of struct net by kernel sockets.
In most cases, the root cause was a timer kicked by a kernel socket which does not hold netns refcount nor clean it up during netns dismantle.
This patch converts the @kern argument of __sock_create() to enum so that we can pass SOCKET_KERN_NET_REF and later sk_alloc() can hold refcount of net for kernel sockets.
We pass !!kern to security_socket(_post)?_create() but kern as is to pf->create() because 3 functions (atalk_create(), inet_create(), inet6_create()) use it for the following check:
if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
The conversion for rest of the callers of __sock_create() and sk_alloc() will be completed in net-next.git as the change is too large to backport.
--- include/linux/net.h | 6 ++++++ net/core/sock.c | 2 +- net/socket.c | 11 ++++++----- 3 files changed, 13 insertions(+), 6 deletions(-)
include/linux/net.h +6 -0
@@ -245,6 +245,12 @@ enum { SOCK_WAKE_URG, }; +enum socket_user { +SOCKET_USER , +SOCKET_KERN , +SOCKET_KERN_NET_REF , +}; +int sock_wake_async (struct socket_wq *sk_wq,int how,int band);int sock_register (const struct net_proto_family *fam);void sock_unregister (int family);
net/core/sock.c +1 -1
@@ -2138,7 +2138,7 @@ struct sock *sk_alloc(struct net *net, int family, gfp_t priority, sk->sk_prot = sk->sk_prot_creator = prot; sk->sk_kern_sock = kern;sock_lock_init (sk); - sk->sk_net_refcnt = kern ?0 :1 ; + sk->sk_net_refcnt = kern !=SOCKET_KERN ;if (likely (sk->sk_net_refcnt)) {get_net_track (net, &sk->ns_tracker, priority);sock_inuse_add (net,1 );
net/socket.c +6 -5
@@ -1489,7 +1489,7 @@ EXPORT_SYMBOL(sock_wake_async);* @type: communication type (SOCK_STREAM, ...) * @protocol: protocol (0, ...) * @res: new socket -* @kern: boolean for kernel space sockets +* @kern: enum for kernel space sockets * * Creates a new socket and assigns it to @res, passing through LSM. * Returns 0 or an error. On failure @res is set to %NULL. @kern must
@@ -1523,7 +1523,7 @@ int __sock_create(struct net *net, int family, int type, int protocol, family =PF_PACKET ; } - err =security_socket_create (family, type, protocol, kern); + err =security_socket_create (family, type, protocol, !!kern);if (err)return err;
@@ -1584,7 +1584,7 @@ int __sock_create(struct net *net, int family, int type, int protocol,* module can have its refcnt decremented */ module_put (pf->owner); - err =security_socket_post_create (sock, family, type, protocol, kern); + err =security_socket_post_create (sock, family, type, protocol, !!kern);if (err) goto out_sock_release; *res = sock;
@@ -1619,7 +1619,8 @@ EXPORT_SYMBOL(__sock_create);int sock_create (int family,int type,int protocol,struct socket **res) { -return __sock_create (current->nsproxy->net_ns, family, type, protocol, res,0 ); +return __sock_create (current->nsproxy->net_ns, family, type, protocol, + res,SOCKET_USER ); }EXPORT_SYMBOL (sock_create);
@@ -1637,7 +1638,7 @@ EXPORT_SYMBOL(sock_create);int sock_create_kern (struct net *net,int family,int type,int protocol,struct socket **res) { -return __sock_create (net, family, type, protocol, res,1 ); +return __sock_create (net, family, type, protocol, res,SOCKET_KERN ); }EXPORT_SYMBOL (sock_create_kern);
Signature · 1 line
2.30.2
RE: [PATCH v2 net 3/5] net: Convert @kern of __sock_create() to enum.
From: Kuniyuki Iwashima
Quoted 2 lines
Sent: 27 February 2024 01:11
Subject: [PATCH v2 net 3/5] net: Convert @kern of__sock_create()to enum.
Should probably be (something like):
Allow __sock_create() create kernel sockets that hold a reference to the network namespace.
Quoted 10 lines
Historically, syzbot has reported many use-after-free of struct net by kernel sockets.
In most cases, the root cause was a timer kicked by a kernel socket which does not hold netns refcount nor clean it up during netns dismantle.
This patch converts the @kern argument of
__sock_create()to enum so that we can passSOCKET_KERN_NET_REFand latersk_alloc()can hold refcount of net for kernel sockets.
I think you should add a 'hold netns' parameter to sock_create_kern(). Indeed, that is likely to be used for a real connection (which would need the 'hold netns') and code that doesn't need it (because the socket is some internal housekeeping socket) could directly call __sock_create().
Fortunately both functions are exported non-gpl.
I've this comment in a driver...
/* sock_create_kern() creates a socket that doesn't hold a reference
* to the namespace (they get used for sockets needed by the protocol
* stack code itself).
* We need a socket that holds a reference to the namespace, so create
* a 'user' socket in a specific namespace.
* This adds an extra security check which we should pass because all the
* sockets are created by kernel threads.
*/
rval = __sock_create(net, family, type, protocol, sockp, 0);
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
PATCH v2 4/5 rds: tcp: Fix use-after-free of net in reqsk_timer_handler().
In reply to Kuniyuki Iwashimasyzkaller reported a warning of netns tracker [0] followed by KASAN splat [1] and another ref tracker warning [1].
syzkaller could not find a repro, but in the log, the only suspicious sequence was as follows:
18:26:22 executing program 1:
r0 = socket$inet6_mptcp(0xa, 0x1, 0x106)
...
connect$inet6(r0, &(0x7f0000000080)={0xa, 0x4001, 0x0, @loopback}, 0x1c) (async)
The notable thing here is 0x4001 in connect(), which is RDS_TCP_PORT.
So, the scenario would be:
1. unshare(CLONE_NEWNET) creates a per netns tcp listener in
rds_tcp_listen_init().
2. syz-executor connect()s to it and creates a reqsk.
3. syz-executor exit()s immediately.
4. netns is dismantled. [0]
5. reqsk timer is fired, and UAF happens while freeing reqsk. [1]
6. listener is freed after RCU grace period. [2]
Basically, reqsk assumes that the listener guarantees netns safety until all reqsk timers are expired by holding the listener's refcount. However, this was not the case for kernel sockets.
Commit 740ea3c4a0b2 ("tcp: Clean up kernel listener's reqsk in inet_twsk_purge()") fixed this issue only for per-netns ehash, but the issue still exists for the global ehash.
We can apply the same fix, but this issue is specific to RDS.
Instead of iterating ehash and purging reqsk during netns dismantle, let's hold netns refcount for the kernel listener.
[0]:ref_tracker: net notrefcnt@0000000065449cc3 has 1/1 users at
sk_alloc (./include/net/net_namespace.h:337 net/core/sock.c:2146)
inet6_create (net/ipv6/af_inet6.c:192 net/ipv6/af_inet6.c:119)
__sock_create (net/socket.c:1572)
rds_tcp_listen_init (net/rds/tcp_listen.c:279)
rds_tcp_init_net (net/rds/tcp.c:577)
ops_init (net/core/net_namespace.c:137)
setup_net (net/core/net_namespace.c:340)
copy_net_ns (net/core/net_namespace.c:497)
create_new_namespaces (kernel/nsproxy.c:110)
unshare_nsproxy_namespaces (kernel/nsproxy.c:228 (discriminator 4))
ksys_unshare (kernel/fork.c:3429)
__x64_sys_unshare (kernel/fork.c:3496)
do_syscall_64 (arch/x86/entry/common.c:52 arch/x86/entry/common.c:83)
entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:129)
...
WARNING: CPU: 0 PID: 27 at lib/ref_tracker.c:179 ref_tracker_dir_exit (lib/ref_tracker.c:179)[1]:
BUG: KASAN: slab-use-after-free in inet_csk_reqsk_queue_drop (./include/net/inet_hashtables.h:180 net/ipv4/inet_connection_sock.c:952 net/ipv4/inet_connection_sock.c:966) Read of size 8 at addr ffff88801b370400 by task swapper/0/0 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.0-0-gd239552ce722-prebuilt.qemu.org 04/01/2014 Call Trace: <IRQ> dump_stack_lvl (lib/dump_stack.c:107 (discriminator 1)) print_report (mm/kasan/report.c:378 mm/kasan/report.c:488) kasan_report (mm/kasan/report.c:603) inet_csk_reqsk_queue_drop (./include/net/inet_hashtables.h:180 net/ipv4/inet_connection_sock.c:952 net/ipv4/inet_connection_sock.c:966) reqsk_timer_handler (net/ipv4/inet_connection_sock.c:979 net/ipv4/inet_connection_sock.c:1092) call_timer_fn (./arch/x86/include/asm/jump_label.h:27 ./include/linux/jump_label.h:207 ./include/trace/events/timer.h:127 kernel/time/timer.c:1701) __run_timers.part.0 (kernel/time/timer.c:1752 kernel/time/timer.c:2038) run_timer_softirq (kernel/time/timer.c:2053) __do_softirq (./arch/x86/include/asm/jump_label.h:27 ./include/linux/jump_label.h:207 ./include/trace/events/irq.h:142 kernel/softirq.c:554) irq_exit_rcu (kernel/softirq.c:427 kernel/softirq.c:632 kernel/softirq.c:644) sysvec_apic_timer_interrupt (arch/x86/kernel/apic/apic.c:1076 (discriminator 14)) </IRQ> Allocated by task 258 on cpu 0 at 83.612050s: kasan_save_stack (mm/kasan/common.c:48) kasan_save_track (mm/kasan/common.c:68) __kasan_slab_alloc (mm/kasan/common.c:343) kmem_cache_alloc (mm/slub.c:3813 mm/slub.c:3860 mm/slub.c:3867) copy_net_ns (./include/linux/slab.h:701 net/core/net_namespace.c:421 net/core/net_namespace.c:480) create_new_namespaces (kernel/nsproxy.c:110) unshare_nsproxy_namespaces (kernel/nsproxy.c:228 (discriminator 4)) ksys_unshare (kernel/fork.c:3429) __x64_sys_unshare (kernel/fork.c:3496) do_syscall_64 (arch/x86/entry/common.c:52 arch/x86/entry/common.c:83) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:129) Freed by task 27 on cpu 0 at 329.158864s: kasan_save_stack (mm/kasan/common.c:48) kasan_save_track (mm/kasan/common.c:68) kasan_save_free_info (mm/kasan/generic.c:643) __kasan_slab_free (mm/kasan/common.c:265) kmem_cache_free (mm/slub.c:4299 mm/slub.c:4363) cleanup_net (net/core/net_namespace.c:456 net/core/net_namespace.c:446 net/core/net_namespace.c:639) process_one_work (kernel/workqueue.c:2638) worker_thread (kernel/workqueue.c:2700 kernel/workqueue.c:2787) kthread (kernel/kthread.c:388) ret_from_fork (arch/x86/kernel/process.c:153) ret_from_fork_asm (arch/x86/entry/entry_64.S:250) The buggy address belongs to the object at ffff88801b370000 which belongs to the cache net_namespace of size 4352
The buggy address is located 1024 bytes inside of
freed 4352-byte region [ffff88801b370000, ffff88801b371100)
[2]:
WARNING: CPU: 0 PID: 95 at lib/ref_tracker.c:228 ref_tracker_free (lib/ref_tracker.c:228 (discriminator 1)) Modules linked in: Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.0-0-gd239552ce722-prebuilt.qemu.org 04/01/2014 RIP: 0010:ref_tracker_free (lib/ref_tracker.c:228 (discriminator 1)) ... Call Trace: <IRQ> __sk_destruct (./include/net/net_namespace.h:353 net/core/sock.c:2204) rcu_core (./arch/x86/include/asm/preempt.h:26 kernel/rcu/tree.c:2165 kernel/rcu/tree.c:2433) __do_softirq (./arch/x86/include/asm/jump_label.h:27 ./include/linux/jump_label.h:207 ./include/trace/events/irq.h:142 kernel/softirq.c:554) irq_exit_rcu (kernel/softirq.c:427 kernel/softirq.c:632 kernel/softirq.c:644) sysvec_apic_timer_interrupt (arch/x86/kernel/apic/apic.c:1076 (discriminator 14)) </IRQ>
--- net/rds/tcp_listen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/rds/tcp_listen.c +2 -2
@@ -274,8 +274,8 @@ struct socket *rds_tcp_listen_init(struct net *net, bool isv6)int addr_len;int ret; - ret =sock_create_kern (net, isv6 ?PF_INET6 :PF_INET ,SOCK_STREAM , -IPPROTO_TCP , &sock); + ret =__sock_create (net, isv6 ?PF_INET6 :PF_INET ,SOCK_STREAM , +IPPROTO_TCP , &sock,SOCKET_KERN_NET_REF );if (ret <0 ) {rdsdebug ("could not create %s listener socket: %d\n" , isv6 ?"IPv6" :"IPv4" , ret);
Signature · 1 line
2.30.2
Re: [PATCH v2 net 4/5] rds: tcp: Fix use-after-free of net in reqsk_timer_handler().
Quoted 52 lines · Kuniyuki Iwashima
syzkaller reported a warning of netns tracker [0] followed by KASAN splat [1] and another ref tracker warning [1].
syzkaller could not find a repro, but in the log, the only suspicious sequence was as follows:
18:26:22 executing program 1:
r0 = socket$inet6_mptcp(0xa,0x1,0x106)
...
connect$inet6(r0, &(0x7f0000000080)={0xa,0x4001,0x0, @loopback},0x1c) (async)The notable thing here is
0x4001inconnect(), which isRDS_TCP_PORT.So, the scenario would be:
1.
unshare(CLONE_NEWNET)creates a per netns tcp listener inrds_tcp_listen_init().2. syz-executor connect()s to it and creates a reqsk.
3. syz-executor exit()s immediately.
4. netns is dismantled. [0]
5. reqsk timer is fired, and UAF happens while freeing reqsk. [1]
6. listener is freed after RCU grace period. [2]Basically, reqsk assumes that the listener guarantees netns safety until all reqsk timers are expired by holding the listener's refcount. However, this was not the case for kernel sockets.
Commit
740ea3c4a0b2("tcp: Clean up kernel listener's reqsk ininet_twsk_purge()") fixed this issue only for per-netns ehash, but the issue still exists for the global ehash.We can apply the same fix, but this issue is specific to RDS.
Instead of iterating ehash and purging reqsk during netns dismantle, let's hold netns refcount for the kernel listener.
Reported-by syzkaller <[email protected]>Suggested-by Eric Dumazet <[email protected]>Fixes 467fa15356ac ("RDS-TCP: Support multiple RDS-TCP listen endpoints, one per netns.")Signed-off-by Kuniyuki Iwashima <[email protected]>--- net/rds/tcp_listen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)net/rds/tcp_listen.c +0
-0
net/rds/tcp_listen.c struct socket *rds_tcp_listen_init(struct net *net, bool isv6) · line 281
Quoted 10 lines
net/rds/tcp_listen.c +2
-2@@ -274,8 +274,8 @@ struct socket *rds_tcp_listen_init(struct net *net, bool isv6)int addr_len;int ret; - ret =sock_create_kern (net, isv6 ?PF_INET6 :PF_INET ,SOCK_STREAM , -IPPROTO_TCP , &sock); + ret =__sock_create (net, isv6 ?PF_INET6 :PF_INET ,SOCK_STREAM , +IPPROTO_TCP , &sock,SOCKET_KERN_NET_REF );if (ret <0 ) {rdsdebug ("could not create %s listener socket: %d\n" , isv6 ?"IPv6" :"IPv4" , ret);
If RDS module keeps a listener alive, not attached to a user process, netns dismantle will never occur.
I think we have to cleanup SYN_RECV sockets in inet_twsk_purge()
Yes, it removes one optimization you did.
Perhaps add a counter of all kernel sockets that were ever attached to a netns in order to decide to apply the optimization. (keeping a precise count of SYN_RECV would be too expensive)
Re: [PATCH v2 net 4/5] rds: tcp: Fix use-after-free of net in reqsk_timer_handler().
From: Eric Dumazet <[email protected]>
Date: Tue, 27 Feb 2024 13:06:07 +0100
Quoted 67 lines · Kuniyuki Iwashima
Quoted 52 lines
syzkaller reported a warning of netns tracker [0] followed by KASAN splat [1] and another ref tracker warning [1].
syzkaller could not find a repro, but in the log, the only suspicious sequence was as follows:
18:26:22 executing program 1:
r0 = socket$inet6_mptcp(0xa,0x1,0x106)
...
connect$inet6(r0, &(0x7f0000000080)={0xa,0x4001,0x0, @loopback},0x1c) (async)The notable thing here is
0x4001inconnect(), which isRDS_TCP_PORT.So, the scenario would be:
1.
unshare(CLONE_NEWNET)creates a per netns tcp listener inrds_tcp_listen_init().2. syz-executor connect()s to it and creates a reqsk.
3. syz-executor exit()s immediately.
4. netns is dismantled. [0]
5. reqsk timer is fired, and UAF happens while freeing reqsk. [1]
6. listener is freed after RCU grace period. [2]Basically, reqsk assumes that the listener guarantees netns safety until all reqsk timers are expired by holding the listener's refcount. However, this was not the case for kernel sockets.
Commit
740ea3c4a0b2("tcp: Clean up kernel listener's reqsk ininet_twsk_purge()") fixed this issue only for per-netns ehash, but the issue still exists for the global ehash.We can apply the same fix, but this issue is specific to RDS.
Instead of iterating ehash and purging reqsk during netns dismantle, let's hold netns refcount for the kernel listener.
Reported-by syzkaller <[email protected]>Suggested-by Eric Dumazet <[email protected]>Fixes 467fa15356ac ("RDS-TCP: Support multiple RDS-TCP listen endpoints, one per netns.")Signed-off-by Kuniyuki Iwashima <[email protected]>--- net/rds/tcp_listen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)net/rds/tcp_listen.c +0
-0net/rds/tcp_listen.c struct socket *rds_tcp_listen_init(struct net *net, bool isv6) · line 281
Quoted 10 lines
net/rds/tcp_listen.c +2
-2@@ -274,8 +274,8 @@ struct socket *rds_tcp_listen_init(struct net *net, bool isv6)int addr_len;int ret; - ret =sock_create_kern (net, isv6 ?PF_INET6 :PF_INET ,SOCK_STREAM , -IPPROTO_TCP , &sock); + ret =__sock_create (net, isv6 ?PF_INET6 :PF_INET ,SOCK_STREAM , +IPPROTO_TCP , &sock,SOCKET_KERN_NET_REF );if (ret <0 ) {rdsdebug ("could not create %s listener socket: %d\n" , isv6 ?"IPv6" :"IPv4" , ret);If RDS module keeps a listener alive, not attached to a user process, netns dismantle will never occur.
Quoted 1 line
I think we have to cleanup
SYN_RECVsockets ininet_twsk_purge()
Ah.. yes, __init_net ops hook must not take net ref.. I'll go that way in v3.
Quoted 6 lines
Yes, it removes one optimization you did.
Perhaps add a counter of all kernel sockets that were ever attached to a netns in order to decide to apply the optimization. (keeping a precise count of
SYN_RECVwould be too expensive)
I'll work on the follow-up for net-next after the right fix is merged.
Thanks!
PATCH v2 5/5 tcp: Add assertion for reqsk->rsk_listener->sk_net_refcnt.
In reply to Kuniyuki Iwashimasyzbot demonstrated that a reqsk timer could be fired after netns dismantle if the timer was kicked by kernel TCP listener.
Regardless of the owner of the socket, TCP listener always has to hold netns refcount.
Let's make sure that new user will not create kernel TCP listener without holding netns refcount.
--- net/ipv4/tcp_input.c | 2 ++ 1 file changed, 2 insertions(+)
net/ipv4/tcp_input.c +2 -0
@@ -6972,6 +6972,8 @@ struct request_sock *inet_reqsk_alloc(const struct request_sock_ops *ops,if (req) {struct inet_request_sock *ireq =inet_rsk (req); +DEBUG_NET_WARN_ON_ONCE (!sk_listener->sk_net_refcnt); + ireq->ireq_opt =NULL ;#if IS_ENABLED (CONFIG_IPV6 ) ireq->pktopts =NULL ;
Signature · 1 line
2.30.2