From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Masoud Aghasi" <maghasi@disroot.org>, <bpf@vger.kernel.org>
Cc: <andrii@kernel.org>, <eddyz87@gmail.com>, <ast@kernel.org>,
<daniel@iogearbox.net>, <memxor@gmail.com>,
<martin.lau@linux.dev>, <song@kernel.org>,
<yonghong.song@linux.dev>, <jolsa@kernel.org>,
<emil@etsalapatis.com>
Subject: Re: [PATCH] libbpf: Add length checks for path parameters before memory allocation
Date: Mon, 29 Jun 2026 11:23:11 -0700 [thread overview]
Message-ID: <DJLQR3M9S62V.2FYC7QDSTU3DJ@gmail.com> (raw)
In-Reply-To: <20260629122559.3828469-1-maghasi@disroot.org>
On Mon Jun 29, 2026 at 5:25 AM PDT, Masoud Aghasi wrote:
> Several libbpf API functions such as bpf_object__open_file() and
> bpf_program__pin() allocate memory based on user-provided paths without
> first validating input length.
>
> This can result in out-of-memory errors or different error codes
> (ENAMETOOLONG, ENOMEM) being returned.
>
> This patch adds missing path length checks to ensure all affected APIs
> return a consistent error code (ENAMETOOLONG) for invalid path lengths,
> preventing potential memory allocation failures.
>
> Additionally, adds some missing NULL pointer checks to prevent
> potential segmentation faults.
>
> Best regards,
>
> Signed-off-by: Masoud Aghasi <maghasi@disroot.org>
> ---
> tools/lib/bpf/libbpf.c | 32 ++++++++++++++++++++++++++++++++
> 1 file changed, 32 insertions(+)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 7162146280a8..bb3f1dd0663e 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -8536,6 +8536,9 @@ bpf_object__open_file(const char *path, const struct bpf_object_open_opts *opts)
> if (!path)
> return libbpf_err_ptr(-EINVAL);
>
> + if (strlen(path) >= PATH_MAX)
> + return libbpf_err_ptr(-ENAMETOOLONG);
> +
The code is fine as-is. We don't add defensive checks.
pw-bot: cr
next prev parent reply other threads:[~2026-06-29 18:23 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-29 12:25 [PATCH] libbpf: Add length checks for path parameters before memory allocation Masoud Aghasi
2026-06-29 13:13 ` bot+bpf-ci
2026-06-29 18:23 ` Alexei Starovoitov [this message]
2026-06-30 6:46 ` Masoud Aghasi
2026-06-30 18:12 ` Alexei Starovoitov
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=DJLQR3M9S62V.2FYC7QDSTU3DJ@gmail.com \
--to=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=jolsa@kernel.org \
--cc=maghasi@disroot.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.