tools: bpftool: fix struct_ops command invalid pointer free
Subsystems (4)
PATCH 1/1 tools: bpftool: fix struct_ops command invalid pointer free
From commit 65c93628599d ("bpftool: Add struct_ops support"), a new type of command struct_ops has been added.
This command requires kernel CONFIG_DEBUG_INFO_BTF=y, and for retrieving btf info, get_btf_vmlinux() is used.
When running this command on kernel without BTF debug info, this will lead to 'btf_vmlinux' variable contains 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.
--- tools/bpf/bpftool/struct_ops.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/bpf/bpftool/struct_ops.c +3 -1
@@ -591,6 +591,8 @@ int do_struct_ops(int argc, char **argv) err =cmd_select (cmds, argc, argv, do_help); -btf__free (btf_vmlinux); +if (!IS_ERR (btf_vmlinux)) +btf__free (btf_vmlinux); +return err; }
Signature · 1 line
2.26.0
Quoted 6 lines · Daniel T. Lee
From commit
65c93628599d("bpftool: Addstruct_opssupport"), a new type of commandstruct_opshas been added.This command requires kernel
CONFIG_DEBUG_INFO_BTF=y, and for retrieving btf info,get_btf_vmlinux()is used.
Quoted 8 lines
When running this command on kernel without BTF debug info, this will lead to '
btf_vmlinux' variable contains invalid(error) pointer. And by this,btf_free()causes a segfault when executing 'bpftoolstruct_ops'.This commit adds pointer validation with
IS_ERRnot to free invalid pointer, and this will fix the segfault issue.Signed-off-by Daniel T. Lee <[email protected]>
Thanks for the fix! Please add the Fixes tag in the future.
Will do, thanks for letting me know.
Thank you for your time and effort for the review.
Best,
Daniel
Quoted 20 lines · Martin KaFai Lau
Quoted 6 lines · Daniel T. Lee
From commit
65c93628599d("bpftool: Addstruct_opssupport"), a new type of commandstruct_opshas been added.This command requires kernel
CONFIG_DEBUG_INFO_BTF=y, and for retrieving btf info,get_btf_vmlinux()is used.Quoted 8 lines
When running this command on kernel without BTF debug info, this will lead to '
btf_vmlinux' variable contains invalid(error) pointer. And by this,btf_free()causes a segfault when executing 'bpftoolstruct_ops'.This commit adds pointer validation with
IS_ERRnot to free invalid pointer, and this will fix the segfault issue.Signed-off-by Daniel T. Lee <[email protected]>Fixes 65c93628599d ("bpftool: Add struct_ops support")Acked-by Martin KaFai LauThanks for the fix! Please add the Fixes tag in the future.
Daniel Borkmann
maintainerQuoted 11 lines · Martin KaFai Lau
Quoted 10 lines · Daniel T. Lee
From commit
65c93628599d("bpftool: Addstruct_opssupport"),
a new type of commandstruct_opshas been added.This command requires kernel
CONFIG_DEBUG_INFO_BTF=y, and for retrieving btf info,get_btf_vmlinux()is used.When running this command on kernel without BTF debug info, this will lead to '
btf_vmlinux' variable contains invalid(error) pointer. And by this,btf_free()causes a segfault when executing 'bpftoolstruct_ops'.
Quoted 6 lines
Quoted 4 lines
This commit adds pointer validation with
IS_ERRnot to free invalid pointer, and this will fix the segfault issue.Signed-off-by Daniel T. Lee <[email protected]>Fixes 65c93628599d ("bpftool: Add struct_ops support")Acked-by Martin KaFai Lau
Applied & fixed up email, thanks!