]> git.itanic.dy.fi Git - linux-stable/commitdiff
bpf: add missing percpu_counter_destroy() in htab_map_alloc()
authorTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Sat, 10 Sep 2022 15:07:11 +0000 (00:07 +0900)
committerAlexei Starovoitov <ast@kernel.org>
Sat, 10 Sep 2022 23:04:07 +0000 (16:04 -0700)
syzbot is reporting ODEBUG bug in htab_map_alloc() [1], for
commit 86fe28f7692d96d2 ("bpf: Optimize element count in non-preallocated
hash map.") added percpu_counter_init() to htab_map_alloc() but forgot to
add percpu_counter_destroy() to the error path.

Link: https://syzkaller.appspot.com/bug?extid=5d1da78b375c3b5e6c2b
Reported-by: syzbot <syzbot+5d1da78b375c3b5e6c2b@syzkaller.appspotmail.com>
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Fixes: 86fe28f7692d96d2 ("bpf: Optimize element count in non-preallocated hash map.")
Reviewed-by: Stanislav Fomichev <sdf@google.com>
Link: https://lore.kernel.org/r/e2e4cc0e-9d36-4ca1-9bfa-ce23e6f8310b@I-love.SAKURA.ne.jp
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/hashtab.c

index 0fe3f136cbbe3be87594ff2594be3625a1bf396f..86aec20c22d0448fb46e72c38983c60ab1c29f78 100644 (file)
@@ -622,6 +622,8 @@ static struct bpf_map *htab_map_alloc(union bpf_attr *attr)
 free_prealloc:
        prealloc_destroy(htab);
 free_map_locked:
+       if (htab->use_percpu_counter)
+               percpu_counter_destroy(&htab->pcount);
        for (i = 0; i < HASHTAB_MAP_LOCK_COUNT; i++)
                free_percpu(htab->map_locked[i]);
        bpf_map_area_free(htab->buckets);