Skip to content

Commit f6de8d6

Browse files
Asphalttanakryiko
authored andcommitted
bpf: Free special fields when update [lru_,]percpu_hash maps
As [lru_,]percpu_hash maps support BPF_KPTR_{REF,PERCPU}, missing calls to 'bpf_obj_free_fields()' in 'pcpu_copy_value()' could cause the memory referenced by BPF_KPTR_{REF,PERCPU} fields to be held until the map gets freed. Fix this by calling 'bpf_obj_free_fields()' after 'copy_map_value[,_long]()' in 'pcpu_copy_value()'. Fixes: 65334e6 ("bpf: Support kptrs in percpu hashmap and percpu LRU hashmap") Signed-off-by: Leon Hwang <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 54c134f commit f6de8d6

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

kernel/bpf/hashtab.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,12 +937,14 @@ static void pcpu_copy_value(struct bpf_htab *htab, void __percpu *pptr,
937937
if (!onallcpus) {
938938
/* copy true value_size bytes */
939939
copy_map_value(&htab->map, this_cpu_ptr(pptr), value);
940+
bpf_obj_free_fields(htab->map.record, this_cpu_ptr(pptr));
940941
} else {
941942
u32 size = round_up(htab->map.value_size, 8);
942943
int off = 0, cpu;
943944

944945
for_each_possible_cpu(cpu) {
945946
copy_map_value_long(&htab->map, per_cpu_ptr(pptr, cpu), value + off);
947+
bpf_obj_free_fields(htab->map.record, per_cpu_ptr(pptr, cpu));
946948
off += size;
947949
}
948950
}

0 commit comments

Comments
 (0)