BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Leon Hwang" <leon.hwang@linux.dev>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v14 1/8] bpf: Extend BPF syscall with common attributes support
Date: Wed, 13 May 2026 22:48:22 +0000	[thread overview]
Message-ID: <20260513224823.6494FC19425@smtp.kernel.org> (raw)
In-Reply-To: <20260512153157.28382-2-leon.hwang@linux.dev>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Implicit compiler padding in UAPI `struct bpf_common_attr` compromises backward compatibility.
- [High] `BPF_COMMON_ATTRS` flag is silently accepted and ignored for unsupported BPF commands, breaking UAPI feature probing.
--

commit 8985d7da06248bc1e83a6cb46060187b0440e549
Author: Leon Hwang <leon.hwang@linux.dev>

bpf: Extend BPF syscall with common attributes support

This commit adds generic BPF syscall support for passing common attributes
like log_buf, log_size, log_level, and log_true_size. It introduces a new
UAPI struct bpf_common_attr and a BPF_COMMON_ATTRS command flag bit to
indicate when these attributes are provided.

> diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
> --- a/include/uapi/linux/bpf.h
> +++ b/include/uapi/linux/bpf.h

[ ... ]

> @@ -1500,6 +1501,13 @@ struct bpf_stack_build_id {
>  	};
>  };
>  
> +struct bpf_common_attr {
> +	__aligned_u64 log_buf;
> +	__u32 log_size;
> +	__u32 log_level;
> +	__u32 log_true_size;
> +};

Does this UAPI structure contain implicit trailing padding? With one
__aligned_u64 (8 bytes) and three __u32 fields (12 bytes), there are 20
bytes of data. Because of the 8-byte alignment, the compiler will pad the
structure to 24 bytes.

If a future kernel extension adds a new 4-byte field, older userspace programs
allocating this structure on the stack might inadvertently pass uninitialized
stack garbage into the new field, permanently breaking backward compatibility.

Should this include an explicit __u32 pad; field, and should the kernel
explicitly validate that attr_common.pad == 0?

[ ... ]

> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> --- a/kernel/bpf/syscall.c
> +++ b/kernel/bpf/syscall.c

[ ... ]

> @@ -6226,6 +6228,20 @@ static int __sys_bpf(enum bpf_cmd cmd, bpfptr_t uattr, unsigned int size)
>  	if (copy_from_bpfptr(&attr, uattr, size) != 0)
>  		return -EFAULT;
>  
> +	memset(&attr_common, 0, sizeof(attr_common));
> +	if (cmd & BPF_COMMON_ATTRS) {
> +		err = bpf_check_uarg_tail_zero(uattr_common, sizeof(attr_common), size_common);
> +		if (err)
> +			return err;
> +
> +		cmd &= ~BPF_COMMON_ATTRS;

By unconditionally stripping BPF_COMMON_ATTRS from the command here, won't any
BPF command (such as BPF_MAP_FREEZE) successfully accept the flag but silently
ignore the provided common attributes?

This might prevent userspace from correctly probing whether the running kernel
actually supports common attributes for a given command.

Should __sys_bpf() enforce a whitelist of supported commands before stripping
the flag, or explicitly reject the flag for commands that do not support it?

> +		size_common = min_t(u32, size_common, sizeof(attr_common));
> +		if (copy_from_bpfptr(&attr_common, uattr_common, size_common) != 0)
> +			return -EFAULT;
> +	} else {
> +		size_common = 0;
> +	}
> +

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260512153157.28382-1-leon.hwang@linux.dev?part=1

  reply	other threads:[~2026-05-13 22:48 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-12 15:31 [PATCH bpf-next v14 0/8] bpf: Extend BPF syscall with common attributes support Leon Hwang
2026-05-12 15:31 ` [PATCH bpf-next v14 1/8] " Leon Hwang
2026-05-13 22:48   ` sashiko-bot [this message]
2026-05-12 15:31 ` [PATCH bpf-next v14 2/8] libbpf: Add support for extended BPF syscall Leon Hwang
2026-05-12 16:23   ` bot+bpf-ci
2026-05-13  2:10     ` Leon Hwang
2026-05-12 15:31 ` [PATCH bpf-next v14 3/8] bpf: Refactor reporting log_true_size for prog_load Leon Hwang
2026-05-12 15:31 ` [PATCH bpf-next v14 4/8] bpf: Add syscall common attributes support " Leon Hwang
2026-05-13 23:56   ` sashiko-bot
2026-05-12 15:31 ` [PATCH bpf-next v14 5/8] bpf: Add syscall common attributes support for btf_load Leon Hwang
2026-05-12 15:31 ` [PATCH bpf-next v14 6/8] bpf: Add syscall common attributes support for map_create Leon Hwang
2026-05-14  0:46   ` sashiko-bot
2026-05-12 15:31 ` [PATCH bpf-next v14 7/8] libbpf: " Leon Hwang
2026-05-14  1:08   ` sashiko-bot
2026-05-12 15:31 ` [PATCH bpf-next v14 8/8] selftests/bpf: Add tests to verify map create failure log Leon Hwang
2026-05-14  1:25   ` sashiko-bot
2026-05-12 19:50 ` [PATCH bpf-next v14 0/8] bpf: Extend BPF syscall with common attributes support 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=20260513224823.6494FC19425@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=leon.hwang@linux.dev \
    --cc=sashiko-reviews@lists.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