BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Siddharth Nayyar" <sidnayyar@google.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH RFC bpf-next 1/7] bpf: Add bpf_btf_get_struct_member_info() helper
Date: Fri, 06 Nov 2026 20:37:30 +0000	[thread overview]
Message-ID: <sashiko-outbox-202238@kernel.org> (raw)
In-Reply-To: <20261106-lskel-struct-ops-v1-1-a4486ffc79cb@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] bpf: 32-bit return value truncation in
  bpf_btf_get_struct_member_info()
--

commit 053d54c272170ad0de7a256a743bef2e2fac76d1
Author: Siddharth Nayyar <sidnayyar@google.com>

bpf: Add bpf_btf_get_struct_member_info() helper

This commit adds the bpf_btf_get_struct_member_info() helper for
BPF_PROG_TYPE_SYSCALL programs to query struct member byte offsets and
indices or struct sizes from vmlinux or module BTF.

> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> index 228b93d4f8c94..8d9188dda34e0 100644
> --- a/kernel/bpf/btf.c
> +++ b/kernel/bpf/btf.c
> @@ -9682,6 +9682,79 @@ const struct bpf_func_proto bpf_btf_find_by_name_kind_proto = {
>  	.arg4_type	= ARG_ANYTHING,
>  };
>  
> +BPF_CALL_4(bpf_btf_get_struct_member_info, u32, btf_id, int, btf_obj_fd,
> +	   const char *, name, int, name_sz)
> +{
> +	const struct btf_member *member;
> +	const struct btf_type *t;
> +	struct btf *btf;
> +	long ret = -EINVAL;
> +	u32 i;

[ ... ]

> +	for_each_member(i, t, member) {
> +		const char *mname = btf_name_by_offset(btf, member->name_off);
> +
> +		if (!mname || !*mname)
> +			continue;
> +		if (!strcmp(mname, name)) {
> +			u32 moff;
> +
> +			if (__btf_member_bitfield_size(t, member)) {
> +				ret = -EOPNOTSUPP;
> +				goto out;
> +			}
> +			moff = __btf_member_bit_offset(t, member) / 8;
> +			ret = moff | (((u64)i) << 32);
> +			goto out;
> +		}
> +	}
> +
> +out:
> +	btf_put(btf);
> +	return ret;
> +}

[Severity: Medium]
Does storing the 64-bit return value in long ret truncate the upper 32
bits on 32-bit architectures?

Because long is 32 bits wide on 32-bit kernels, assigning
moff | (((u64)i) << 32) to ret discards the member index i in the upper
32 bits before returning, breaking callers such as struct_ops light
skeletons when querying any member at index i > 0.  Declaring ret as s64
would preserve both negative error codes and the full 64-bit value.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261106-lskel-struct-ops-v1-0-a4486ffc79cb@google.com?part=1

  reply	other threads:[~2026-11-06 20:37 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-06 20:19 [PATCH RFC bpf-next 0/7] bpf: Support struct_ops in light skeletons Siddharth Nayyar
2026-11-06 20:19 ` [PATCH RFC bpf-next 1/7] bpf: Add bpf_btf_get_struct_member_info() helper Siddharth Nayyar
2026-11-06 20:37   ` sashiko-bot [this message]
2026-11-06 20:56   ` bot+bpf-ci
2026-11-06 20:19 ` [PATCH RFC bpf-next 2/7] libbpf: Implement bpf_gen__init_kern_struct_ops() for light skeletons Siddharth Nayyar
2026-11-06 20:53   ` sashiko-bot
2026-11-06 20:56   ` bot+bpf-ci
2026-11-06 20:19 ` [PATCH RFC bpf-next 3/7] libbpf: Support BPF_MAP_TYPE_STRUCT_OPS in bpf_gen__map_create() Siddharth Nayyar
2026-11-06 20:33   ` sashiko-bot
2026-11-06 20:56   ` bot+bpf-ci
2026-11-06 20:19 ` [PATCH RFC bpf-next 4/7] libbpf: Support BPF_PROG_TYPE_STRUCT_OPS in bpf_gen__prog_load() Siddharth Nayyar
2026-11-06 20:56   ` bot+bpf-ci
2026-11-06 20:19 ` [PATCH RFC bpf-next 5/7] libbpf: Implement bpf_gen__struct_ops_update_elem() for light skeletons Siddharth Nayyar
2026-11-06 20:39   ` sashiko-bot
2026-11-06 20:56   ` bot+bpf-ci
2026-11-06 20:19 ` [PATCH RFC bpf-next 6/7] bpftool: Generate attach and detach for struct_ops in " Siddharth Nayyar
2026-11-06 20:19 ` [PATCH RFC bpf-next 7/7] selftests/bpf: Add light skeleton struct_ops tests Siddharth Nayyar
2026-11-09 19:46 ` [PATCH RFC bpf-next 0/7] bpf: Support struct_ops in light skeletons Ihor Solodrai
2026-11-09 21:39   ` Alexei Starovoitov
2026-11-10 13:08     ` Anton Protopopov
2026-11-10 13:12     ` Anton Protopopov
2026-11-11  7:35       ` Sid Nayyar

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=sashiko-outbox-202238@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sidnayyar@google.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