Skip to content

Commit c7fcb79

Browse files
Asphalttanakryiko
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]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent f6de8d6 commit c7fcb79

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
@@ -1110,6 +1110,7 @@ static long htab_map_update_elem(struct bpf_map *map, void *key, void *value,
11101110
copy_map_value_locked(map,
11111111
htab_elem_value(l_old, key_size),
11121112
value, false);
1113+
check_and_free_fields(htab, l_old);
11131114
return 0;
11141115
}
11151116
/* fall through, grab the bucket lock and lookup again.
@@ -1138,6 +1139,7 @@ static long htab_map_update_elem(struct bpf_map *map, void *key, void *value,
11381139
copy_map_value_locked(map,
11391140
htab_elem_value(l_old, key_size),
11401141
value, false);
1142+
check_and_free_fields(htab, l_old);
11411143
ret = 0;
11421144
goto err;
11431145
}

0 commit comments

Comments
 (0)