From: sashiko-bot@kernel.org
To: chenyuan_fl@163.com
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v4 3/3] bpftool: Fix bypass of the batch line length check by comments
Date: Mon, 10 Aug 2026 09:14:39 +0000 [thread overview]
Message-ID: <20260810091439.645E31F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260810090459.2666243-4-chenyuan_fl@163.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Incomplete fix for batch line length check bypass, allowing command injection via embedded null bytes.
--
--- Patch [3]: [PATCH bpf-next v4 3/3] bpftool: Fix bypass of the batch line length check by comments ---
commit 1803699d659bb5e5e3beb9beeb6577cdf2791dda
Author: Yuan Chen <chenyuan@kylinos.cn>
bpftool: Fix bypass of the batch line length check by comments
This commit fixes an issue in do_batch() where trailing comments truncated
by '#' would bypass the line length check. It records whether fgets()
truncated the line before stripping the comment to reliably reject overlong
lines regardless of comments.
> diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c
> --- a/tools/bpf/bpftool/main.c
> +++ b/tools/bpf/bpftool/main.c
> @@ -367,11 +367,13 @@ static int do_batch(int argc, char **argv)
> if (json_output)
> jsonw_start_array(json_wtr);
> while (fgets(buf, sizeof(buf), fp)) {
> + bool truncated = strlen(buf) == sizeof(buf) - 1;
[Severity: High]
This isn't a bug introduced by this patch, but does using strlen() here leave
the length check vulnerable to an embedded null byte bypass?
Since fgets() reads up to sizeof(buf) - 1 bytes, if a batch file line
contains an embedded null byte ('\0'), strlen(buf) will stop at the null
byte. This makes strlen(buf) strictly less than sizeof(buf) - 1, causing the
truncation check to evaluate to false even if the line exceeded the buffer
capacity.
If this bypasses the length check, could the unread remainder of the
buffer-exceeding line remain in the file stream and be parsed and executed
as a separate, arbitrary command on the next loop iteration?
Might it be safer to check if the buffer is missing a newline character
instead of relying on strlen()?
[ ... ]
> /* Append continuation lines if any (coming after a line ending
> * with '\' in the batch file).
> */
> while ((cp = strstr(buf, "\\\n")) != NULL) {
> + bool cont_truncated;
> +
> if (!fgets(contline, sizeof(contline), fp) ||
> strlen(contline) == 0) {
[ ... ]
> }
>
> + cont_truncated = strlen(contline) == sizeof(contline) - 1;
[Severity: High]
This is also a pre-existing issue, but does the same embedded null byte
bypass apply to continuation lines here?
If contline contains a null byte, cont_truncated will evaluate to false,
potentially allowing an overlong continuation line to bypass the length
enforcement and execute trailing input as unintended commands.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260810090459.2666243-1-chenyuan_fl@163.com?part=3
prev parent reply other threads:[~2026-08-10 9:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-10 9:04 [PATCH bpf-next v4 0/3] bpftool: fix batch file handling issues chenyuan_fl
2026-08-10 9:04 ` [PATCH bpf-next v4 1/3] bpftool: fix double close in map dump chenyuan_fl
2026-08-10 9:20 ` sashiko-bot
2026-08-10 9:04 ` [PATCH bpf-next v4 2/3] bpftool: fix spurious batch file read error chenyuan_fl
2026-08-10 9:15 ` sashiko-bot
2026-08-10 10:13 ` bot+bpf-ci
2026-08-10 9:04 ` [PATCH bpf-next v4 3/3] bpftool: Fix bypass of the batch line length check by comments chenyuan_fl
2026-08-10 9:14 ` sashiko-bot [this message]
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=20260810091439.645E31F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=chenyuan_fl@163.com \
--cc=sashiko-reviews@lists.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox