Skip to content

Commit

Permalink
bpftool: Fix NULL pointer dereference when pin {PROG, MAP, LINK} with…
Browse files Browse the repository at this point in the history
…out FILE

[ Upstream commit 34de8e6 ]

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: 75a1e79 ("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>
  • Loading branch information
Pu Lehui authored and gregkh committed Nov 16, 2022
1 parent d2400b4 commit da5161b
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tools/bpf/bpftool/common.c
Expand Up @@ -300,6 +300,9 @@ int do_pin_any(int argc, char **argv, int (*get_fd)(int *, char ***))
int err;
int fd;

if (!REQ_ARGS(3))
return -EINVAL;

fd = get_fd(&argc, &argv);
if (fd < 0)
return fd;
Expand Down

0 comments on commit da5161b

Please sign in to comment.