From: Martin KaFai Lau <martin.lau@linux.dev>
To: Kui-Feng Lee <sinquersw@gmail.com>
Cc: kuifeng@meta.com, John Fastabend <john.fastabend@gmail.com>,
Kui-Feng Lee <thinker.li@gmail.com>,
bpf@vger.kernel.org, ast@kernel.org, song@kernel.org,
kernel-team@meta.com, andrii@kernel.org
Subject: Re: [PATCH bpf-next] selftests/bpf: Make sure libbpf doesn't enforce the signature of a func pointer.
Date: Wed, 3 Apr 2024 13:52:24 -0700 [thread overview]
Message-ID: <ed6929e4-cf8f-43cc-869a-d79b0158c9ea@linux.dev> (raw)
In-Reply-To: <cf7c6aaa-123b-43b2-8c7b-2c1e2b2dcb67@gmail.com>
On 4/2/24 10:00 AM, Kui-Feng Lee wrote:
>
>
>
> On 4/1/24 18:43, John Fastabend wrote:
>> Kui-Feng Lee wrote:
>>> The verifier in the kernel checks the signatures of struct_ops
>>> operators. Libbpf should not verify it in order to allow flexibility in
This description probably is not accurate. iirc, the verifier does not check the
function signature either. The verifier rejects only when the struct_ops prog
tries to access something invalid. e.g. reading a function argument that does
not exist in the running kernel.
>>> loading different implementations of an operator with different signatures
>>> to try to comply with the kernel, even if the signature defined in the BPF
>>> programs does not match with the implementations and the kernel.
>>> This feature enables user space applications to manage the variations
>>> between different versions of the kernel by attempting various
>>> implementations of an operator.
>>
>> What is the utility of this? I'm missing what difference it would be
>> if libbpf rejected vs kernel rejecting it? For backwards compat the
>> kernel will fail or libbpf might throw an error and user will have to
>> fixup signature regardless right? Why not get the error as early as
>> possible.
>
> The check described here is that libbpf compares BTF types of functions
> and function pointers in struct_ops types in BPF programs, which may
> differ from kernel definitions.
>
> A scenario here is a struct_ops type that includes an operator op_A with
> different versions depending on the kernel. All other fields in the
> struct_ops type have the same types. The application has only one
> definition for this struct_ops type, but the implementation of op_A is
> done separately for each version.
>
> The application can try variations by assigning implementations to the
> op_A field until one is accepted by the kernel if libbpf doesn’t enforce
It probably would be clearer if the test actually does the retry. e.g. Try to
load a struct_ops prog which reads an extra arg that is not supported by the
running kernel and gets rejected by verifier. Then assigns an older struct_ops
prog to the skel->struct_ops...->fn and loads successfully by the verifier.
next prev parent reply other threads:[~2024-04-03 20:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-01 22:30 [PATCH bpf-next] selftests/bpf: Make sure libbpf doesn't enforce the signature of a func pointer Kui-Feng Lee
2024-04-02 1:43 ` John Fastabend
2024-04-02 17:00 ` Kui-Feng Lee
2024-04-03 20:52 ` Martin KaFai Lau [this message]
2024-04-03 21:15 ` Andrii Nakryiko
2024-04-03 21:34 ` Kui-Feng Lee
2024-04-03 21:28 ` Kui-Feng Lee
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=ed6929e4-cf8f-43cc-869a-d79b0158c9ea@linux.dev \
--to=martin.lau@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=john.fastabend@gmail.com \
--cc=kernel-team@meta.com \
--cc=kuifeng@meta.com \
--cc=sinquersw@gmail.com \
--cc=song@kernel.org \
--cc=thinker.li@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