* [PATCH bpf] bpftool: Fix NULL pointer dereference when pin {PROG, MAP, LINK} without FILE
@ 2022-11-02 8:40 Pu Lehui
2022-11-02 10:51 ` Quentin Monnet
2022-11-02 11:10 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Pu Lehui @ 2022-11-02 8:40 UTC (permalink / raw)
To: bpf, linux-kernel
Cc: Quentin Monnet, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko, Martin KaFai Lau, Song Liu, Yonghong Song,
John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
Pu Lehui, Pu Lehui
From: Pu Lehui <pulehui@huawei.com>
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: 75a1e792c335 ("tools: bpftool: Allow all prog/map handles for pinning objects")
Signed-off-by: Pu Lehui <pulehui@huawei.com>
---
tools/bpf/bpftool/common.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c
index e4d33bc8bbbf..653c130a0aaa 100644
--- a/tools/bpf/bpftool/common.c
+++ b/tools/bpf/bpftool/common.c
@@ -302,6 +302,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;
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH bpf] bpftool: Fix NULL pointer dereference when pin {PROG, MAP, LINK} without FILE
2022-11-02 8:40 [PATCH bpf] bpftool: Fix NULL pointer dereference when pin {PROG, MAP, LINK} without FILE Pu Lehui
@ 2022-11-02 10:51 ` Quentin Monnet
2022-11-02 11:10 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Quentin Monnet @ 2022-11-02 10:51 UTC (permalink / raw)
To: Pu Lehui, bpf, linux-kernel
Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, Pu Lehui
2022-11-02 16:40 UTC+0800 ~ Pu Lehui <pulehui@huaweicloud.com>
> From: Pu Lehui <pulehui@huawei.com>
>
> 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: 75a1e792c335 ("tools: bpftool: Allow all prog/map handles for pinning objects")
> Signed-off-by: Pu Lehui <pulehui@huawei.com>
> ---
> tools/bpf/bpftool/common.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c
> index e4d33bc8bbbf..653c130a0aaa 100644
> --- a/tools/bpf/bpftool/common.c
> +++ b/tools/bpf/bpftool/common.c
> @@ -302,6 +302,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;
Good catch, and thanks for the fix!
Reviewed-by: Quentin Monnet <quentin@isovalent.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf] bpftool: Fix NULL pointer dereference when pin {PROG, MAP, LINK} without FILE
2022-11-02 8:40 [PATCH bpf] bpftool: Fix NULL pointer dereference when pin {PROG, MAP, LINK} without FILE Pu Lehui
2022-11-02 10:51 ` Quentin Monnet
@ 2022-11-02 11:10 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-11-02 11:10 UTC (permalink / raw)
To: Pu Lehui
Cc: bpf, linux-kernel, quentin, ast, daniel, andrii, martin.lau, song,
yhs, john.fastabend, kpsingh, sdf, haoluo, jolsa, pulehui
Hello:
This patch was applied to bpf/bpf.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:
On Wed, 2 Nov 2022 16:40:34 +0800 you wrote:
> From: Pu Lehui <pulehui@huawei.com>
>
> 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:
>
> [...]
Here is the summary with links:
- [bpf] bpftool: Fix NULL pointer dereference when pin {PROG, MAP, LINK} without FILE
https://git.kernel.org/bpf/bpf/c/34de8e6e0e1f
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-11-02 11:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-02 8:40 [PATCH bpf] bpftool: Fix NULL pointer dereference when pin {PROG, MAP, LINK} without FILE Pu Lehui
2022-11-02 10:51 ` Quentin Monnet
2022-11-02 11:10 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox