Commit 96b2eb6e authored by Daniel T. Lee's avatar Daniel T. Lee Committed by Daniel Borkmann

tools, bpftool: Fix struct_ops command invalid pointer free

In commit 65c93628 ("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: 65c93628 ("bpftool: Add struct_ops support")
Signed-off-by: default avatarDaniel T. Lee <danieltimlee@gmail.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarMartin KaFai Lau <kafai@fb.com>
Link: https://lore.kernel.org/bpf/20200410020612.2930667-1-danieltimlee@gmail.com
parent 642c1654
...@@ -591,6 +591,8 @@ int do_struct_ops(int argc, char **argv) ...@@ -591,6 +591,8 @@ int do_struct_ops(int argc, char **argv)
err = cmd_select(cmds, argc, argv, do_help); err = cmd_select(cmds, argc, argv, do_help);
btf__free(btf_vmlinux); if (!IS_ERR(btf_vmlinux))
btf__free(btf_vmlinux);
return err; return err;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment