From: Daniel Borkmann Date: Tue, 21 Aug 2018 13:55:00 +0000 (+0200) Subject: bpf, sockmap: fix sock_hash_alloc and reject zero-sized keys X-Git-Tag: v4.18.12~49 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=efed642bc585c8d26bdba3b4de97d78057874bcf;p=users%2Fdwmw2%2Flinux.git bpf, sockmap: fix sock_hash_alloc and reject zero-sized keys [ Upstream commit b845c898b2f1ea458d5453f0fa1da6e2dfce3bb4 ] Currently, it is possible to create a sock hash map with key size of 0 and have the kernel return a fd back to user space. This is invalid for hash maps (and kernel also hasn't been tested for zero key size support in general at this point). Thus, reject such configuration. Fixes: 81110384441a ("bpf: sockmap, add hash map support") Signed-off-by: Daniel Borkmann Acked-by: John Fastabend Acked-by: Song Liu Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- diff --git a/kernel/bpf/sockmap.c b/kernel/bpf/sockmap.c index 58899601fccf2..dd87d930f036b 100644 --- a/kernel/bpf/sockmap.c +++ b/kernel/bpf/sockmap.c @@ -2143,7 +2143,9 @@ static struct bpf_map *sock_hash_alloc(union bpf_attr *attr) return ERR_PTR(-EPERM); /* check sanity of attributes */ - if (attr->max_entries == 0 || attr->value_size != 4 || + if (attr->max_entries == 0 || + attr->key_size == 0 || + attr->value_size != 4 || attr->map_flags & ~SOCK_CREATE_FLAG_MASK) return ERR_PTR(-EINVAL);