Skip to content

Commit 42f39ed

Browse files
AsphalttKernel Patches Daemon
authored andcommitted
bpf: Free special fields when update hash maps with BPF_F_LOCK
When updating hash maps with BPF_F_LOCK, 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. Fix this by calling 'check_and_free_fields()' after 'copy_map_value_locked()' to properly release the old fields. Fixes: 14a324f ("bpf: Wire up freeing of referenced kptr") Signed-off-by: Leon Hwang <[email protected]>
1 parent 8b81aac commit 42f39ed

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
@@ -1124,6 +1124,7 @@ static long htab_map_update_elem(struct bpf_map *map, void *key, void *value,
11241124
copy_map_value_locked(map,
11251125
htab_elem_value(l_old, key_size),
11261126
value, false);
1127+
check_and_free_fields(htab, l_old);
11271128
return 0;
11281129
}
11291130
/* fall through, grab the bucket lock and lookup again.
@@ -1152,6 +1153,7 @@ static long htab_map_update_elem(struct bpf_map *map, void *key, void *value,
11521153
copy_map_value_locked(map,
11531154
htab_elem_value(l_old, key_size),
11541155
value, false);
1156+
check_and_free_fields(htab, l_old);
11551157
ret = 0;
11561158
goto err;
11571159
}

0 commit comments

Comments
 (0)