Commit d4899572 authored by Kumar Kartikeya Dwivedi's avatar Kumar Kartikeya Dwivedi Committed by Alexei Starovoitov

bpf: Free inner_map_meta when btf_record_dup fails

Whenever btf_record_dup fails, we must free inner_map_meta that was
allocated before.

This fixes a memory leak (in case of errors) during inner map creation.

Fixes: aa3496ac ("bpf: Refactor kptr_off_tab into btf_record")
Signed-off-by: default avatarKumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20221118015614.2013203-4-memxor@gmail.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent d7f5ef65
...@@ -52,12 +52,14 @@ struct bpf_map *bpf_map_meta_alloc(int inner_map_ufd) ...@@ -52,12 +52,14 @@ struct bpf_map *bpf_map_meta_alloc(int inner_map_ufd)
inner_map_meta->max_entries = inner_map->max_entries; inner_map_meta->max_entries = inner_map->max_entries;
inner_map_meta->record = btf_record_dup(inner_map->record); inner_map_meta->record = btf_record_dup(inner_map->record);
if (IS_ERR(inner_map_meta->record)) { if (IS_ERR(inner_map_meta->record)) {
struct bpf_map *err_ptr = ERR_CAST(inner_map_meta->record);
/* btf_record_dup returns NULL or valid pointer in case of /* btf_record_dup returns NULL or valid pointer in case of
* invalid/empty/valid, but ERR_PTR in case of errors. During * invalid/empty/valid, but ERR_PTR in case of errors. During
* equality NULL or IS_ERR is equivalent. * equality NULL or IS_ERR is equivalent.
*/ */
kfree(inner_map_meta);
fdput(f); fdput(f);
return ERR_CAST(inner_map_meta->record); return err_ptr;
} }
if (inner_map->btf) { if (inner_map->btf) {
btf_get(inner_map->btf); btf_get(inner_map->btf);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment