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

Fix global subprog PTR_TO_CTX arg handling #6432

Closed

Conversation

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

Pull request for series with
subject: Fix global subprog PTR_TO_CTX arg handling
version: 2
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=825393

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 68bc61c
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=825393
version: 2

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 68bc61c
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=825393
version: 2

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 68bc61c
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=825393
version: 2

@kernel-patches-daemon-bpf
Copy link
Author

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

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 52dbd67
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=825393
version: 2

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 12bbcf8
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=825393
version: 2

@kernel-patches-daemon-bpf
Copy link
Author

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

@kernel-patches-daemon-bpf
Copy link
Author

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

Return result of btf_get_prog_ctx_type() is never used and callers only
check NULL vs non-NULL case to determine if given type matches expected
PTR_TO_CTX type. So rename function to `btf_is_prog_ctx_type()` and
return a simple true/false. We'll use this simpler interface to handle
kprobe program type's special typedef case in the next patch.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
…al arg

Expected canonical argument type for global function arguments
representing PTR_TO_CTX is `bpf_user_pt_regs_t *ctx`. This currently
works on s390x by accident because kernel resolves such typedef to
underlying struct (which is anonymous on s390x), and erroneously
accepting it as expected context type. We are fixing this problem next,
which would break s390x arch, so we need to handle `bpf_user_pt_regs_t`
case explicitly for KPROBE programs.

Fixes: 91cc1a9 ("bpf: Annotate context types")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
For program types that don't have named context type name (e.g., BPF
iterator programs or tracepoint programs), ctx_tname will be a non-NULL
empty string. For such programs it shouldn't be possible to have
PTR_TO_CTX argument for global subprogs based on type name alone.
arg:ctx tag is the only way to have PTR_TO_CTX passed into global
subprog for such program types.

Fix this loophole, which currently would assume PTR_TO_CTX whenever
user uses a pointer to anonymous struct as an argument to their global
subprogs. This happens in practice with the following (quite common, in
practice) approach:

typedef struct { /* anonymous */
    int x;
} my_type_t;

int my_subprog(my_type_t *arg) { ... }

User's intent is to have PTR_TO_MEM argument for `arg`, but verifier
will complain about expecting PTR_TO_CTX.

This fix also closes unintended s390x-specific KPROBE handling of
PTR_TO_CTX case. Selftest change is necessary to accommodate this.

Fixes: 91cc1a9 ("bpf: Annotate context types")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Add tests validating that kernel handles pointer to anonymous struct
argument as PTR_TO_MEM case, not as PTR_TO_CTX case.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 32e18e7
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=825393
version: 2

@kernel-patches-daemon-bpf
Copy link
Author

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

@kernel-patches-daemon-bpf kernel-patches-daemon-bpf bot deleted the series/825393=>bpf-next branch February 14, 2024 02:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant