selftests/bpf: Clean up sys_nanosleep uses
Subsystems (3)
PATCH 1/1 selftests/bpf: Clean up sys_nanosleep uses
This patch cleans up a few things:
* dynptr_fail.c:
There is no sys_nanosleep tracepoint. dynptr_fail only tests that the prog load fails, so just SEC("?raw_tp") suffices here.
* test_bpf_cookie:
There is no sys_nanosleep kprobe. The prog is loaded in userspace through bpf_program__attach_kprobe_opts passing in SYS_NANOSLEEP_KPROBE_NAME, so just SEC("k{ret}probe") suffices here.
* test_helper_restricted:
There is no sys_nanosleep kprobe. test_helper_restricted only tests that the prog load fails, so just SEC("?kprobe")( suffices here.
There are no functional changes.
--- .../testing/selftests/bpf/progs/dynptr_fail.c | 56 +++++++++---------- .../selftests/bpf/progs/test_bpf_cookie.c | 4 +- .../bpf/progs/test_helper_restricted.c | 4 +- 3 files changed, 32 insertions(+), 32 deletions(-)
tools/testing/selftests/bpf/progs/dynptr_fail.c +28 -28
@@ -65,7 +65,7 @@ static int get_map_val_dynptr(struct bpf_dynptr *ptr)/* Every bpf_ringbuf_reserve_dynptr call must have a corresponding * bpf_ringbuf_submit/discard_dynptr call */ -SEC("?raw_tp/sys_nanosleep") +SEC("?raw_tp")int ringbuf_missing_release1 (void *ctx) {struct bpf_dynptr ptr;
@@ -77,7 +77,7 @@ int ringbuf_missing_release1(void *ctx)return 0 ; } -SEC("?raw_tp/sys_nanosleep") +SEC("?raw_tp")int ringbuf_missing_release2 (void *ctx) {struct bpf_dynptr ptr1, ptr2;
@@ -112,7 +112,7 @@ static int missing_release_callback_fn(__u32 index, void *data) }/* Any dynptr initialized within a callback must have bpf_dynptr_put called */ -SEC("?raw_tp/sys_nanosleep") +SEC("?raw_tp")int ringbuf_missing_release_callback (void *ctx) {bpf_loop (10 , missing_release_callback_fn,NULL ,0 );
@@ -120,7 +120,7 @@ int ringbuf_missing_release_callback(void *ctx) }/* Can't call bpf_ringbuf_submit/discard_dynptr on a non-initialized dynptr */ -SEC("?raw_tp/sys_nanosleep") +SEC("?raw_tp")int ringbuf_release_uninit_dynptr (void *ctx) {struct bpf_dynptr ptr;
@@ -132,7 +132,7 @@ int ringbuf_release_uninit_dynptr(void *ctx) }/* A dynptr can't be used after it has been invalidated */ -SEC("?raw_tp/sys_nanosleep") +SEC("?raw_tp")int use_after_invalid (void *ctx) {struct bpf_dynptr ptr;
@@ -151,7 +151,7 @@ int use_after_invalid(void *ctx) }/* Can't call non-dynptr ringbuf APIs on a dynptr ringbuf sample */ -SEC("?raw_tp/sys_nanosleep") +SEC("?raw_tp")int ringbuf_invalid_api (void *ctx) {struct bpf_dynptr ptr;
@@ -173,7 +173,7 @@ int ringbuf_invalid_api(void *ctx) }/* Can't add a dynptr to a map */ -SEC("?raw_tp/sys_nanosleep") +SEC("?raw_tp")int add_dynptr_to_map1 (void *ctx) {struct bpf_dynptr ptr;
@@ -190,7 +190,7 @@ int add_dynptr_to_map1(void *ctx) }/* Can't add a struct with an embedded dynptr to a map */ -SEC("?raw_tp/sys_nanosleep") +SEC("?raw_tp")int add_dynptr_to_map2 (void *ctx) {struct test_info x;
@@ -207,7 +207,7 @@ int add_dynptr_to_map2(void *ctx) }/* A data slice can't be accessed out of bounds */ -SEC("?raw_tp/sys_nanosleep") +SEC("?raw_tp")int data_slice_out_of_bounds_ringbuf (void *ctx) {struct bpf_dynptr ptr;
@@ -227,7 +227,7 @@ int data_slice_out_of_bounds_ringbuf(void *ctx)return 0 ; } -SEC("?raw_tp/sys_nanosleep") +SEC("?raw_tp")int data_slice_out_of_bounds_map_value (void *ctx) {__u32 key =0 , map_val;
@@ -247,7 +247,7 @@ int data_slice_out_of_bounds_map_value(void *ctx) }/* A data slice can't be used after it has been released */ -SEC("?raw_tp/sys_nanosleep") +SEC("?raw_tp")int data_slice_use_after_release (void *ctx) {struct bpf_dynptr ptr;
@@ -273,7 +273,7 @@ int data_slice_use_after_release(void *ctx) }/* A data slice must be first checked for NULL */ -SEC("?raw_tp/sys_nanosleep") +SEC("?raw_tp")int data_slice_missing_null_check1 (void *ctx) {struct bpf_dynptr ptr;
@@ -293,7 +293,7 @@ int data_slice_missing_null_check1(void *ctx) }/* A data slice can't be dereferenced if it wasn't checked for null */ -SEC("?raw_tp/sys_nanosleep") +SEC("?raw_tp")int data_slice_missing_null_check2 (void *ctx) {struct bpf_dynptr ptr;
@@ -315,7 +315,7 @@ int data_slice_missing_null_check2(void *ctx)/* Can't pass in a dynptr as an arg to a helper function that doesn't take in a * dynptr argument */ -SEC("?raw_tp/sys_nanosleep") +SEC("?raw_tp")int invalid_helper1 (void *ctx) {struct bpf_dynptr ptr;
@@ -329,7 +329,7 @@ int invalid_helper1(void *ctx) }/* A dynptr can't be passed into a helper function at a non-zero offset */ -SEC("?raw_tp/sys_nanosleep") +SEC("?raw_tp")int invalid_helper2 (void *ctx) {struct bpf_dynptr ptr;
@@ -344,7 +344,7 @@ int invalid_helper2(void *ctx) }/* A bpf_dynptr is invalidated if it's been written into */ -SEC("?raw_tp/sys_nanosleep") +SEC("?raw_tp")int invalid_write1 (void *ctx) {struct bpf_dynptr ptr;
@@ -365,7 +365,7 @@ int invalid_write1(void *ctx)* A bpf_dynptr can't be used as a dynptr if it has been written into at a fixed * offset */ -SEC("?raw_tp/sys_nanosleep") +SEC("?raw_tp")int invalid_write2 (void *ctx) {struct bpf_dynptr ptr;
@@ -388,7 +388,7 @@ int invalid_write2(void *ctx)* A bpf_dynptr can't be used as a dynptr if it has been written into at a * non-const offset */ -SEC("?raw_tp/sys_nanosleep") +SEC("?raw_tp")int invalid_write3 (void *ctx) {struct bpf_dynptr ptr;
@@ -419,7 +419,7 @@ static int invalid_write4_callback(__u32 index, void *data)/* If the dynptr is written into in a callback function, it should * be invalidated as a dynptr */ -SEC("?raw_tp/sys_nanosleep") +SEC("?raw_tp")int invalid_write4 (void *ctx) {struct bpf_dynptr ptr;
@@ -436,7 +436,7 @@ int invalid_write4(void *ctx)/* A globally-defined bpf_dynptr can't be used (it must reside as a stack frame) */ struct bpf_dynptr global_dynptr; -SEC("?raw_tp/sys_nanosleep") +SEC("?raw_tp")int global (void *ctx) {/* this should fail */
@@ -448,7 +448,7 @@ int global(void *ctx) }/* A direct read should fail */ -SEC("?raw_tp/sys_nanosleep") +SEC("?raw_tp")int invalid_read1 (void *ctx) {struct bpf_dynptr ptr;
@@ -464,7 +464,7 @@ int invalid_read1(void *ctx) }/* A direct read at an offset should fail */ -SEC("?raw_tp/sys_nanosleep") +SEC("?raw_tp")int invalid_read2 (void *ctx) {struct bpf_dynptr ptr;
@@ -479,7 +479,7 @@ int invalid_read2(void *ctx) }/* A direct read at an offset into the lower stack slot should fail */ -SEC("?raw_tp/sys_nanosleep") +SEC("?raw_tp")int invalid_read3 (void *ctx) {struct bpf_dynptr ptr1, ptr2;
@@ -505,7 +505,7 @@ static int invalid_read4_callback(__u32 index, void *data) }/* A direct read within a callback function should fail */ -SEC("?raw_tp/sys_nanosleep") +SEC("?raw_tp")int invalid_read4 (void *ctx) {struct bpf_dynptr ptr;
@@ -520,7 +520,7 @@ int invalid_read4(void *ctx) }/* Initializing a dynptr on an offset should fail */ -SEC("?raw_tp/sys_nanosleep") +SEC("?raw_tp")int invalid_offset (void *ctx) {struct bpf_dynptr ptr;
@@ -534,7 +534,7 @@ int invalid_offset(void *ctx) }/* Can't release a dynptr twice */ -SEC("?raw_tp/sys_nanosleep") +SEC("?raw_tp")int release_twice (void *ctx) {struct bpf_dynptr ptr;
@@ -560,7 +560,7 @@ static int release_twice_callback_fn(__u32 index, void *data)/* Test that releasing a dynptr twice, where one of the releases happens * within a calback function, fails */ -SEC("?raw_tp/sys_nanosleep") +SEC("?raw_tp")int release_twice_callback (void *ctx) {struct bpf_dynptr ptr;
@@ -575,7 +575,7 @@ int release_twice_callback(void *ctx) }/* Reject unsupported local mem types for dynptr_from_mem API */ -SEC("?raw_tp/sys_nanosleep") +SEC("?raw_tp")int dynptr_from_mem_invalid_api (void *ctx) {struct bpf_dynptr ptr;
tools/testing/selftests/bpf/progs/test_bpf_cookie.c +2 -2
@@ -28,14 +28,14 @@ static void update(void *ctx, __u64 *res) *res |=bpf_get_attach_cookie (ctx); } -SEC("kprobe/sys_nanosleep") +SEC("kprobe")int handle_kprobe (struct pt_regs *ctx) {update (ctx, &kprobe_res);return 0 ; } -SEC("kretprobe/sys_nanosleep") +SEC("kretprobe")int handle_kretprobe (struct pt_regs *ctx) {update (ctx, &kretprobe_res);
tools/testing/selftests/bpf/progs/test_helper_restricted.c +2 -2
@@ -72,7 +72,7 @@ int tp_timer(void *ctx)return 0 ; } -SEC("?kprobe/sys_nanosleep") +SEC("?kprobe")int kprobe_timer (void *ctx) {timer_work ();
@@ -104,7 +104,7 @@ int tp_spin_lock(void *ctx)return 0 ; } -SEC("?kprobe/sys_nanosleep") +SEC("?kprobe")int kprobe_spin_lock (void *ctx) {spin_lock_work ();
Signature · 1 line
2.30.2
Quoted 11 lines · Joanne Koong
This patch cleans up a few things:
*
dynptr_fail.c:
There is nosys_nanosleeptracepoint.dynptr_failonly tests that the prog load fails, so justSEC("?raw_tp")suffices here.*
test_bpf_cookie:
There is nosys_nanosleepkprobe. The prog is loaded in userspace throughbpf_program__attach_kprobe_optspassing inSYS_NANOSLEEP_KPROBE_NAME, so justSEC("k{ret}probe")suffices here.
Quoted 8 lines
*
test_helper_restricted:
There is nosys_nanosleepkprobe.test_helper_restrictedonly tests that the prog load fails, so just SEC("?kprobe")( suffices here.There are no functional changes.
Signed-off-by Joanne Koong <[email protected]>Suggested-by Andrii Nakryiko <[email protected]>
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Quoted 6 lines · On Fri, 5 Aug 2022 10:14:05 -0700 you wrote:
This patch cleans up a few things:
*
dynptr_fail.c:
There is nosys_nanosleeptracepoint.dynptr_failonly tests that the prog load fails, so justSEC("?raw_tp")suffices here.
Quoted 6 lines
*
test_bpf_cookie:
There is nosys_nanosleepkprobe. The prog is loaded in userspace throughbpf_program__attach_kprobe_optspassing inSYS_NANOSLEEP_KPROBE_NAME, so justSEC("k{ret}probe")suffices here.[...]
Here is the summary with links:
- [bpf-next,v1] selftests/bpf: Clean up sys_nanosleep uses
https://git.kernel.org/bpf/bpf-next/c/5653f55ebd76
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html