From: Alan Maguire <alan.maguire@oracle.com>
To: ast@kernel.org, andrii@kernel.org, eddyz87@gmail.com, qmo@kernel.org
Cc: jolsa@kernel.org, daniel@iogearbox.net, ihor.solodrai@linux.dev,
yonghong.song@linux.dev, song@kernel.org, martin.lau@linux.dev,
memxor@gmail.com, emil@etsalapatis.com, bpf@vger.kernel.org,
nsc@kernel.org, puranjay@kernel.org, yatsenko@meta.com,
Alan Maguire <alan.maguire@oracle.com>
Subject: [PATCH v3 bpf-next 1/3] bpf: Verify BTF_KIND_LOC_PARAM vlen, flags
Date: Sat, 26 Sep 2026 18:51:11 +0100 [thread overview]
Message-ID: <20260926175113.2368566-2-alan.maguire@oracle.com> (raw)
In-Reply-To: <20260926175113.2368566-1-alan.maguire@oracle.com>
Ensure that vlen and flags combinations are consistent for
BTF_KIND_LOC_PARAMs.
Fixes: 33c5a3278bdb ("btf: Extend UAPI to support BTF location (inline site) info")
Suggested-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
---
kernel/bpf/btf.c | 43 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 9bcfefdfb734..8cc17a1cd25c 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -4823,10 +4823,53 @@ static s32 btf_loc_param_check_meta(struct btf_verifier_env *env,
btf_verifier_log_type(env, t, "Invalid btf_info kind_flag");
return -EINVAL;
}
+ /* All LOC_PARAMs have vlen of at least 1 */
+ if (vlen < 1)
+ goto invalid_vlen;
+
+ switch (p->flags) {
+ case BTF_LOC_PARAM_CONST:
+ case BTF_LOC_PARAM_CONST | BTF_LOC_PARAM_SIGNED:
+ case BTF_LOC_PARAM_CONST | BTF_LOC_PARAM_ADDR:
+ case BTF_LOC_PARAM_CONST | BTF_LOC_PARAM_ADDR | BTF_LOC_PARAM_SIGNED:
+ if (vlen > 2)
+ goto invalid_vlen;
+ /* Ensure size/vlen are consistent */
+ if (size > sizeof(__u32) && vlen != 2)
+ goto invalid_vlen;
+ if (size > sizeof(__u64))
+ goto invalid_vlen;
+ break;
+ case BTF_LOC_PARAM_REG:
+ /* Reg or reg/reg pair */
+ if (vlen > 2)
+ goto invalid_vlen;
+ break;
+ case BTF_LOC_PARAM_REG | BTF_LOC_PARAM_DEREF:
+ /* A reg deref without offset can only have vlen 1 */
+ if (vlen != 1)
+ goto invalid_vlen;
+ break;
+ case BTF_LOC_PARAM_REG | BTF_LOC_PARAM_OFFSET:
+ case BTF_LOC_PARAM_REG | BTF_LOC_PARAM_OFFSET | BTF_LOC_PARAM_SIGNED:
+ case BTF_LOC_PARAM_REG | BTF_LOC_PARAM_DEREF | BTF_LOC_PARAM_OFFSET:
+ case BTF_LOC_PARAM_REG | BTF_LOC_PARAM_DEREF | BTF_LOC_PARAM_OFFSET |
+ BTF_LOC_PARAM_SIGNED:
+ if (vlen < 2 || vlen > 3)
+ goto invalid_vlen;
+ break;
+ default:
+ btf_verifier_log_type(env, t, "Invalid flags");
+ return -EINVAL;
+ }
btf_verifier_log_type(env, t, NULL);
return meta_needed;
+
+invalid_vlen:
+ btf_verifier_log_type(env, t, "Invalid vlen");
+ return -EINVAL;
}
static void btf_loc_param_log(struct btf_verifier_env *env,
--
2.43.5
next prev parent reply other threads:[~2026-09-26 17:51 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-26 17:51 [PATCH v3 bpf-next 0/3] BTF inline functionality followups Alan Maguire
2026-09-26 17:51 ` Alan Maguire [this message]
2026-09-29 10:43 ` [PATCH v3 bpf-next 1/3] bpf: Verify BTF_KIND_LOC_PARAM vlen, flags Alexei Starovoitov
2026-09-29 10:50 ` Alan Maguire
2026-09-26 17:51 ` [PATCH v3 bpf-next 2/3] bpftool: Update func representation to include function signature Alan Maguire
2026-09-28 9:39 ` Jiri Olsa
2026-09-28 9:50 ` Alan Maguire
2026-09-28 11:46 ` Quentin Monnet
2026-09-26 17:51 ` [PATCH v3 bpf-next 3/3] selftests/bpf: Fix up bpftool btf dump test for signatures Alan Maguire
2026-09-28 9:39 ` [PATCH v3 bpf-next 0/3] BTF inline functionality followups Jiri Olsa
2026-09-28 11:46 ` Quentin Monnet
2026-09-29 10:50 ` patchwork-bot+netdevbpf
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=20260926175113.2368566-2-alan.maguire@oracle.com \
--to=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=jolsa@kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=nsc@kernel.org \
--cc=puranjay@kernel.org \
--cc=qmo@kernel.org \
--cc=song@kernel.org \
--cc=yatsenko@meta.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