-
Notifications
You must be signed in to change notification settings - Fork 96
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
Conversation
Upstream branch: 68bc61c |
c8d202e
to
58cae51
Compare
Upstream branch: 68bc61c |
ace2b7f
to
0966ebf
Compare
58cae51
to
1659413
Compare
Upstream branch: 68bc61c |
0966ebf
to
7f6dfd1
Compare
1659413
to
e6cf751
Compare
Upstream branch: fc1c9e4 |
7f6dfd1
to
4ef7f5f
Compare
e6cf751
to
7722716
Compare
Upstream branch: 52dbd67 |
4ef7f5f
to
a7b813c
Compare
7722716
to
9835ec6
Compare
Upstream branch: 12bbcf8 |
a7b813c
to
fa8b520
Compare
9835ec6
to
6ee1f8b
Compare
Upstream branch: dc8543b |
fa8b520
to
718f61c
Compare
6ee1f8b
to
78363d5
Compare
Upstream branch: 2c21a0f |
718f61c
to
b42ed78
Compare
78363d5
to
957b42c
Compare
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>
Upstream branch: 32e18e7 |
b42ed78
to
6fdc251
Compare
957b42c
to
0f0cac4
Compare
At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=825393 irrelevant now. Closing PR. |
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