From: Leon Hwang <leon.hwang@linux.dev>
To: Kumar Kartikeya Dwivedi <memxor@gmail.com>, bot+bpf-ci@kernel.org
Cc: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com,
song@kernel.org, yonghong.song@linux.dev,
john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me,
haoluo@google.com, jolsa@kernel.org, shuah@kernel.org,
yangfeng@kylinos.cn, menglong8.dong@gmail.com,
puranjay@kernel.org, bjorn@kernel.org, pulehui@huawei.com,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
netdev@vger.kernel.org, kernel-patches-bot@fb.com,
martin.lau@kernel.org, clm@meta.com, ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next v3 3/6] bpf: Disallow !kprobe_write_ctx progs tail-calling kprobe_write_ctx progs
Date: Wed, 11 Mar 2026 14:08:01 +0800 [thread overview]
Message-ID: <94cfdbdc-833a-4838-af84-e0989e988418@linux.dev> (raw)
In-Reply-To: <CAP01T74sqmUAL7=PuzFPNbghX+6N_OzrsZiOHcMEMtg01CuL4A@mail.gmail.com>
On 11/3/26 01:23, Kumar Kartikeya Dwivedi wrote:
> On Tue, 3 Mar 2026 at 17:04, <bot+bpf-ci@kernel.org> wrote:
>>
>>> diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
>>> --- a/kernel/bpf/core.c
>>> +++ b/kernel/bpf/core.c
>>
>> [ ... ]
>>
>>> + switch (match) {
>>> + case BPF_MAP_OWNER_MATCH_FOR_INIT:
>>> + if (owner->kprobe_write_ctx != aux->kprobe_write_ctx)
>>> + return false;
>>> + break;
>>> +
>>> + case BPF_MAP_OWNER_MATCH_FOR_UPDATE:
>>> + if (!owner->kprobe_write_ctx && aux->kprobe_write_ctx)
>>> + return false;
>>> + break;
>>> + }
>>
>> In the v1 review, Alexei Starovoitov asked for strict conformance
>> both ways rather than one-directional validation:
>>
>> "Don't be fancy. Require strict conformance both ways
>> in *all* patches."
>>
>> https://lore.kernel.org/bpf/CAADnVQ+-V0-1i8_+CYpK7G0CnV-2n8e9Szv43yM3Az197eL_0A@mail.gmail.com/
>>
>> The BPF_MAP_OWNER_MATCH_FOR_UPDATE case still uses one-directional
>> matching, rejecting only !owner->kprobe_write_ctx && aux->kprobe_write_ctx
>> but allowing the reverse. Was this an intentional design choice, and
>> if so, should the changelog note the disagreement?
>>
>
> Let's follow the approach Alexei outlined, while the changes look ok
> to me, let's remove the one way check and just do
> owner->kprobe_write_ctx != aux->kprobe_write_ctx, same for the other
> two checks. With this we can also get rid of this INIT vs UPDATE
> distinction.
>
> Other than that I think patches are good, please also test both
> directions in the selftest in next respin.
>
Hi Kumar,
Thanks for your review.
I agreed that both-ways check could simplify the code. But, the UX could
not be great.
Let me explain it with an example.
struct {
__uint(type, BPF_MAP_TYPE_PROG_ARRAY);
__uint(max_entries, 1);
__uint(key_size, sizeof(__u32));
__uint(value_size, sizeof(__u32));
} jmp_table SEC(".maps");
SEC("?kprobe")
int prog_a(struct pt_regs *regs)
{
regs->ax = 0;
bpf_tail_call_static(regs, &jmp_table, 0);
return 0;
}
SEC("?kprobe")
int prog_b(struct pt_regs *regs)
{
return 0;
}
prog_a is kprobe_write_ctx.
prog_b is !kprobe_write_ctx. And, it will be added to jmp_table.
With both-ways check, prog_b is required to modify regs. I think it's
too restrictive for users to use prog_b as tail callee.
With one-way-check of this patch, prog_b can be used as tail callee to
keep regs as-is.
This was what I was concerned about, and the reason why I did not follow
Alexei's approach.
Thanks,
Leon
next prev parent reply other threads:[~2026-03-11 6:08 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-03 15:06 [PATCH bpf-next v3 0/6] bpf: Enhance __bpf_prog_map_compatible() Leon Hwang
2026-03-03 15:06 ` [PATCH bpf-next v3 1/6] bpf: Add fsession to verbose log in check_get_func_ip() Leon Hwang
2026-03-03 15:06 ` [PATCH bpf-next v3 2/6] bpf: Factor out bpf_map_owner_[init,matches]() helpers Leon Hwang
2026-03-03 15:06 ` [PATCH bpf-next v3 3/6] bpf: Disallow !kprobe_write_ctx progs tail-calling kprobe_write_ctx progs Leon Hwang
2026-03-03 16:01 ` bot+bpf-ci
2026-03-10 17:23 ` Kumar Kartikeya Dwivedi
2026-03-11 6:08 ` Leon Hwang [this message]
2026-03-11 9:21 ` Kumar Kartikeya Dwivedi
2026-03-11 15:44 ` Alexei Starovoitov
2026-03-11 16:00 ` Leon Hwang
2026-03-11 22:45 ` Jiri Olsa
2026-03-12 2:24 ` Leon Hwang
2026-03-12 10:46 ` Jiri Olsa
2026-03-12 13:39 ` Leon Hwang
2026-03-03 15:06 ` [PATCH bpf-next v3 4/6] bpf: Disallow !call_get_func_ip progs tail-calling call_get_func_ip progs Leon Hwang
2026-03-03 15:06 ` [PATCH bpf-next v3 5/6] bpf: Disallow !call_session_cookie progs tail-calling call_session_cookie progs Leon Hwang
2026-03-03 15:06 ` [PATCH bpf-next v3 6/6] selftests/bpf: Add tests to verify prog_array map compatibility 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=94cfdbdc-833a-4838-af84-e0989e988418@linux.dev \
--to=leon.hwang@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bjorn@kernel.org \
--cc=bot+bpf-ci@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=clm@meta.com \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kernel-patches-bot@fb.com \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=menglong8.dong@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pulehui@huawei.com \
--cc=puranjay@kernel.org \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yangfeng@kylinos.cn \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.