aboutsummaryrefslogtreecommitdiff
path: root/kernel/bpf
diff options
context:
space:
mode:
authorGravatar Benjamin Tissoires <bentiss@kernel.org> 2024-04-30 12:43:24 +0200
committerGravatar Daniel Borkmann <daniel@iogearbox.net> 2024-04-30 16:28:33 +0200
commitb98a5c68ccaa94e93b9e898091fe2cf21c1500e6 (patch)
tree1d966ca8b4a480aaa183bc5d1eb2759645af885a /kernel/bpf
parentselftests/bpf: validate nulled-out struct_ops program is handled properly (diff)
downloadlinux-b98a5c68ccaa94e93b9e898091fe2cf21c1500e6.tar.gz
linux-b98a5c68ccaa94e93b9e898091fe2cf21c1500e6.tar.bz2
linux-b98a5c68ccaa94e93b9e898091fe2cf21c1500e6.zip
bpf: Do not walk twice the map on free
If someone stores both a timer and a workqueue in a map, on free we would walk it twice. Add a check in array_map_free_timers_wq and free the timers and workqueues if they are present. Fixes: 246331e3f1ea ("bpf: allow struct bpf_wq to be embedded in arraymaps and hashmaps") Signed-off-by: Benjamin Tissoires <bentiss@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Link: https://lore.kernel.org/bpf/20240430-bpf-next-v3-1-27afe7f3b17c@kernel.org
Diffstat (limited to 'kernel/bpf')
-rw-r--r--kernel/bpf/arraymap.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c
index 580d07b15471..feabc0193852 100644
--- a/kernel/bpf/arraymap.c
+++ b/kernel/bpf/arraymap.c
@@ -436,13 +436,14 @@ static void array_map_free_timers_wq(struct bpf_map *map)
/* We don't reset or free fields other than timer and workqueue
* on uref dropping to zero.
*/
- if (btf_record_has_field(map->record, BPF_TIMER))
- for (i = 0; i < array->map.max_entries; i++)
- bpf_obj_free_timer(map->record, array_map_elem_ptr(array, i));
-
- if (btf_record_has_field(map->record, BPF_WORKQUEUE))
- for (i = 0; i < array->map.max_entries; i++)
- bpf_obj_free_workqueue(map->record, array_map_elem_ptr(array, i));
+ if (btf_record_has_field(map->record, BPF_TIMER | BPF_WORKQUEUE)) {
+ for (i = 0; i < array->map.max_entries; i++) {
+ if (btf_record_has_field(map->record, BPF_TIMER))
+ bpf_obj_free_timer(map->record, array_map_elem_ptr(array, i));
+ if (btf_record_has_field(map->record, BPF_WORKQUEUE))
+ bpf_obj_free_workqueue(map->record, array_map_elem_ptr(array, i));
+ }
+ }
}
/* Called when map->refcnt goes to zero, either from workqueue or from syscall */