bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yusheng Zheng" <yunwei356@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [RFC PATCH bpf-next 1/7] bpf: Let kfunc sets give kfuncs a BPF body
Date: Mon, 05 Oct 2026 14:38:35 +0000	[thread overview]
Message-ID: <20261005143835.8D8D91F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20261005142219.33451-2-yunwei356@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] bpf: integer conversion bypasses kfunc body length check
- [Medium] bpf: type confusion when checking size of pointer arguments
--

commit ab41a09d317c7611ac2e010f734c868245e66554
Author: Yusheng Zheng <yunwei356@gmail.com>

bpf: Let kfunc sets give kfuncs a BPF body

This commit allows a kfunc set to provide a BPF instruction body for its
kfuncs, enabling the verifier to analyze the instructions inline. These
small kfuncs can then be used like instructions while the verifier knows
exactly what they compute.

> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> --- a/kernel/bpf/btf.c
> +++ b/kernel/bpf/btf.c
[ ... ]
> +static bool btf_check_kfunc_body(const struct btf *btf, const struct btf_type *func,
> +				 const struct bpf_kfunc_body *b)
> +{
> +	const struct btf_type *proto = btf_type_by_id(btf, func->type);
> +	const struct btf_param *args = btf_params(proto);
> +	int i, n = btf_type_vlen(proto), len = b->len;
> +	const struct bpf_insn *insn;
> +	u8 op;
> +
> +	if (n > MAX_BPF_FUNC_REG_ARGS || !b->insns || !len || len > BPF_KFUNC_BODY_MAX_INSNS ||
> +	    (proto->type && !btf_kfunc_reg_type(btf, proto->type)))
> +		return false;

[Severity: Medium]
Does this code inadvertently bypass the bounds check and instruction
validation loop if b->len is very large? 

b->len is an unsigned 32-bit integer. Assigning it to int len
implicitly casts it to a signed integer. If a module registers a kfunc with
b->len >= 0x80000000, len becomes negative. The check
len > BPF_KFUNC_BODY_MAX_INSNS evaluates as false, and the subsequent
for (i = 0; i < len; i++) loop is skipped entirely because
0 < negative_value is false. This could allow invalid or excessively large
BPF instruction sequences to be registered.

> +	for (i = 0; i < n; i++)
> +		if (!btf_kfunc_reg_type(btf, args[i].type) ||
> +		    (btf_param_match_suffix(btf, &args[i], "__k") &&
> +		     btf_type_skip_modifiers(btf, args[i].type, NULL)->size > sizeof(s32)))
> +			return false;

[Severity: Medium]
Does this code check the correct union field for pointer arguments?

When evaluating pointer arguments ending in "__k", this accesses
->size on the returned btf_type. However, for BTF_KIND_PTR, the size
field shares a union with type (the pointee BTF ID). This evaluates the
arbitrary BTF ID of the pointee type instead of its byte size, causing
unpredictable validation results or erroneously rejecting arguments based
on their pointee BTF type ID.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261005142219.33451-1-yunwei356@gmail.com?part=1

  reply	other threads:[~2026-10-05 14:38 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-05 14:22 [RFC PATCH bpf-next 0/7] bpf: Inline kfuncs that have a BPF body Yusheng Zheng
2026-10-05 14:22 ` [RFC PATCH bpf-next 1/7] bpf: Let kfunc sets give kfuncs " Yusheng Zheng
2026-10-05 14:38   ` sashiko-bot [this message]
2026-10-05 15:16   ` bot+bpf-ci
2026-10-05 14:22 ` [RFC PATCH bpf-next 2/7] bpf: Verify calls of kfuncs with a body through the body Yusheng Zheng
2026-10-05 14:41   ` sashiko-bot
2026-10-05 14:22 ` [RFC PATCH bpf-next 3/7] bpf, x86: Inline native code for kfuncs that have a body Yusheng Zheng
2026-10-05 14:22 ` [RFC PATCH bpf-next 4/7] bpf: Add kfuncs with bodies for common operations Yusheng Zheng
2026-10-05 14:39   ` sashiko-bot
2026-10-05 14:22 ` [RFC PATCH bpf-next 5/7] bpf, x86: Add native code for some inline kfuncs Yusheng Zheng
2026-10-05 14:22 ` [RFC PATCH bpf-next 6/7] selftests/bpf: Test " Yusheng Zheng
2026-10-05 14:22 ` [RFC PATCH bpf-next 7/7] Documentation/bpf: Describe " Yusheng Zheng
2026-10-05 15:16   ` bot+bpf-ci

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=20261005143835.8D8D91F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=yunwei356@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;
as well as URLs for NNTP newsgroup(s).