Skip to content

Commit ca7a5ba

Browse files
author
Alexei Starovoitov
committed
Merge branch 'two-tiny-fixes-for-btf-record'
Hou Tao says: ==================== The tiny patch set aims to fix two problems found during the development of supporting dynptr key in hash table. Patch #1 fixes the missed btf_record_free() when map creation fails and patch #2 fixes the missed kfree() when there is no special field in the passed btf. ==================== Link: https://lore.kernel.org/r/20240912012845.3458483-1-houtao@huaweicloud.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2 parents 211bf9c + 986deb2 commit ca7a5ba

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

kernel/bpf/btf.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5572,8 +5572,10 @@ btf_parse_struct_metas(struct bpf_verifier_log *log, struct btf *btf)
55725572
aof->ids[aof->cnt++] = i;
55735573
}
55745574

5575-
if (!aof->cnt)
5575+
if (!aof->cnt) {
5576+
kfree(aof);
55765577
return NULL;
5578+
}
55775579
sort(&aof->ids, aof->cnt, sizeof(aof->ids[0]), btf_id_cmp_func, NULL);
55785580

55795581
for (i = 1; i < n; i++) {

kernel/bpf/syscall.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -735,15 +735,11 @@ void bpf_obj_free_fields(const struct btf_record *rec, void *obj)
735735
}
736736
}
737737

738-
/* called from workqueue */
739-
static void bpf_map_free_deferred(struct work_struct *work)
738+
static void bpf_map_free(struct bpf_map *map)
740739
{
741-
struct bpf_map *map = container_of(work, struct bpf_map, work);
742740
struct btf_record *rec = map->record;
743741
struct btf *btf = map->btf;
744742

745-
security_bpf_map_free(map);
746-
bpf_map_release_memcg(map);
747743
/* implementation dependent freeing */
748744
map->ops->map_free(map);
749745
/* Delay freeing of btf_record for maps, as map_free
@@ -762,6 +758,16 @@ static void bpf_map_free_deferred(struct work_struct *work)
762758
btf_put(btf);
763759
}
764760

761+
/* called from workqueue */
762+
static void bpf_map_free_deferred(struct work_struct *work)
763+
{
764+
struct bpf_map *map = container_of(work, struct bpf_map, work);
765+
766+
security_bpf_map_free(map);
767+
bpf_map_release_memcg(map);
768+
bpf_map_free(map);
769+
}
770+
765771
static void bpf_map_put_uref(struct bpf_map *map)
766772
{
767773
if (atomic64_dec_and_test(&map->usercnt)) {
@@ -1413,8 +1419,7 @@ static int map_create(union bpf_attr *attr)
14131419
free_map_sec:
14141420
security_bpf_map_free(map);
14151421
free_map:
1416-
btf_put(map->btf);
1417-
map->ops->map_free(map);
1422+
bpf_map_free(map);
14181423
put_token:
14191424
bpf_token_put(token);
14201425
return err;

0 commit comments

Comments
 (0)