Skip to contentSkip to conversation

bpf: harden flags check in cgroup_storage_update_elem()

PATCH Applied Roman Gushchin 2 participants 2 messages Sep 28, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: harden flags check in cgroup_storage_update_elem()

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")
Cc Alexei Starovoitov <[email protected]>
Cc Daniel Borkmann <[email protected]>
---
 kernel/bpf/local_storage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/local_storage.c +1 -1
index f8746e6a9a35..2a7680106320 100644
@@ -130,7 +130,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,
Signature · 1 line
2.17.1
maintainer Applied
#1 lore raw
Quoted 18 lines · Roman Gushchin

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")
Cc Alexei Starovoitov <[email protected]>
Cc Daniel Borkmann <[email protected]>
---
 kernel/bpf/local_storage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/local_storage.c +0 -0
index f8746e6a9a35..2a7680106320 100644

kernel/bpf/local_storage.c static int cgroup_storage_update_elem(struct bpf_map *map, void *_key, · line 136

Quoted 8 lines
kernel/bpf/local_storage.c +1 -1
@@ -130,7 +130,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,

Applied to bpf, thanks!