The test_lsm/lsm_basic test contains a test attaching to a sleepable fentry, which doesn't logically fit into the LSM test suite. In addition, it makes the entire test fail on kernels which do not support sleepable fentry programs. Factor out the sleepable fentry part into a new test fentry_sleepable. Signed-off-by: Viktor Malik --- .../bpf/prog_tests/fentry_sleepable.c | 28 +++++++++++++++++++ .../selftests/bpf/prog_tests/test_lsm.c | 8 ------ .../selftests/bpf/progs/fentry_sleepable.c | 28 +++++++++++++++++++ tools/testing/selftests/bpf/progs/lsm.c | 21 -------------- 4 files changed, 56 insertions(+), 29 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/fentry_sleepable.c create mode 100644 tools/testing/selftests/bpf/progs/fentry_sleepable.c diff --git a/tools/testing/selftests/bpf/prog_tests/fentry_sleepable.c b/tools/testing/selftests/bpf/prog_tests/fentry_sleepable.c new file mode 100644 index 000000000000..efe3ea616575 --- /dev/null +++ b/tools/testing/selftests/bpf/prog_tests/fentry_sleepable.c @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include "fentry_sleepable.skel.h" + +void test_fentry_sleepable(void) +{ + struct fentry_sleepable *skel; + int buf = 1234; + int err; + + skel = fentry_sleepable__open_and_load(); + if (!ASSERT_OK_PTR(skel, "fentry_sleepable__open_and_load")) + return; + + err = fentry_sleepable__attach(skel); + if (!ASSERT_OK(err, "fentry_sleepable__attach")) + goto cleanup; + + syscall(__NR_setdomainname, &buf, -2L); + syscall(__NR_setdomainname, 0, -3L); + syscall(__NR_setdomainname, ~0L, -4L); + + ASSERT_EQ(skel->bss->copy_test, 3, "copy_test"); + +cleanup: + fentry_sleepable__destroy(skel); +} diff --git a/tools/testing/selftests/bpf/prog_tests/test_lsm.c b/tools/testing/selftests/bpf/prog_tests/test_lsm.c index bdc4fc06bc5a..67c7c437574a 100644 --- a/tools/testing/selftests/bpf/prog_tests/test_lsm.c +++ b/tools/testing/selftests/bpf/prog_tests/test_lsm.c @@ -55,7 +55,6 @@ int exec_cmd(int *monitored_pid) static int test_lsm(struct lsm *skel) { struct bpf_link *link; - int buf = 1234; int err; err = lsm__attach(skel); @@ -82,15 +81,8 @@ static int test_lsm(struct lsm *skel) ASSERT_EQ(skel->bss->mprotect_count, 1, "mprotect_count"); - syscall(__NR_setdomainname, &buf, -2L); - syscall(__NR_setdomainname, 0, -3L); - syscall(__NR_setdomainname, ~0L, -4L); - - ASSERT_EQ(skel->bss->copy_test, 3, "copy_test"); - lsm__detach(skel); - skel->bss->copy_test = 0; skel->bss->bprm_count = 0; skel->bss->mprotect_count = 0; return 0; diff --git a/tools/testing/selftests/bpf/progs/fentry_sleepable.c b/tools/testing/selftests/bpf/progs/fentry_sleepable.c new file mode 100644 index 000000000000..621548b97564 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/fentry_sleepable.c @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "vmlinux.h" +#include +#include +#include +#include "bpf_misc.h" + +char _license[] SEC("license") = "GPL"; + +int copy_test = 0; + +SEC("fentry.s/" SYS_PREFIX "sys_setdomainname") +int BPF_PROG(test_sys_setdomainname, struct pt_regs *regs) +{ + void *ptr = (void *)PT_REGS_PARM1_SYSCALL(regs); + int len = PT_REGS_PARM2_SYSCALL(regs); + int buf = 0; + long ret; + + ret = bpf_copy_from_user(&buf, sizeof(buf), ptr); + if (len == -2 && ret == 0 && buf == 1234) + copy_test++; + if (len == -3 && ret == -EFAULT) + copy_test++; + if (len == -4 && ret == -EFAULT) + copy_test++; + return 0; +} diff --git a/tools/testing/selftests/bpf/progs/lsm.c b/tools/testing/selftests/bpf/progs/lsm.c index 7de173daf27b..dd5d41903a26 100644 --- a/tools/testing/selftests/bpf/progs/lsm.c +++ b/tools/testing/selftests/bpf/progs/lsm.c @@ -9,7 +9,6 @@ #include #include #include -#include "bpf_misc.h" struct { __uint(type, BPF_MAP_TYPE_ARRAY); @@ -161,23 +160,3 @@ int BPF_PROG(test_task_free, struct task_struct *task) { return 0; } - -int copy_test = 0; - -SEC("fentry.s/" SYS_PREFIX "sys_setdomainname") -int BPF_PROG(test_sys_setdomainname, struct pt_regs *regs) -{ - void *ptr = (void *)PT_REGS_PARM1_SYSCALL(regs); - int len = PT_REGS_PARM2_SYSCALL(regs); - int buf = 0; - long ret; - - ret = bpf_copy_from_user(&buf, sizeof(buf), ptr); - if (len == -2 && ret == 0 && buf == 1234) - copy_test++; - if (len == -3 && ret == -EFAULT) - copy_test++; - if (len == -4 && ret == -EFAULT) - copy_test++; - return 0; -} -- 2.53.0