bpf: prevent non-ipv4 socket to be added into sock map
Subsystems (3)
PATCH 1/1 bpf: prevent non-ipv4 socket to be added into sock map
From: Wei Wang <[email protected]>
Sock map only supports IPv4 socket proto right now.
If a non-IPv4 socket gets stored in the BPF map, sk->sk_prot gets overwritten with the v4 tcp prot.
It could potentially cause issues when invoking functions from sk->sk_prot later in the stack.
Fixes 174a79ff9515 ("bpf: sockmap with sk redirect support")
Signed-off-by Wei Wang <[email protected]>
Acked-by Eric Dumazet <[email protected]>
Acked-by Willem de Bruijn <[email protected]>
--- kernel/bpf/sockmap.c | 5 +++++ 1 file changed, 5 insertions(+)
kernel/bpf/sockmap.c +5 -0
@@ -1873,6 +1873,11 @@ static int sock_map_update_elem(struct bpf_map *map,return -EOPNOTSUPP ; } +if (skops.sk->sk_family !=AF_INET ) { +fput (socket->file); +return -EAFNOSUPPORT ; + } + err =sock_map_ctx_update_elem (&skops, map, key, flags);fput (socket->file);return err;
Signature · 1 line
2.17.1.1185.g55be947832-goog