From: sashiko-bot@kernel.org
To: "Suchit Karunakaran" <suchitkarunakaran@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH] bpf: add diagnostics for rejected memory and map accesses
Date: Mon, 21 Sep 2026 15:59:45 +0000 [thread overview]
Message-ID: <20260921155945.949431F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260921154650.130677-1-suchitkarunakaran@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] bpf: incomplete diagnostic coverage for read-only and packet writes
--
commit 4bb7159fc40bb3fd0415a49f32660f99d3a92102
Author: Suchit Karunakaran <suchitkarunakaran@gmail.com>
bpf: add diagnostics for rejected memory and map accesses
Emit structured verifier diagnostics when BPF programs are rejected for
unsupported or prohibited memory operations. Cover sign-extending arena
loads without JIT support, read/write access restrictions on maps, writes
through read-only pointers, direct packet writes, and modifying helpers
used with BPF_F_RDONLY_PROG.
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 18aad4886f9cf..a4ca95168a01f 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
[ ... ]
> @@ -6529,6 +6535,9 @@ static int check_mem_access(struct bpf_verifier_env *env, int insn_idx, struct b
> if (t == BPF_WRITE && rdonly_mem) {
> verbose(env, "%s cannot write into %s\n",
> reg_arg_name(env, argno), reg_type_str(env, reg->type));
> + bpf_diag_policy(env, insn_idx, "write through a read-only memory pointer",
> + "this pointer permits reads only",
> + "Use a writable destination, or copy the data into a writable buffer before modifying it.");
> return -EACCES;
> }
[Severity: Low]
This isn't a bug introduced by this patch, but does the check for PTR_TO_BUF
also need this diagnostic when rejecting direct writes in check_mem_access()?
kernel/bpf/verifier.c:check_mem_access() {
...
} else if (base_type(reg->type) == PTR_TO_BUF &&
!type_may_be_null(reg->type)) {
bool rdonly_mem = type_is_rdonly_mem(reg->type);
u32 *max_access;
if (rdonly_mem) {
if (t == BPF_WRITE) {
verbose(env, "%s cannot write into %s\n",
reg_arg_name(env, argno), reg_type_str(env, reg->type));
return -EACCES;
}
...
}
Should writes to read-only PTR_TO_MEM and PTR_TO_BUF via helper function
arguments also emit the structured diagnostic?
kernel/bpf/verifier.c:check_helper_mem_access() {
...
case PTR_TO_MEM:
if (type_is_rdonly_mem(reg->type)) {
if (access_type == BPF_WRITE) {
verbose(env, "%s cannot write into %s\n",
reg_arg_name(env, argno), reg_type_str(env, reg->type));
return -EACCES;
}
}
...
}
[ ... ]
> @@ -6608,6 +6617,9 @@ static int check_mem_access(struct bpf_verifier_env *env, int insn_idx, struct b
> } else if (reg_is_pkt_pointer(reg)) {
> if (t == BPF_WRITE && !may_access_direct_pkt_data(env, NULL, t)) {
> verbose(env, "cannot write into packet\n");
> + bpf_diag_policy(env, insn_idx, "direct packet write",
> + "direct packet writes are disabled for this program type",
> + "Remove the direct write, or perform the modification in a program type and hook that support packet writes.");
> return -EACCES;
> }
[Severity: Low]
This is a pre-existing issue, but should the same diagnostic be emitted when
packet writes are rejected via helper function arguments?
kernel/bpf/verifier.c:check_helper_mem_access() {
...
case PTR_TO_PACKET:
case PTR_TO_PACKET_META:
if (!may_access_direct_pkt_data(env, meta, access_type)) {
verbose(env, "function access to the packet is not allowed\n");
return -EACCES;
}
...
}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260921154650.130677-1-suchitkarunakaran@gmail.com?part=1
next prev parent reply other threads:[~2026-09-21 15:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-21 15:46 [PATCH] bpf: add diagnostics for rejected memory and map accesses Suchit Karunakaran
2026-09-21 15:59 ` sashiko-bot [this message]
2026-09-21 17:05 ` Alexei Starovoitov
2026-09-21 17:38 ` Suchit Karunakaran
2026-09-21 19:00 ` Alexei Starovoitov
2026-09-22 5:49 ` Suchit Karunakaran
2026-09-25 1:42 ` 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=20260921155945.949431F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=suchitkarunakaran@gmail.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