bpf: harden flags check in cgroup_storage_update_elem()
authorRoman Gushchin <guro@fb.com>
Fri, 28 Sep 2018 13:33:21 +0000 (14:33 +0100)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 28 Sep 2018 13:50:23 +0000 (15:50 +0200)
cgroup_storage_update_elem() shouldn't accept any flags
argument values except BPF_ANY and BPF_EXIST to guarantee
the backward compatibility, had a new flag value been added.

Fixes: de9cbbaadba5 ("bpf: introduce cgroup storage maps")
Signed-off-by: Roman Gushchin <guro@fb.com>
Reported-by: Daniel Borkmann <daniel@iogearbox.net>
Cc: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
kernel/bpf/local_storage.c

index 22ad967d1e5f14b9bafd41a99117b97700e041f6..94126cbffc880f76d50ede6b21940348890343f7 100644 (file)
@@ -129,7 +129,7 @@ static int cgroup_storage_update_elem(struct bpf_map *map, void *_key,
        struct bpf_cgroup_storage *storage;
        struct bpf_storage_buffer *new;
 
-       if (flags & BPF_NOEXIST)
+       if (flags != BPF_ANY && flags != BPF_EXIST)
                return -EINVAL;
 
        storage = cgroup_storage_lookup((struct bpf_cgroup_storage_map *)map,