bpftool: Explicit errno handling in skeletons
authorDelyan Kratunov <delyank@fb.com>
Mon, 21 Mar 2022 23:29:18 +0000 (23:29 +0000)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 30 Mar 2022 12:06:59 +0000 (14:06 +0200)
commit522574fd7864e091d473765102e866414979b2ab
tree97879dee0c4610beb021ee2b915a844f6b23fbf9
parent77c9387c0c5bd496fba3200024e3618356b2fd34
bpftool: Explicit errno handling in skeletons

Andrii noticed that since f97b8b9bd630 ("bpftool: Fix a bug in subskeleton
code generation") the subskeleton code allows bpf_object__destroy_subskeleton
to overwrite the errno that subskeleton__open would return with. While this
is not currently an issue, let's make it future-proof.

This patch explicitly tracks err in subskeleton__open and skeleton__create
(i.e. calloc failure is explicitly ENOMEM) and ensures that errno is -err on
the error return path. The skeleton code had to be changed since maps and
progs codegen is shared with subskeletons.

Fixes: f97b8b9bd630 ("bpftool: Fix a bug in subskeleton code generation")
Signed-off-by: Delyan Kratunov <delyank@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/3b6bfbb770c79ae64d8de26c1c1bd9d53a4b85f8.camel@fb.com
tools/bpf/bpftool/gen.c