Skip to contentSkip to conversation

bpf: prevent non-ipv4 socket to be added into sock map

PATCH New Wei Wang 1 participant 1 message May 30, 2018

Subsystems (3)
lore
Share & tools
lore

Wei Wang

author
#0 lore raw

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")
---
 kernel/bpf/sockmap.c | 5 +++++
 1 file changed, 5 insertions(+)
kernel/bpf/sockmap.c +5 -0
index 95a84b2f10ce..1984922f99ee 100644
@@ -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