Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

Suggested-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20220805171405.2272103-1-joannelkoong@gmail.com

authored by

Joanne Koong and committed by
Daniel Borkmann
5653f55e d25f40ff

+32 -32
+28 -28
tools/testing/selftests/bpf/progs/dynptr_fail.c
··· 65 65 /* Every bpf_ringbuf_reserve_dynptr call must have a corresponding 66 66 * bpf_ringbuf_submit/discard_dynptr call 67 67 */ 68 - SEC("?raw_tp/sys_nanosleep") 68 + SEC("?raw_tp") 69 69 int ringbuf_missing_release1(void *ctx) 70 70 { 71 71 struct bpf_dynptr ptr; ··· 77 77 return 0; 78 78 } 79 79 80 - SEC("?raw_tp/sys_nanosleep") 80 + SEC("?raw_tp") 81 81 int ringbuf_missing_release2(void *ctx) 82 82 { 83 83 struct bpf_dynptr ptr1, ptr2; ··· 112 112 } 113 113 114 114 /* Any dynptr initialized within a callback must have bpf_dynptr_put called */ 115 - SEC("?raw_tp/sys_nanosleep") 115 + SEC("?raw_tp") 116 116 int ringbuf_missing_release_callback(void *ctx) 117 117 { 118 118 bpf_loop(10, missing_release_callback_fn, NULL, 0); ··· 120 120 } 121 121 122 122 /* Can't call bpf_ringbuf_submit/discard_dynptr on a non-initialized dynptr */ 123 - SEC("?raw_tp/sys_nanosleep") 123 + SEC("?raw_tp") 124 124 int ringbuf_release_uninit_dynptr(void *ctx) 125 125 { 126 126 struct bpf_dynptr ptr; ··· 132 132 } 133 133 134 134 /* A dynptr can't be used after it has been invalidated */ 135 - SEC("?raw_tp/sys_nanosleep") 135 + SEC("?raw_tp") 136 136 int use_after_invalid(void *ctx) 137 137 { 138 138 struct bpf_dynptr ptr; ··· 151 151 } 152 152 153 153 /* Can't call non-dynptr ringbuf APIs on a dynptr ringbuf sample */ 154 - SEC("?raw_tp/sys_nanosleep") 154 + SEC("?raw_tp") 155 155 int ringbuf_invalid_api(void *ctx) 156 156 { 157 157 struct bpf_dynptr ptr; ··· 173 173 } 174 174 175 175 /* Can't add a dynptr to a map */ 176 - SEC("?raw_tp/sys_nanosleep") 176 + SEC("?raw_tp") 177 177 int add_dynptr_to_map1(void *ctx) 178 178 { 179 179 struct bpf_dynptr ptr; ··· 190 190 } 191 191 192 192 /* Can't add a struct with an embedded dynptr to a map */ 193 - SEC("?raw_tp/sys_nanosleep") 193 + SEC("?raw_tp") 194 194 int add_dynptr_to_map2(void *ctx) 195 195 { 196 196 struct test_info x; ··· 207 207 } 208 208 209 209 /* A data slice can't be accessed out of bounds */ 210 - SEC("?raw_tp/sys_nanosleep") 210 + SEC("?raw_tp") 211 211 int data_slice_out_of_bounds_ringbuf(void *ctx) 212 212 { 213 213 struct bpf_dynptr ptr; ··· 227 227 return 0; 228 228 } 229 229 230 - SEC("?raw_tp/sys_nanosleep") 230 + SEC("?raw_tp") 231 231 int data_slice_out_of_bounds_map_value(void *ctx) 232 232 { 233 233 __u32 key = 0, map_val; ··· 247 247 } 248 248 249 249 /* A data slice can't be used after it has been released */ 250 - SEC("?raw_tp/sys_nanosleep") 250 + SEC("?raw_tp") 251 251 int data_slice_use_after_release(void *ctx) 252 252 { 253 253 struct bpf_dynptr ptr; ··· 273 273 } 274 274 275 275 /* A data slice must be first checked for NULL */ 276 - SEC("?raw_tp/sys_nanosleep") 276 + SEC("?raw_tp") 277 277 int data_slice_missing_null_check1(void *ctx) 278 278 { 279 279 struct bpf_dynptr ptr; ··· 293 293 } 294 294 295 295 /* A data slice can't be dereferenced if it wasn't checked for null */ 296 - SEC("?raw_tp/sys_nanosleep") 296 + SEC("?raw_tp") 297 297 int data_slice_missing_null_check2(void *ctx) 298 298 { 299 299 struct bpf_dynptr ptr; ··· 315 315 /* Can't pass in a dynptr as an arg to a helper function that doesn't take in a 316 316 * dynptr argument 317 317 */ 318 - SEC("?raw_tp/sys_nanosleep") 318 + SEC("?raw_tp") 319 319 int invalid_helper1(void *ctx) 320 320 { 321 321 struct bpf_dynptr ptr; ··· 329 329 } 330 330 331 331 /* A dynptr can't be passed into a helper function at a non-zero offset */ 332 - SEC("?raw_tp/sys_nanosleep") 332 + SEC("?raw_tp") 333 333 int invalid_helper2(void *ctx) 334 334 { 335 335 struct bpf_dynptr ptr; ··· 344 344 } 345 345 346 346 /* A bpf_dynptr is invalidated if it's been written into */ 347 - SEC("?raw_tp/sys_nanosleep") 347 + SEC("?raw_tp") 348 348 int invalid_write1(void *ctx) 349 349 { 350 350 struct bpf_dynptr ptr; ··· 365 365 * A bpf_dynptr can't be used as a dynptr if it has been written into at a fixed 366 366 * offset 367 367 */ 368 - SEC("?raw_tp/sys_nanosleep") 368 + SEC("?raw_tp") 369 369 int invalid_write2(void *ctx) 370 370 { 371 371 struct bpf_dynptr ptr; ··· 388 388 * A bpf_dynptr can't be used as a dynptr if it has been written into at a 389 389 * non-const offset 390 390 */ 391 - SEC("?raw_tp/sys_nanosleep") 391 + SEC("?raw_tp") 392 392 int invalid_write3(void *ctx) 393 393 { 394 394 struct bpf_dynptr ptr; ··· 419 419 /* If the dynptr is written into in a callback function, it should 420 420 * be invalidated as a dynptr 421 421 */ 422 - SEC("?raw_tp/sys_nanosleep") 422 + SEC("?raw_tp") 423 423 int invalid_write4(void *ctx) 424 424 { 425 425 struct bpf_dynptr ptr; ··· 436 436 437 437 /* A globally-defined bpf_dynptr can't be used (it must reside as a stack frame) */ 438 438 struct bpf_dynptr global_dynptr; 439 - SEC("?raw_tp/sys_nanosleep") 439 + SEC("?raw_tp") 440 440 int global(void *ctx) 441 441 { 442 442 /* this should fail */ ··· 448 448 } 449 449 450 450 /* A direct read should fail */ 451 - SEC("?raw_tp/sys_nanosleep") 451 + SEC("?raw_tp") 452 452 int invalid_read1(void *ctx) 453 453 { 454 454 struct bpf_dynptr ptr; ··· 464 464 } 465 465 466 466 /* A direct read at an offset should fail */ 467 - SEC("?raw_tp/sys_nanosleep") 467 + SEC("?raw_tp") 468 468 int invalid_read2(void *ctx) 469 469 { 470 470 struct bpf_dynptr ptr; ··· 479 479 } 480 480 481 481 /* A direct read at an offset into the lower stack slot should fail */ 482 - SEC("?raw_tp/sys_nanosleep") 482 + SEC("?raw_tp") 483 483 int invalid_read3(void *ctx) 484 484 { 485 485 struct bpf_dynptr ptr1, ptr2; ··· 505 505 } 506 506 507 507 /* A direct read within a callback function should fail */ 508 - SEC("?raw_tp/sys_nanosleep") 508 + SEC("?raw_tp") 509 509 int invalid_read4(void *ctx) 510 510 { 511 511 struct bpf_dynptr ptr; ··· 520 520 } 521 521 522 522 /* Initializing a dynptr on an offset should fail */ 523 - SEC("?raw_tp/sys_nanosleep") 523 + SEC("?raw_tp") 524 524 int invalid_offset(void *ctx) 525 525 { 526 526 struct bpf_dynptr ptr; ··· 534 534 } 535 535 536 536 /* Can't release a dynptr twice */ 537 - SEC("?raw_tp/sys_nanosleep") 537 + SEC("?raw_tp") 538 538 int release_twice(void *ctx) 539 539 { 540 540 struct bpf_dynptr ptr; ··· 560 560 /* Test that releasing a dynptr twice, where one of the releases happens 561 561 * within a calback function, fails 562 562 */ 563 - SEC("?raw_tp/sys_nanosleep") 563 + SEC("?raw_tp") 564 564 int release_twice_callback(void *ctx) 565 565 { 566 566 struct bpf_dynptr ptr; ··· 575 575 } 576 576 577 577 /* Reject unsupported local mem types for dynptr_from_mem API */ 578 - SEC("?raw_tp/sys_nanosleep") 578 + SEC("?raw_tp") 579 579 int dynptr_from_mem_invalid_api(void *ctx) 580 580 { 581 581 struct bpf_dynptr ptr;
+2 -2
tools/testing/selftests/bpf/progs/test_bpf_cookie.c
··· 28 28 *res |= bpf_get_attach_cookie(ctx); 29 29 } 30 30 31 - SEC("kprobe/sys_nanosleep") 31 + SEC("kprobe") 32 32 int handle_kprobe(struct pt_regs *ctx) 33 33 { 34 34 update(ctx, &kprobe_res); 35 35 return 0; 36 36 } 37 37 38 - SEC("kretprobe/sys_nanosleep") 38 + SEC("kretprobe") 39 39 int handle_kretprobe(struct pt_regs *ctx) 40 40 { 41 41 update(ctx, &kretprobe_res);
+2 -2
tools/testing/selftests/bpf/progs/test_helper_restricted.c
··· 72 72 return 0; 73 73 } 74 74 75 - SEC("?kprobe/sys_nanosleep") 75 + SEC("?kprobe") 76 76 int kprobe_timer(void *ctx) 77 77 { 78 78 timer_work(); ··· 104 104 return 0; 105 105 } 106 106 107 - SEC("?kprobe/sys_nanosleep") 107 + SEC("?kprobe") 108 108 int kprobe_spin_lock(void *ctx) 109 109 { 110 110 spin_lock_work();