Skip to content

Commit 9b28ae2

Browse files
lmbborkmann
authored andcommitted
bpf: fix out-of-bounds read in __bpf_skc_lookup
__bpf_skc_lookup takes a socket tuple and the length of the tuple as an argument. Based on the length, it decides which address family to pass to the helper function sk_lookup. In case of AF_INET6, it fails to verify that the length of the tuple is long enough. sk_lookup may therefore access data past the end of the tuple. Fixes: 6acc9b4 ("bpf: Add helper to retrieve socket in BPF") Signed-off-by: Lorenz Bauer <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent 221fb72 commit 9b28ae2

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

net/core/filter.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5304,7 +5304,13 @@ __bpf_skc_lookup(struct sk_buff *skb, struct bpf_sock_tuple *tuple, u32 len,
53045304
struct net *net;
53055305
int sdif;
53065306

5307-
family = len == sizeof(tuple->ipv4) ? AF_INET : AF_INET6;
5307+
if (len == sizeof(tuple->ipv4))
5308+
family = AF_INET;
5309+
else if (len == sizeof(tuple->ipv6))
5310+
family = AF_INET6;
5311+
else
5312+
return NULL;
5313+
53085314
if (unlikely(family == AF_UNSPEC || flags ||
53095315
!((s32)netns_id < 0 || netns_id <= S32_MAX)))
53105316
goto out;

0 commit comments

Comments
 (0)