From: Sun Jian <sun.jian.kdev@gmail.com>
To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
eddyz87@gmail.com, memxor@gmail.com, bpf@vger.kernel.org
Cc: john.fastabend@gmail.com, martin.lau@linux.dev, song@kernel.org,
yonghong.song@linux.dev, jolsa@kernel.org,
linux-kernel@vger.kernel.org, Sun Jian <sun.jian.kdev@gmail.com>
Subject: [PATCH bpf] bpf: reject ERR_PTR map->record in map_check_btf
Date: Thu, 16 Apr 2026 22:48:08 +0800 [thread overview]
Message-ID: <20260416144808.149543-1-sun.jian.kdev@gmail.com> (raw)
btf_parse_fields() returns an ERR_PTR() when it encounters an invalid
special field in map value BTF.
For example, an invalid kptr-annotated field whose tagged pointee is not
a full struct type can make btf_parse_fields() fail with -EINVAL.
map_check_btf() stores the result in map->record, but currently only
handles the successful non-NULL case explicitly. ERR_PTR() results are
not rejected immediately before proceeding with the rest of map BTF
setup.
Handle IS_ERR(map->record) explicitly in map_check_btf() and return the
underlying error code immediately.
Fixes: aa3496accc412 ("bpf: Refactor kptr_off_tab into btf_record")
Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com>
---
kernel/bpf/syscall.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index b73b25c63073..83e206a0626a 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -1262,7 +1262,12 @@ static int map_check_btf(struct bpf_map *map, struct bpf_token *token,
BPF_RB_ROOT | BPF_REFCOUNT | BPF_WORKQUEUE | BPF_UPTR |
BPF_TASK_WORK,
map->value_size);
- if (!IS_ERR_OR_NULL(map->record)) {
+ if (IS_ERR(map->record)) {
+ ret = PTR_ERR(map->record);
+ map->record = NULL;
+ goto free_map_tab;
+ }
+ if (map->record) {
int i;
if (!bpf_token_capable(token, CAP_BPF)) {
base-commit: 1d51b370a0f8f642f4fc84c795fbedac0fcdbbd2
--
2.43.0
next reply other threads:[~2026-04-16 14:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-16 14:48 Sun Jian [this message]
2026-04-16 15:42 ` [PATCH bpf] bpf: reject ERR_PTR map->record in map_check_btf Alexei Starovoitov
2026-04-16 16:41 ` sun jian
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=20260416144808.149543-1-sun.jian.kdev@gmail.com \
--to=sun.jian.kdev@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox