Skip to content

Commit b49558c

Browse files
Asphalttanakryiko
authored andcommitted
bpf: Free special fields when update local storage maps
When updating local storage maps with BPF_F_LOCK on the fast path, the special fields were not freed after being replaced. This could cause memory referenced by BPF_KPTR_{REF,PERCPU} fields to be held until the map gets freed. Similarly, on the other path, the old sdata's special fields were never freed regardless of whether BPF_F_LOCK was used, causing the same issue. Fix this by calling 'bpf_obj_free_fields()' after 'copy_map_value_locked()' to properly release the old fields. Fixes: 9db44fd ("bpf: Support kptrs in local storage maps") Signed-off-by: Leon Hwang <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent c7fcb79 commit b49558c

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

kernel/bpf/bpf_local_storage.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ bpf_local_storage_update(void *owner, struct bpf_local_storage_map *smap,
609609
if (old_sdata && selem_linked_to_storage_lockless(SELEM(old_sdata))) {
610610
copy_map_value_locked(&smap->map, old_sdata->data,
611611
value, false);
612+
bpf_obj_free_fields(smap->map.record, old_sdata->data);
612613
return old_sdata;
613614
}
614615
}
@@ -641,6 +642,7 @@ bpf_local_storage_update(void *owner, struct bpf_local_storage_map *smap,
641642
if (old_sdata && (map_flags & BPF_F_LOCK)) {
642643
copy_map_value_locked(&smap->map, old_sdata->data, value,
643644
false);
645+
bpf_obj_free_fields(smap->map.record, old_sdata->data);
644646
selem = SELEM(old_sdata);
645647
goto unlock;
646648
}

0 commit comments

Comments
 (0)