From: Wei Wang <wei...@google.com>

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 <wei...@google.com>
Acked-by: Eric Dumazet <eduma...@google.com>
Acked-by: Willem de Bruijn <will...@google.com>
---
 kernel/bpf/sockmap.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/kernel/bpf/sockmap.c b/kernel/bpf/sockmap.c
index 95a84b2f10ce..1984922f99ee 100644
--- a/kernel/bpf/sockmap.c
+++ b/kernel/bpf/sockmap.c
@@ -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;
-- 
2.17.1.1185.g55be947832-goog

Reply via email to