Skip to contentSkip to conversation

bpf: fix flags check in bpf_percpu_cgroup_storage_update()

PATCH In review Roman Gushchin 2 participants 3 messages Sep 28, 2018

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

PATCH 1/1 bpf: fix flags check in bpf_percpu_cgroup_storage_update()

Fix an issue in bpf_percpu_cgroup_storage_update(): it should return -EINVAL on an attempt to pass BPF_NOEXIST rather than BPF_EXIST.

Cgroup local storage is automatically created on attaching of a bpf program to a cgroup, and it can't be done from the userspace.

Fixes 0daef9b42374 ("bpf: introduce per-cpu cgroup local storage")
Cc Daniel Borkmann <[email protected]>
Cc Alexei Starovoitov <[email protected]>
---
 kernel/bpf/local_storage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/local_storage.c +1 -1
index c739f6dcc3c2..190535f6d5e2 100644
@@ -191,7 +191,7 @@ int bpf_percpu_cgroup_storage_update(struct bpf_map *_map, void *_key,
 	int cpu, off = 0;
 	u32 size;
 
-	if (unlikely(map_flags & BPF_EXIST))
+	if (map_flags & BPF_NOEXIST)
 		return -EINVAL;
 
 	rcu_read_lock();
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 19 lines · Roman Gushchin

Fix an issue in bpf_percpu_cgroup_storage_update(): it should return -EINVAL on an attempt to pass BPF_NOEXIST rather than BPF_EXIST.

Cgroup local storage is automatically created on attaching of a bpf program to a cgroup, and it can't be done from the userspace.

Fixes 0daef9b42374 ("bpf: introduce per-cpu cgroup local storage")
Cc Daniel Borkmann <[email protected]>
Cc Alexei Starovoitov <[email protected]>
---
 kernel/bpf/local_storage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/local_storage.c +0 -0
index c739f6dcc3c2..190535f6d5e2 100644

kernel/bpf/local_storage.c int bpf_percpu_cgroup_storage_update(struct bpf_map *_map, void *_key, · line 195

Quoted 6 lines
kernel/bpf/local_storage.c +1 -1
@@ -191,7 +191,7 @@ int bpf_percpu_cgroup_storage_update(struct bpf_map *_map, void *_key,
 	int cpu, off = 0;
 	u32 size;
 
-	if (unlikely(map_flags & BPF_EXIST))
+	if (map_flags & BPF_NOEXIST)
 		return -EINVAL;

Hmm, this is also incorrect as any future reserved flag would be accepted here and couldn't be extended anymore. :/ And it looks like cgroup_storage_update_elem() is doing the same today, given the cgroups local storage is still early, we should route a patch to stable for fixing this.

Wrt this series, given the series is top of tree right now, I would prefer a fresh respin so we have the fix integrated properly w/o follow-up. Perhaps this could also incorporate Alexei's previous cleanup suggestions as well from today if you have a chance.

Thanks,
Daniel

#2 lore raw
Quoted 23 lines · Daniel Borkmann
Quoted 22 lines · Roman Gushchin

Fix an issue in bpf_percpu_cgroup_storage_update(): it should return -EINVAL on an attempt to pass BPF_NOEXIST rather than BPF_EXIST.

Cgroup local storage is automatically created on attaching of a bpf program to a cgroup, and it can't be done from the userspace.

Fixes 0daef9b42374 ("bpf: introduce per-cpu cgroup local storage")
Cc Daniel Borkmann <[email protected]>
Cc Alexei Starovoitov <[email protected]>
---
 kernel/bpf/local_storage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/local_storage.c +0 -0
index c739f6dcc3c2..190535f6d5e2 100644
@@ -191,7 +191,7 @@ int bpf_percpu_cgroup_storage_update(struct bpf_map *_map, void *_key,
 	int cpu, off = 0;
 	u32 size;
 
Quoted 8 lines

kernel/bpf/local_storage.c int bpf_percpu_cgroup_storage_update(struct bpf_map *_map, void *_key, · line 195

Quoted 3 lines
kernel/bpf/local_storage.c +1 -1
-	if (unlikely(map_flags & BPF_EXIST))
+	if (map_flags & BPF_NOEXIST)
 		return -EINVAL;

Hmm, this is also incorrect as any future reserved flag would be accepted here and couldn't be extended anymore. :/ And it looks like cgroup_storage_update_elem() is doing the same today, given the cgroups local storage is still early, we should route a patch to stable for fixing this.

Fair enough, will post soon.

Quoted 5 lines

Wrt this series, given the series is top of tree right now, I would prefer a fresh respin so we have the fix integrated properly w/o follow-up. Perhaps this could also incorporate Alexei's previous cleanup suggestions as well from today if you have a chance.

I'm not sure about merging copy() and update() functions, as large #define blocks are really bad. So I'd think a bit more here. Will do the rest.

Thanks!