From: Leon Hwang <leon.hwang@linux.dev>
To: sashiko@lists.linux.dev
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v13 4/8] bpf: Add syscall common attributes support for prog_load
Date: Wed, 13 May 2026 18:44:32 +0800 [thread overview]
Message-ID: <4e22ee14-6d49-4eff-83df-cc1e908c17e5@linux.dev> (raw)
In-Reply-To: <20260512221819.7EA2FC2BCB0@smtp.kernel.org>
On 13/5/26 06:18, sashiko-bot@kernel.org wrote:
[...]
>> int bpf_log_attr_init(struct bpf_log_attr *log, u64 log_buf, u32 log_size, u32 log_level,
>> - u32 offsetof_log_true_size, bpfptr_t uattr)
>> + u32 offsetof_log_true_size, bpfptr_t uattr, struct bpf_common_attr *common,
>> + bpfptr_t uattr_common, u32 size_common)
>> {
>> + char __user *ubuf_common = u64_to_user_ptr(common->log_buf);
>> char __user *ubuf = u64_to_user_ptr(log_buf);
>>
>> + if (!bpf_verifier_log_attr_valid(common->log_level, ubuf_common, common->log_size) ||
>> + !bpf_verifier_log_attr_valid(log_level, ubuf, log_size))
>> + return -EINVAL;
>> +
>> + if (ubuf && ubuf_common && (ubuf != ubuf_common || log_size != common->log_size ||
>> + log_level != common->log_level))
>> + return -EINVAL;
>
> If a user specifies log_level != 0 but leaves log_buf == NULL to probe for
> log_true_size, will these checks bypass conflicts?
>
> If one side provides a complete tuple and the other provides only log_level,
> or if both provide mismatched log_levels without buffers, it appears the
> conflict checks are skipped and no -EINVAL is returned.
>
Correct.
However, if users want to probe for log_true_size, they should not
provide common attrs. It is compatible for bpf libraries to probe for
log_true_size using union bpf_attr without providing common attrs.
>> +
>> memset(log, 0, sizeof(*log));
>> log->ubuf = ubuf;
>> log->size = log_size;
>> log->level = log_level;
>> log->offsetof_true_size = offsetof_log_true_size;
>> log->uattr = uattr;
>> +
>> + if (!ubuf && ubuf_common) {
>
> Does this condition silently ignore valid common->log_level configurations?
>
> If the user provides only common->log_level via bpf_common_attr for a log
> size dry-run, ubuf_common evaluates to NULL. The condition here would
> evaluate to false, and common->log_level would be ignored instead of
> applied.
>
The user should probe for log size using union bpf_attr instead of
common attrs.
> Also, if both specific and common attributes provide identical log
> parameters, the code appears to unconditionally use uattr for the
> log_true_size writeback since ubuf is not NULL.
>
> If the original uattr uses an older layout without space for log_true_size,
> log->offsetof_true_size will be set to 0. Does this mean log_true_size
> writeback will be lost even if the user provided a modern attr_common
> struct with sufficient space to receive it?
>
This was intentional.
If the user uses union bpf_attr to receive log, he should provide the
space for log_true_size.
IOW, if the user uses common attrs to receive log, he should provide the
space in common attrs for log_true_size.
Thanks,
Leon
>> + log->ubuf = ubuf_common;
>> + log->size = common->log_size;
>> + log->level = common->log_level;
>> + log->uattr = uattr_common;
>> + log->offsetof_true_size = 0;
>> + if (size_common >= offsetofend(struct bpf_common_attr, log_true_size))
>> + log->offsetof_true_size = offsetof(struct bpf_common_attr, log_true_size);
>> + }
>> return 0;
>> }
>
next prev parent reply other threads:[~2026-05-13 10:45 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-11 15:28 [PATCH bpf-next v13 0/8] bpf: Extend BPF syscall with common attributes support Leon Hwang
2026-05-11 15:28 ` [PATCH bpf-next v13 1/8] " Leon Hwang
2026-05-11 16:19 ` bot+bpf-ci
2026-05-11 16:53 ` Alexei Starovoitov
2026-05-12 2:41 ` Leon Hwang
2026-05-11 15:28 ` [PATCH bpf-next v13 2/8] libbpf: Add support for extended BPF syscall Leon Hwang
2026-05-11 15:28 ` [PATCH bpf-next v13 3/8] bpf: Refactor reporting log_true_size for prog_load Leon Hwang
2026-05-11 15:28 ` [PATCH bpf-next v13 4/8] bpf: Add syscall common attributes support " Leon Hwang
2026-05-12 22:18 ` sashiko-bot
2026-05-13 10:44 ` Leon Hwang [this message]
2026-05-11 15:28 ` [PATCH bpf-next v13 5/8] bpf: Add syscall common attributes support for btf_load Leon Hwang
2026-05-11 15:28 ` [PATCH bpf-next v13 6/8] bpf: Add syscall common attributes support for map_create Leon Hwang
2026-05-11 16:19 ` bot+bpf-ci
2026-05-11 17:07 ` Alexei Starovoitov
2026-05-12 2:47 ` Leon Hwang
2026-05-12 23:36 ` sashiko-bot
2026-05-13 10:45 ` Leon Hwang
2026-05-11 15:28 ` [PATCH bpf-next v13 7/8] libbpf: " Leon Hwang
2026-05-12 23:56 ` sashiko-bot
2026-05-13 10:46 ` Leon Hwang
2026-05-11 15:28 ` [PATCH bpf-next v13 8/8] selftests/bpf: Add tests to verify map create failure log Leon Hwang
2026-05-13 0:33 ` sashiko-bot
2026-05-13 10:47 ` Leon Hwang
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=4e22ee14-6d49-4eff-83df-cc1e908c17e5@linux.dev \
--to=leon.hwang@linux.dev \
--cc=bpf@vger.kernel.org \
--cc=sashiko@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