Skip to content

Commit ef9539c

Browse files
AsphalttKernel Patches Daemon
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]>
1 parent 7c8a49d commit ef9539c

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
@@ -950,12 +950,14 @@ static void pcpu_copy_value(struct bpf_htab *htab, void __percpu *pptr,
950950
if (!onallcpus) {
951951
/* copy true value_size bytes */
952952
copy_map_value(&htab->map, this_cpu_ptr(pptr), value);
953+
bpf_obj_free_fields(htab->map.record, this_cpu_ptr(pptr));
953954
} else {
954955
u32 size = round_up(htab->map.value_size, 8);
955956
int off = 0, cpu;
956957

957958
for_each_possible_cpu(cpu) {
958959
copy_map_value_long(&htab->map, per_cpu_ptr(pptr, cpu), value + off);
960+
bpf_obj_free_fields(htab->map.record, per_cpu_ptr(pptr, cpu));
959961
off += size;
960962
}
961963
}

0 commit comments

Comments
 (0)