summaryrefslogtreecommitdiffstats
path: root/kernel/bpf
diff options
context:
space:
mode:
authorDaniel Borkmann <daniel@iogearbox.net>2018-08-21 15:55:00 +0200
committerDaniel Borkmann <daniel@iogearbox.net>2018-08-22 20:34:51 +0200
commitb845c898b2f1ea458d5453f0fa1da6e2dfce3bb4 (patch)
treed458693137c517ac84ff3195e1bb3e76019473b8 /kernel/bpf
parent96c26e04581667e3cd17ed74c2fc3499afea49b8 (diff)
downloadlinux-b845c898b2f1ea458d5453f0fa1da6e2dfce3bb4.tar.bz2
bpf, sockmap: fix sock_hash_alloc and reject zero-sized keys
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 <daniel@iogearbox.net> Acked-by: John Fastabend <john.fastabend@gmail.com> Acked-by: Song Liu <songliubraving@fb.com>
Diffstat (limited to 'kernel/bpf')
-rw-r--r--kernel/bpf/sockmap.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/kernel/bpf/sockmap.c b/kernel/bpf/sockmap.c
index 98e621a29e8e..60ceb0e1fa56 100644
--- a/kernel/bpf/sockmap.c
+++ b/kernel/bpf/sockmap.c
@@ -2140,7 +2140,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);