]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commit
bpftool: Only set obj->skeleton on complete success
authorWei Fu <fuweid89@gmail.com>
Sat, 8 Jan 2022 08:40:08 +0000 (16:40 +0800)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 20 May 2022 12:38:39 +0000 (14:38 +0200)
commit7bcdcc02c5644af469ddbb6d28f0dfcde6cf8701
treee854a9bd4755d194800935776b62d09fe46ee9ec
parent8bebaad8f83eff749aa6a368c5a5de983670e49e
bpftool: Only set obj->skeleton on complete success

BugLink: https://bugs.launchpad.net/bugs/1969110
[ Upstream commit 0991f6a38f576aa9a5e34713e23c998a3310d4d0 ]

After `bpftool gen skeleton`, the ${bpf_app}.skel.h will provide that
${bpf_app_name}__open helper to load bpf. If there is some error
like ENOMEM, the ${bpf_app_name}__open will rollback(free) the allocated
object, including `bpf_object_skeleton`.

Since the ${bpf_app_name}__create_skeleton set the obj->skeleton first
and not rollback it when error, it will cause double-free in
${bpf_app_name}__destory at ${bpf_app_name}__open. Therefore, we should
set the obj->skeleton before return 0;

Fixes: 5dc7a8b21144 ("bpftool, selftests/bpf: Embed object file inside skeleton")
Signed-off-by: Wei Fu <fuweid89@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20220108084008.1053111-1-fuweid89@gmail.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit e5f642c55f4ce1021838d87ed4806c35943136d1)
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
tools/bpf/bpftool/gen.c