Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trusted PTR_TO_BTF_ID arg support in global subprogs #6323

Closed

Conversation

kernel-patches-daemon-bpf[bot]
Copy link

Pull request for series with
subject: Trusted PTR_TO_BTF_ID arg support in global subprogs
version: 2
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=820027

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: c8632ac
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=820027
version: 2

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: be4840b
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=820027
version: 2

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: e6be8cd
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=820027
version: 2

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: e6be8cd
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=820027
version: 2

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: e48f0f4
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=820027
version: 2

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: fa7178b
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=820027
version: 2

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: beb53f3
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=820027
version: 2

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 29788f3
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=820027
version: 2

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 06a33d0
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=820027
version: 2

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: f149d03
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=820027
version: 2

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: efaa47d
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=820027
version: 2

Now that feature detection code is in bpf-next tree, integrate __arg_ctx
kernel-side support into kernel_supports() framework.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Adjust PERF_EVENT type enforcement around __arg_ctx to match exactly
what kernel is doing.

Fixes: 76ec90a ("libbpf: warn on unexpected __arg_ctx type when rewriting BTF")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Now that bpf and bpf-next trees converged and we don't run the risk of
merge conflicts, move btf_validate_prog_ctx_type() into its most logical
place inside the main logic loop.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Add support for passing PTR_TO_BTF_ID registers to global subprogs.
Currently only PTR_TRUSTED flavor of PTR_TO_BTF_ID is supported.
Non-NULL semantics is assumed, so caller will be forced to prove
PTR_TO_BTF_ID can't be NULL.

Note, we disallow global subprogs to destroy passed in PTR_TO_BTF_ID
arguments, even the trusted one. We achieve that by not setting
ref_obj_id when validating subprog code. This basically enforces (in
Rust terms) borrowing semantics vs move semantics. Borrowing semantics
seems to be a better fit for isolated global subprog validation
approach.

Implementation-wise, we utilize existing logic for matching
user-provided BTF type to kernel-side BTF type, used by BPF CO-RE logic
and following same matching rules. We enforce a unique match for types.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Add ability to mark arg:trusted arguments with optional arg:maybe_null
tag to mark is as PTR_TO_BTF_ID_OR_NULL variant, which will allow
callers to pass NULL, and subsequently will force global subprog's code
to do NULL check. This allows to have "optional" PTR_TO_BTF_ID values
passed into global subprogs.

For now arg:maybe_null cannot be combined with anything else.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Add __arg_trusted to annotate global func args that accept trusted
PTR_TO_BTF_ID arguments.

Also add __arg_maybe_null to combine with __arg_trusted (and maybe other
tags in the future) to force global subprog itself (i.e., callee) to do
NULL checks, as opposed to default non-NULL semantics (and thus caller's
responsibility to ensure non-NULL values).

Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Add a bunch of test cases validating behavior of __arg_trusted and its
combination with __arg_maybe_null tag. We also validate CO-RE flavor
support by kernel for __arg_trusted args.

Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: ced33f2
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=820027
version: 2

@kernel-patches-daemon-bpf
Copy link
Author

At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=820027 irrelevant now. Closing PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant