linux-stable/tools/bpf/bpftool
Pu Lehui 6dcdd1b68b bpftool: Fix NULL pointer dereference when pin {PROG, MAP, LINK} without FILE
[ Upstream commit 34de8e6e0e ]

When using bpftool to pin {PROG, MAP, LINK} without FILE,
segmentation fault will occur. The reson is that the lack
of FILE will cause strlen to trigger NULL pointer dereference.
The corresponding stacktrace is shown below:

do_pin
  do_pin_any
    do_pin_fd
      mount_bpffs_for_pin
        strlen(name) <- NULL pointer dereference

Fix it by adding validation to the common process.

Fixes: 75a1e792c3 ("tools: bpftool: Allow all prog/map handles for pinning objects")
Signed-off-by: Pu Lehui <pulehui@huawei.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Quentin Monnet <quentin@isovalent.com>
Link: https://lore.kernel.org/bpf/20221102084034.3342995-1-pulehui@huaweicloud.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-11-16 09:58:15 +01:00
..
bash-completion tools: bpftool: Complete metrics list in "bpftool prog profile" doc 2021-07-30 15:40:28 -07:00
Documentation bpftool: Fix indent in option lists in the documentation 2022-01-27 11:05:26 +01:00
skeleton tools, bpftool: Remove two unused variables. 2020-10-29 15:23:18 +01:00
.gitignore tools/bpf: Remove bpf-helpers from bpftool docs 2021-03-04 18:39:45 -08:00
btf.c tools: bpftool: Document and add bash completion for -L, -B options 2021-07-30 15:40:28 -07:00
btf_dumper.c bpftool: Fix a wrong type cast in btf_dumper_int 2022-10-26 12:34:39 +02:00
cfg.c tools, bpftool: Poison and replace kernel integer typedefs 2020-05-11 21:20:46 +02:00
cfg.h
cgroup.c tools: bpftool: Document and add bash completion for -L, -B options 2021-07-30 15:40:28 -07:00
common.c bpftool: Fix NULL pointer dereference when pin {PROG, MAP, LINK} without FILE 2022-11-16 09:58:15 +01:00
feature.c tools: bpftool: Update and synchronise option list in doc and help msg 2021-07-30 15:40:27 -07:00
gen.c bpftool: Only set obj->skeleton on complete success 2022-04-08 14:23:24 +02:00
iter.c tools: bpftool: Update and synchronise option list in doc and help msg 2021-07-30 15:40:27 -07:00
jit_disasm.c bpftool: Properly close va_list 'ap' by va_end() on error 2021-07-06 09:19:23 +02:00
json_writer.c bpftool: Support dumping metadata 2020-09-15 18:28:27 -07:00
json_writer.h bpftool: Support dumping metadata 2020-09-15 18:28:27 -07:00
link.c tools: bpftool: Update and synchronise option list in doc and help msg 2021-07-30 15:40:27 -07:00
main.c bpftool: Clear errno after libcap's checks 2022-10-26 12:35:32 +02:00
main.h tools: bpftool: Update and synchronise option list in doc and help msg 2021-07-30 15:40:27 -07:00
Makefile bpftool: Remove inclusion of utilities.mak from Makefiles 2022-01-27 11:05:26 +01:00
map.c bpftool: Fix the error when lookup in no-btf maps 2022-04-08 14:23:31 +02:00
map_perf_ring.c tools, bpftool: Poison and replace kernel integer typedefs 2020-05-11 21:20:46 +02:00
net.c tools: bpftool: Update and synchronise option list in doc and help msg 2021-07-30 15:40:27 -07:00
netlink_dumper.c
netlink_dumper.h
perf.c tools: bpftool: Update and synchronise option list in doc and help msg 2021-07-30 15:40:27 -07:00
pids.c tools/bpftool: Fix PID fetching with a lot of results 2020-12-08 16:45:20 +01:00
prog.c bpftool: Fix memory leak in prog_dump() 2022-01-27 11:03:07 +01:00
struct_ops.c tools: bpftool: Update and synchronise option list in doc and help msg 2021-07-30 15:40:27 -07:00
tracelog.c
xlated_dumper.c bpftool: Use syscall/loader program in "prog load" and "gen skeleton" command. 2021-05-19 00:41:31 +02:00
xlated_dumper.h