aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/bpf/map_in_map.c
diff options
context:
space:
mode:
authorKumar Kartikeya Dwivedi <memxor@gmail.com>2022-11-18 07:25:53 +0530
committerAlexei Starovoitov <ast@kernel.org>2022-11-17 19:11:31 -0800
commitd48995723c9a1c4896206be382c72d722accbfbc (patch)
treea231d7e8a0c91dff1a43fd2e83713d26cc47c479 /kernel/bpf/map_in_map.c
parentbpf: Do btf_record_free outside map_free callback (diff)
downloadlinux-d48995723c9a1c4896206be382c72d722accbfbc.tar.xz
linux-d48995723c9a1c4896206be382c72d722accbfbc.zip
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: aa3496accc41 ("bpf: Refactor kptr_off_tab into btf_record") Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Link: https://lore.kernel.org/r/20221118015614.2013203-4-memxor@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'kernel/bpf/map_in_map.c')
-rw-r--r--kernel/bpf/map_in_map.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/kernel/bpf/map_in_map.c b/kernel/bpf/map_in_map.c
index 8ca0cca39d49..a423130a8720 100644
--- a/kernel/bpf/map_in_map.c
+++ b/kernel/bpf/map_in_map.c
@@ -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->record = btf_record_dup(inner_map->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
* invalid/empty/valid, but ERR_PTR in case of errors. During
* equality NULL or IS_ERR is equivalent.
*/
+ kfree(inner_map_meta);
fdput(f);
- return ERR_CAST(inner_map_meta->record);
+ return err_ptr;
}
if (inner_map->btf) {
btf_get(inner_map->btf);