Skip to content

Commit 8897562

Browse files
lmbMartin KaFai Lau
authored andcommitted
net: Fix slab-out-of-bounds in inet[6]_steal_sock
Kumar reported a KASAN splat in tcp_v6_rcv: bash-5.2# ./test_progs -t btf_skc_cls_ingress ... [ 51.810085] BUG: KASAN: slab-out-of-bounds in tcp_v6_rcv+0x2d7d/0x3440 [ 51.810458] Read of size 2 at addr ffff8881053f038c by task test_progs/226 The problem is that inet[6]_steal_sock accesses sk->sk_protocol without accounting for request or timewait sockets. To fix this we can't just check sock_common->skc_reuseport since that flag is present on timewait sockets. Instead, add a fullsock check to avoid the out of bands access of sk_protocol. Fixes: 9c02bec ("bpf, net: Support SO_REUSEPORT sockets with bpf_sk_assign") Reported-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Signed-off-by: Lorenz Bauer <lmb@isovalent.com> Link: https://lore.kernel.org/r/20230815-bpf-next-v2-1-95126eaa4c1b@isovalent.com Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
1 parent dda7704 commit 8897562

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

include/net/inet6_hashtables.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ struct sock *inet6_steal_sock(struct net *net, struct sk_buff *skb, int doff,
116116
if (!sk)
117117
return NULL;
118118

119-
if (!prefetched)
119+
if (!prefetched || !sk_fullsock(sk))
120120
return sk;
121121

122122
if (sk->sk_protocol == IPPROTO_TCP) {

include/net/inet_hashtables.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ struct sock *inet_steal_sock(struct net *net, struct sk_buff *skb, int doff,
462462
if (!sk)
463463
return NULL;
464464

465-
if (!prefetched)
465+
if (!prefetched || !sk_fullsock(sk))
466466
return sk;
467467

468468
if (sk->sk_protocol == IPPROTO_TCP) {

0 commit comments

Comments
 (0)