From: Shankari Anand <shankari.ak0208@gmail.com>
To: bpf@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
John Fastabend <john.fastabend@gmail.com>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>,
Shankari Anand <shankari.ak0208@gmail.com>,
syzbot+ad4661d6ca888ce7fe11@syzkaller.appspotmail.com
Subject: [PATCH] bpf: restrict verifier access to bpf_lru_node.ref
Date: Tue, 15 Jul 2025 13:27:55 +0530 [thread overview]
Message-ID: <20250715075755.114339-1-shankari.ak0208@gmail.com> (raw)
syzbot reported a data race on the `ref` field of `struct bpf_lru_node`:
https://syzkaller.appspot.com/bug?extid=ad4661d6ca888ce7fe11
This race arises when user programs read the `.ref` field from a BPF map
that uses LRU logic, potentially exposing unprotected state.
Accesses to `ref` are already wrapped with READ_ONCE() and WRITE_ONCE().
However, the BPF verifier currently allows unprivileged programs to
read this field via BTF-enabled pointer, bypassing internal assumptions.
To mitigate this, the verifier is updated to disallow access
to the `.ref` field in `struct bpf_lru_node`.
This is done by checking both the base type and field name
in `check_ptr_to_btf_access()` and returning -EACCES if matched.
Reported-by: syzbot+ad4661d6ca888ce7fe11@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/all/6847e661.a70a0220.27c366.005d.GAE@google.com/T/
Signed-off-by: Shankari Anand <shankari.ak0208@gmail.com>
---
kernel/bpf/verifier.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 169845710c7e..775ce454268c 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -7159,6 +7159,19 @@ static int check_ptr_to_btf_access(struct bpf_verifier_env *env,
}
ret = btf_struct_access(&env->log, reg, off, size, atype, &btf_id, &flag, &field_name);
+
+ /* Block access to sensitive kernel-internal fields */
+ if (field_name && reg->btf && btf_is_kernel(reg->btf)) {
+ const struct btf_type *base_type = btf_type_by_id(reg->btf, reg->btf_id);
+ const char *type_name = btf_name_by_offset(reg->btf, base_type->name_off);
+
+ if (strcmp(type_name, "bpf_lru_node") == 0 &&
+ strcmp(field_name, "ref") == 0) {
+ verbose(env,
+ "access to field 'ref' in struct bpf_lru_node is not allowed\n");
+ return -EACCES;
+ }
+ }
}
if (ret < 0)
base-commit: 155a3c003e555a7300d156a5252c004c392ec6b0
--
2.34.1
next reply other threads:[~2025-07-15 7:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-15 7:57 Shankari Anand [this message]
2025-07-15 14:49 ` Alexei Starovoitov
2025-07-15 21:26 ` Martin KaFai Lau
2025-07-16 6:32 ` Shankari Anand
2025-07-16 20:02 ` Martin KaFai Lau
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=20250715075755.114339-1-shankari.ak0208@gmail.com \
--to=shankari.ak0208@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--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=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=syzbot+ad4661d6ca888ce7fe11@syzkaller.appspotmail.com \
--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 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®