From: sashiko-bot@kernel.org
To: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 12/17] bpf: Report Execution Context Safety errors
Date: Fri, 19 Jun 2026 21:19:29 +0000 [thread overview]
Message-ID: <20260619211930.5AFC51F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260619205934.1312876-13-memxor@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [Critical] Integer overflow and out-of-bounds write in `bpf_bprintf_prepare` due to `snprintf` return value mishandling.
--
commit 9da2a659fbd6ab09232d9dfa84f7ad227b09b2a1
Author: Kumar Kartikeya Dwivedi <memxor@gmail.com>
bpf: Report Execution Context Safety errors
This commit augments the BPF verifier to report Execution Context Safety
errors. It provides source context, path history, and suggestions for
sleepability and critical-section failures.
While reviewing the BPF codebase, I noticed a critical pre-existing issue in
kernel/bpf/helpers.c within bpf_bprintf_prepare().
> --- a/kernel/bpf/helpers.c
> +++ b/kernel/bpf/helpers.c
> @@ -818, ... @@ int bpf_bprintf_prepare(const char *fmt, u32 fmt_size, const u64 *raw_args,
> u32 num_args, struct bpf_bprintf_data *data)
> {
[ ... ]
> if (fmt[i + 1] == 'B') {
> if (tmp_buf) {
> err = snprintf(tmp_buf,
> (tmp_buf_end - tmp_buf),
> "%pB",
> (void *)(long)raw_args[num_spec]);
> tmp_buf += (err + 1);
[Severity: Critical]
This is a pre-existing issue, but does this handle the snprintf return value
safely?
The snprintf function returns the number of characters that would have been
written if the buffer was large enough, not the actual number of characters
written. If the output is truncated because the remaining buffer space is
small, adding the return value to tmp_buf could advance the pointer past
tmp_buf_end.
[ ... ]
> /* hack: bstr_printf expects IP addresses to be
> * pre-formatted as strings, ironically, the easiest way
> * to do that is to call snprintf.
> */
> ip_spec[2] = fmt[i - 1];
> ip_spec[3] = fmt[i];
> err = snprintf(tmp_buf, tmp_buf_end - tmp_buf,
> ip_spec, &cur_ip);
>
> tmp_buf += err + 1;
[Severity: Critical]
This is a pre-existing issue, but the same snprintf return value behavior
applies here. Could this also advance tmp_buf past tmp_buf_end if the output
is truncated?
[ ... ]
> } else if (fmt[i] == 's') {
> fmt_ptype = fmt[i];
> fmt_str:
> if (fmt[i + 1] != 0 &&
> !isspace(fmt[i + 1]) &&
> !ispunct(fmt[i + 1])) {
> err = -EINVAL;
> goto out;
> }
>
> if (!tmp_buf)
> goto nocopy_fmt;
>
> if (tmp_buf_end == tmp_buf) {
> err = -ENOSPC;
> goto out;
> }
>
> unsafe_ptr = (char *)(long)raw_args[num_spec];
> err = bpf_trace_copy_string(tmp_buf, unsafe_ptr,
> fmt_ptype,
> tmp_buf_end - tmp_buf);
[Severity: Critical]
This is a pre-existing issue, but can this bypass the out-of-space check?
If tmp_buf was advanced past tmp_buf_end by a previous truncated snprintf
call, the exact equality check (tmp_buf_end == tmp_buf) will evaluate to
false.
This would cause the size parameter (tmp_buf_end - tmp_buf) passed to
bpf_trace_copy_string to be negative. Since the size parameter is typically
treated as an unsigned value, this could result in a massive out-of-bounds
write. Could we use a greater-than-or-equal check or track the remaining
length more safely?
> if (err < 0) {
> tmp_buf[0] = '\0';
> err = 1;
> }
>
> tmp_buf += err;
> num_spec++;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260619205934.1312876-1-memxor@gmail.com?part=12
next prev parent reply other threads:[~2026-06-19 21:19 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-19 20:59 [PATCH bpf-next v2 00/17] Redesign Verification Errors Kumar Kartikeya Dwivedi
2026-06-19 20:59 ` [PATCH bpf-next v2 01/17] bpf: Add verifier diagnostics report helpers Kumar Kartikeya Dwivedi
2026-06-19 21:09 ` sashiko-bot
2026-06-19 20:59 ` [PATCH bpf-next v2 02/17] bpf: Add source and instruction diagnostic context Kumar Kartikeya Dwivedi
2026-06-19 21:46 ` bot+bpf-ci
2026-06-19 20:59 ` [PATCH bpf-next v2 03/17] bpf: Add verifier diagnostic event log Kumar Kartikeya Dwivedi
2026-06-19 21:46 ` bot+bpf-ci
2026-06-19 20:59 ` [PATCH bpf-next v2 04/17] bpf: Prune verifier diagnostics on backtracking Kumar Kartikeya Dwivedi
2026-06-19 21:46 ` bot+bpf-ci
2026-06-19 20:59 ` [PATCH bpf-next v2 05/17] bpf: Track verifier register diagnostic events Kumar Kartikeya Dwivedi
2026-06-19 21:18 ` sashiko-bot
2026-06-19 23:35 ` Alexei Starovoitov
2026-06-19 20:59 ` [PATCH bpf-next v2 06/17] bpf: Track verifier reference " Kumar Kartikeya Dwivedi
2026-06-19 20:59 ` [PATCH bpf-next v2 07/17] bpf: Track verifier context " Kumar Kartikeya Dwivedi
2026-06-19 21:13 ` sashiko-bot
2026-06-19 21:19 ` Kumar Kartikeya Dwivedi
2026-06-19 21:46 ` bot+bpf-ci
2026-06-19 20:59 ` [PATCH bpf-next v2 08/17] bpf: Report Register Type Safety errors Kumar Kartikeya Dwivedi
2026-06-19 20:59 ` [PATCH bpf-next v2 09/17] bpf: Report Memory Safety bounds errors Kumar Kartikeya Dwivedi
2026-06-19 21:46 ` bot+bpf-ci
2026-06-19 23:40 ` Alexei Starovoitov
2026-06-19 20:59 ` [PATCH bpf-next v2 10/17] bpf: Report Resource Lifetime reference leaks Kumar Kartikeya Dwivedi
2026-06-19 21:12 ` sashiko-bot
2026-06-19 23:42 ` Alexei Starovoitov
2026-06-19 20:59 ` [PATCH bpf-next v2 11/17] bpf: Report Call Type Safety argument errors Kumar Kartikeya Dwivedi
2026-06-19 21:47 ` bot+bpf-ci
2026-06-19 20:59 ` [PATCH bpf-next v2 12/17] bpf: Report Execution Context Safety errors Kumar Kartikeya Dwivedi
2026-06-19 21:19 ` sashiko-bot [this message]
2026-06-19 23:44 ` Alexei Starovoitov
2026-06-19 20:59 ` [PATCH bpf-next v2 13/17] bpf: Report Program Structure CFG errors Kumar Kartikeya Dwivedi
2026-06-19 20:59 ` [PATCH bpf-next v2 14/17] bpf: Report Policy helper and kfunc errors Kumar Kartikeya Dwivedi
2026-06-19 20:59 ` [PATCH bpf-next v2 15/17] bpf: Report Verifier Limit errors Kumar Kartikeya Dwivedi
2026-06-19 20:59 ` [PATCH bpf-next v2 16/17] bpf: Report Verifier Internal errors Kumar Kartikeya Dwivedi
2026-06-19 20:59 ` [PATCH bpf-next v2 17/17] bpf: Gate verifier diagnostics on log level Kumar Kartikeya Dwivedi
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=20260619211930.5AFC51F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=memxor@gmail.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 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.