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

selftests/bpf: fexit_sleep: Fix stack allocation for arm64

On ARM64 the stack pointer should be aligned at a 16 byte boundary or
the SPAlignmentFault can occur. The fexit_sleep selftest allocates the
stack for the child process as a character array, this is not guaranteed
to be aligned at 16 bytes.

Because of the SPAlignmentFault, the child process is killed before it
can do the nanosleep call and hence fentry_cnt remains as 0. This causes
the main thread to hang on the following line:

while (READ_ONCE(fexit_skel->bss->fentry_cnt) != 2);

Fix this by allocating the stack using mmap() as described in the
example in the man page of clone().

Remove the fexit_sleep test from the DENYLIST of arm64.

Fixes: eddbe8e65214 ("selftest/bpf: Add a test to check trampoline freeing logic.")
Signed-off-by: Puranjay Mohan <puranjay@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20240715173327.8657-1-puranjay@kernel.org

authored by

Puranjay Mohan and committed by
Daniel Borkmann
e1ef78dc 0e03c643

+7 -2
-1
tools/testing/selftests/bpf/DENYLIST.aarch64
··· 1 1 bpf_cookie/multi_kprobe_attach_api # kprobe_multi_link_api_subtest:FAIL:fentry_raw_skel_load unexpected error: -3 2 2 bpf_cookie/multi_kprobe_link_api # kprobe_multi_link_api_subtest:FAIL:fentry_raw_skel_load unexpected error: -3 3 - fexit_sleep # The test never returns. The remaining tests cannot start. 4 3 kprobe_multi_bench_attach # needs CONFIG_FPROBE 5 4 kprobe_multi_test # needs CONFIG_FPROBE 6 5 module_attach # prog 'kprobe_multi': failed to auto-attach: -95
+7 -1
tools/testing/selftests/bpf/prog_tests/fexit_sleep.c
··· 21 21 } 22 22 23 23 #define STACK_SIZE (1024 * 1024) 24 - static char child_stack[STACK_SIZE]; 25 24 26 25 void test_fexit_sleep(void) 27 26 { 28 27 struct fexit_sleep_lskel *fexit_skel = NULL; 29 28 int wstatus, duration = 0; 30 29 pid_t cpid; 30 + char *child_stack = NULL; 31 31 int err, fexit_cnt; 32 32 33 33 fexit_skel = fexit_sleep_lskel__open_and_load(); ··· 36 36 37 37 err = fexit_sleep_lskel__attach(fexit_skel); 38 38 if (CHECK(err, "fexit_attach", "fexit attach failed: %d\n", err)) 39 + goto cleanup; 40 + 41 + child_stack = mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | 42 + MAP_ANONYMOUS | MAP_STACK, -1, 0); 43 + if (!ASSERT_NEQ(child_stack, MAP_FAILED, "mmap")) 39 44 goto cleanup; 40 45 41 46 cpid = clone(do_sleep, child_stack + STACK_SIZE, CLONE_FILES | SIGCHLD, fexit_skel); ··· 83 78 goto cleanup; 84 79 85 80 cleanup: 81 + munmap(child_stack, STACK_SIZE); 86 82 fexit_sleep_lskel__destroy(fexit_skel); 87 83 }