]> git.baikalelectronics.ru Git - kernel.git/commit
tools, bpftool: Fix struct_ops command invalid pointer free
authorDaniel T. Lee <danieltimlee@gmail.com>
Fri, 10 Apr 2020 02:06:12 +0000 (11:06 +0900)
committerDaniel Borkmann <daniel@iogearbox.net>
Tue, 14 Apr 2020 19:33:53 +0000 (21:33 +0200)
commitbec797dda069afe6fba0526ba0e7265ff07ea648
tree4b2925662cb05bc2667f432372bcbc02956b0439
parent02ee1cafee15c055005c45e239ff0ecb7ee271b2
tools, bpftool: Fix struct_ops command invalid pointer free

In commit d9282374a6ca ("bpftool: Add struct_ops support") a new
type of command named struct_ops has been added. This command requires
a kernel with CONFIG_DEBUG_INFO_BTF=y set and for retrieving BTF info
in bpftool, the helper get_btf_vmlinux() is used.

When running this command on kernel without BTF debug info, this will
lead to 'btf_vmlinux' variable being an invalid(error) pointer. And by
this, btf_free() causes a segfault when executing 'bpftool struct_ops'.

This commit adds pointer validation with IS_ERR not to free invalid
pointer, and this will fix the segfault issue.

Fixes: d9282374a6ca ("bpftool: Add struct_ops support")
Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Link: https://lore.kernel.org/bpf/20200410020612.2930667-1-danieltimlee@gmail.com
tools/bpf/bpftool/struct_ops.c