ipv6: tcp: fix flowlabels reflection for RST packets
Subsystems (5)
PATCH 1/1 ipv6: tcp: fix flowlabels reflection for RST packets
In 323a53c41292 ("ipv6: tcp: enable flowlabel reflection in some RST packets") and 50a8accf1062 ("ipv6: tcp: send consistent flowlabel in TIME_WAIT state") we took care of IPv6 flowlabel reflections for two cases.
This patch takes care of the remaining case, when the RST packet is sent on behalf of a 'full' socket.
In Marek use case, this was a socket in TCP_CLOSE state.
--- net/ipv6/tcp_ipv6.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/ipv6/tcp_ipv6.c +6 -1
@@ -984,8 +984,13 @@ static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb)if (sk) { oif = sk->sk_bound_dev_if; -if (sk_fullsock (sk)) +if (sk_fullsock (sk)) { +const struct ipv6_pinfo *np =tcp_inet6_sk (sk); +trace_tcp_send_reset (sk, skb); +if (np->repflow) + label =ip6_flowlabel (ipv6h); + }if (sk->sk_state ==TCP_TIME_WAIT ) label =cpu_to_be32 (inet_twsk (sk)->tw_flowlabel); }else {
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH 1/1 ipv6: fix potential crash in ip6_datagram_dst_update()
Willem forgot to change one of the calls to fl6_sock_lookup(), which can now return an error or NULL.
syzbot reported :
kasan: CONFIG_KASAN_INLINE enabled
kasan: GPF could be caused by NULL-ptr deref or user memory access
general protection fault: 0000 [#1] PREEMPT SMP KASAN CPU: 1 PID: 31763 Comm: syz-executor.0 Not tainted 5.2.0-rc6+ #63 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 RIP: 0010:ip6_datagram_dst_update+0x559/0xc30 net/ipv6/datagram.c:83 Code: 00 00 e8 ea 29 3f fb 4d 85 f6 0f 84 96 04 00 00 e8 dc 29 3f fb 49 8d 7e 20 48 b8 00 00 00 00 00 fc ff df 48 89 fa 48 c1 ea 03 <80> 3c 02 00 0f 85 16 06 00 00 4d 8b 6e 20 e8 b4 29 3f fb 4c 89 ee RSP: 0018:ffff88809ba97ae0 EFLAGS: 00010207 RAX: dffffc0000000000 RBX: ffff8880a81254b0 RCX: ffffc90008118000 RDX: 0000000000000003 RSI: ffffffff86319a84 RDI: 000000000000001e RBP: ffff88809ba97c10 R08: ffff888065e9e700 R09: ffffed1015d26c80 R10: ffffed1015d26c7f R11: ffff8880ae9363fb R12: ffff8880a8124f40 R13: 0000000000000001 R14: fffffffffffffffe R15: ffff88809ba97b40 FS: 00007f38e606a700(0000) GS:ffff8880ae900000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00000000202c0140 CR3: 00000000a026a000 CR4: 00000000001406e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: __ip6_datagram_connect+0x5e9/0x1390 net/ipv6/datagram.c:246 ip6_datagram_connect+0x30/0x50 net/ipv6/datagram.c:269 ip6_datagram_connect_v6_only+0x69/0x90 net/ipv6/datagram.c:281 inet_dgram_connect+0x14a/0x2d0 net/ipv4/af_inet.c:571 __sys_connect+0x264/0x330 net/socket.c:1824 __do_sys_connect net/socket.c:1835 [inline] __se_sys_connect net/socket.c:1832 [inline] __x64_sys_connect+0x73/0xb0 net/socket.c:1832 do_syscall_64+0xfd/0x680 arch/x86/entry/common.c:301 entry_SYSCALL_64_after_hwframe+0x49/0xbe RIP: 0033:0x4597c9 Code: fd b7 fb ff c3 66 2e 0f 1f 84 00 00 00 00 00 66 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 0f 83 cb b7 fb ff c3 66 2e 0f 1f 84 00 00 00 00 RSP: 002b:00007f38e6069c78 EFLAGS: 00000246 ORIG_RAX: 000000000000002a RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 00000000004597c9 RDX: 000000000000001c RSI: 0000000020000040 RDI: 0000000000000003 RBP: 000000000075bf20 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 00007f38e606a6d4 R13: 00000000004bfd07 R14: 00000000004d1838 R15: 00000000ffffffff Modules linked in: RIP: 0010:ip6_datagram_dst_update+0x559/0xc30 net/ipv6/datagram.c:83 Code: 00 00 e8 ea 29 3f fb 4d 85 f6 0f 84 96 04 00 00 e8 dc 29 3f fb 49 8d 7e 20 48 b8 00 00 00 00 00 fc ff df 48 89 fa 48 c1 ea 03 <80> 3c 02 00 0f 85 16 06 00 00 4d 8b 6e 20 e8 b4 29 3f fb 4c 89 ee
--- net/ipv6/datagram.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/datagram.c +1 -1
@@ -74,7 +74,7 @@ int ip6_datagram_dst_update(struct sock *sk, bool fix_sk_saddr)if (np->sndflow && (np->flow_label &IPV6_FLOWLABEL_MASK )) { flowlabel =fl6_sock_lookup (sk, np->flow_label); -if (!flowlabel) +if (IS_ERR (flowlabel))return -EINVAL ; }ip6_datagram_flow_key_init (&fl6, sk);
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
Re: [PATCH net] ipv6: fix potential crash in ip6_datagram_dst_update()
From: Eric Dumazet <[email protected]>
Date: Wed, 10 Jul 2019 06:40:10 -0700
Quoted 4 lines
Willem forgot to change one of the calls to
fl6_sock_lookup(), which can now return an error or NULL.syzbot reported :
...
Quoted 4 lines
Fixes 59c820b2317f ("ipv6: elide flowlabel check if no exclusive leases exist")Signed-off-by Eric Dumazet <[email protected]>Acked-by Willem de Bruijn <[email protected]>Reported-by syzbot <[email protected]>
Applied.
PATCH 1/1 ipv6: fix static key imbalance in fl_create()
In reply to Eric Dumazetfl_create() should call static_branch_deferred_inc() only in case of success.
Also we should not call fl_free() in error path, as this could cause a static key imbalance.
jump label: negative count!
WARNING: CPU: 0 PID: 15907 at kernel/jump_label.c:221 static_key_slow_try_dec kernel/jump_label.c:221 [inline] WARNING: CPU: 0 PID: 15907 at kernel/jump_label.c:221 static_key_slow_try_dec+0x1ab/0x1d0 kernel/jump_label.c:206 Kernel panic - not syncing: panic_on_warn set ... CPU: 0 PID: 15907 Comm: syz-executor.2 Not tainted 5.2.0-rc6+ #62 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Call Trace: __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0x172/0x1f0 lib/dump_stack.c:113 panic+0x2cb/0x744 kernel/panic.c:219 __warn.cold+0x20/0x4d kernel/panic.c:576 report_bug+0x263/0x2b0 lib/bug.c:186 fixup_bug arch/x86/kernel/traps.c:179 [inline] fixup_bug arch/x86/kernel/traps.c:174 [inline] do_error_trap+0x11b/0x200 arch/x86/kernel/traps.c:272 do_invalid_op+0x37/0x50 arch/x86/kernel/traps.c:291 invalid_op+0x14/0x20 arch/x86/entry/entry_64.S:986 RIP: 0010:static_key_slow_try_dec kernel/jump_label.c:221 [inline] RIP: 0010:static_key_slow_try_dec+0x1ab/0x1d0 kernel/jump_label.c:206 Code: c0 e8 e9 3e e5 ff 83 fb 01 0f 85 32 ff ff ff e8 5b 3d e5 ff 45 31 ff eb a0 e8 51 3d e5 ff 48 c7 c7 40 99 92 87 e8 13 75 b7 ff <0f> 0b eb 8b 4c 89 e7 e8 a9 c0 1e 00 e9 de fe ff ff e8 bf 6d b7 ff RSP: 0018:ffff88805f9c7450 EFLAGS: 00010286 RAX: 0000000000000000 RBX: 00000000ffffffff RCX: 0000000000000000 RDX: 000000000000e3e1 RSI: ffffffff815adb06 RDI: ffffed100bf38e7c RBP: ffff88805f9c74e0 R08: ffff88806acf0700 R09: ffffed1015d060a9 R10: ffffed1015d060a8 R11: ffff8880ae830547 R12: ffffffff89832ce0 R13: ffff88805f9c74b8 R14: 1ffff1100bf38e8b R15: 00000000ffffff01 __static_key_slow_dec_deferred+0x65/0x110 kernel/jump_label.c:272 fl_free+0xa9/0xe0 net/ipv6/ip6_flowlabel.c:121 fl_create+0x6af/0x9f0 net/ipv6/ip6_flowlabel.c:457 ipv6_flowlabel_opt+0x80e/0x2730 net/ipv6/ip6_flowlabel.c:624 do_ipv6_setsockopt.isra.0+0x2119/0x4100 net/ipv6/ipv6_sockglue.c:825 ipv6_setsockopt+0xf6/0x170 net/ipv6/ipv6_sockglue.c:944 tcp_setsockopt net/ipv4/tcp.c:3131 [inline] tcp_setsockopt+0x8f/0xe0 net/ipv4/tcp.c:3125 sock_common_setsockopt+0x94/0xd0 net/core/sock.c:3130 __sys_setsockopt+0x253/0x4b0 net/socket.c:2080 __do_sys_setsockopt net/socket.c:2096 [inline] __se_sys_setsockopt net/socket.c:2093 [inline] __x64_sys_setsockopt+0xbe/0x150 net/socket.c:2093 do_syscall_64+0xfd/0x680 arch/x86/entry/common.c:301 entry_SYSCALL_64_after_hwframe+0x49/0xbe RIP: 0033:0x4597c9 Code: fd b7 fb ff c3 66 2e 0f 1f 84 00 00 00 00 00 66 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 0f 83 cb b7 fb ff c3 66 2e 0f 1f 84 00 00 00 00 RSP: 002b:00007f2670556c78 EFLAGS: 00000246 ORIG_RAX: 0000000000000036 RAX: ffffffffffffffda RBX: 0000000000000005 RCX: 00000000004597c9 RDX: 0000000000000020 RSI: 0000000000000029 RDI: 0000000000000003 RBP: 000000000075bfc8 R08: 000000000000fdf7 R09: 0000000000000000 R10: 0000000020000000 R11: 0000000000000246 R12: 00007f26705576d4 R13: 00000000004cec00 R14: 00000000004dd520 R15: 00000000ffffffff
Kernel Offset: disabled
Rebooting in 86400 seconds..
--- net/ipv6/ip6_flowlabel.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
net/ipv6/ip6_flowlabel.c +6 -3
@@ -435,8 +435,6 @@ fl_create(struct net *net, struct sock *sk, struct in6_flowlabel_req *freq, } fl->dst = freq->flr_dst;atomic_set (&fl->users,1 ); -if (fl_shared_exclusive (fl) || fl->opt) -static_branch_deferred_inc (&ipv6_flowlabel_exclusive);switch (fl->share) {case IPV6_FL_S_EXCL :case IPV6_FL_S_ANY :
@@ -451,10 +449,15 @@ fl_create(struct net *net, struct sock *sk, struct in6_flowlabel_req *freq, err = -EINVAL ; goto done; } +if (fl_shared_exclusive (fl) || fl->opt) +static_branch_deferred_inc (&ipv6_flowlabel_exclusive);return fl; done: -fl_free (fl); +if (fl) { +kfree (fl->opt); +kfree (fl); + } *err_p = err;return NULL ; }
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
Re: [PATCH net] ipv6: fix static key imbalance in fl_create()
From: Eric Dumazet <[email protected]>
Date: Wed, 10 Jul 2019 06:40:11 -0700
Quoted 5 lines
fl_create()should callstatic_branch_deferred_inc()only in case of success.Also we should not call
fl_free()in error path, as this could cause a static key imbalance.
...
Quoted 4 lines
Fixes 59c820b2317f ("ipv6: elide flowlabel check if no exclusive leases exist")Signed-off-by Eric Dumazet <[email protected]>Acked-by Willem de Bruijn <[email protected]>Reported-by syzbot <[email protected]>
Applied.
From: Eric Dumazet <[email protected]>
Date: Wed, 10 Jul 2019 06:40:09 -0700
Quoted 4 lines
In
323a53c41292("ipv6: tcp: enable flowlabel reflection in some RST packets") and50a8accf1062("ipv6: tcp: send consistent flowlabel inTIME_WAITstate") we took care of IPv6 flowlabel reflections for two cases.
Quoted 8 lines
This patch takes care of the remaining case, when the RST packet is sent on behalf of a 'full' socket.
In Marek use case, this was a socket in
TCP_CLOSEstate.Signed-off-by Eric Dumazet <[email protected]>Reported-by Marek Majkowski <[email protected]>Tested-by Marek Majkowski <[email protected]>
Applied.