From: Quentin Monnet <quentin@isovalent.com>
To: Pu Lehui <pulehui@huaweicloud.com>,
bpf@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>, Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>, Pu Lehui <pulehui@huawei.com>
Subject: Re: [PATCH bpf] bpftool: Fix NULL pointer dereference when pin {PROG, MAP, LINK} without FILE
Date: Wed, 2 Nov 2022 10:51:56 +0000 [thread overview]
Message-ID: <c4948e58-0666-5d4b-3436-7672f98fe1e3@isovalent.com> (raw)
In-Reply-To: <20221102084034.3342995-1-pulehui@huaweicloud.com>
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>
next prev parent reply other threads:[~2022-11-02 10:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-02 8:40 Pu Lehui
2022-11-02 10:51 ` Quentin Monnet [this message]
2022-11-02 11:10 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c4948e58-0666-5d4b-3436-7672f98fe1e3@isovalent.com \
--to=quentin@isovalent.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=pulehui@huawei.com \
--cc=pulehui@huaweicloud.com \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®