mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-04-13 09:59:31 +00:00
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: 246331e3f1
("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
This commit is contained in:
parent
1bba3b3d37
commit
b98a5c68cc
1 changed files with 8 additions and 7 deletions
|
@ -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
|
/* We don't reset or free fields other than timer and workqueue
|
||||||
* on uref dropping to zero.
|
* on uref dropping to zero.
|
||||||
*/
|
*/
|
||||||
if (btf_record_has_field(map->record, BPF_TIMER))
|
if (btf_record_has_field(map->record, BPF_TIMER | BPF_WORKQUEUE)) {
|
||||||
for (i = 0; i < array->map.max_entries; i++)
|
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_TIMER))
|
||||||
|
bpf_obj_free_timer(map->record, array_map_elem_ptr(array, i));
|
||||||
if (btf_record_has_field(map->record, BPF_WORKQUEUE))
|
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));
|
||||||
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 */
|
/* Called when map->refcnt goes to zero, either from workqueue or from syscall */
|
||||||
|
|
Loading…
Add table
Reference in a new issue