selftests: Skip SUD tests when unsupported
cover selftests: Skip SUD tests when unsupported
Syscall User Dispatch (SUD) is unavailable on architectures without generic syscall entry. Such architectures return -EINVAL for otherwise valid SUD prctl and ptrace requests, which the SUD selftests currently report as failures.
Probe SUD with a valid disabled configuration and skip the affected tests when that probe returns EINVAL. Unexpected errors remain failures, and the existing coverage is unchanged on kernels that support SUD.
Christian Loehle (3):
selftests/ptrace: Skip get_set_sud if SUD is unsupported selftests/syscall_user_dispatch: Skip tests if SUD is unsupported selftests/syscall_user_dispatch: Skip benchmark if SUD is unsupported
tools/testing/selftests/ptrace/get_set_sud.c | 8 +++++ .../syscall_user_dispatch/sud_benchmark.c | 9 +++++ .../syscall_user_dispatch/sud_test.c | 36 +++++++++++++++++++ 3 files changed, 53 insertions(+)
base-commit: 8d3ae59288f1e7d58d76558a6ee96d533bc5019f
Signature · 1 line
2.34.1
PATCH 1/3 selftests/ptrace: Skip get_set_sud if SUD is unsupported
Syscall User Dispatch is unavailable on architectures without generic syscall entry. Such architectures return -EINVAL for otherwise valid SUD ptrace requests.
The test currently treats this as a failure even though the feature is not supported. Probe SUD with a valid disabled configuration before creating the tracee and skip the test when the kernel returns EINVAL. Other errors remain test failures, and kernels that support SUD continue to exercise the ptrace GET/SET requests.
--- tools/testing/selftests/ptrace/get_set_sud.c | 8 ++++++++ 1 file changed, 8 insertions(+)
tools/testing/selftests/ptrace/get_set_sud.c +8 -0
@@ -22,6 +22,14 @@ TEST(get_set_sud)int ret =0 ;int status; + ret =prctl (PR_SET_SYSCALL_USER_DISPATCH ,PR_SYS_DISPATCH_OFF , +0UL ,0UL ,0UL ); +if (ret ==-1 && errno ==EINVAL ) +SKIP (return,"Syscall User Dispatch is not supported" ); + ASSERT_EQ(0, ret) { +TH_LOG ("PR_SET_SYSCALL_USER_DISPATCH: %m" ); + } + child =fork ();ASSERT_GE (child,0 );if (child ==0 ) {
Signature · 1 line
2.34.1
Re: [PATCH 1/3] selftests/ptrace: Skip get_set_sud if SUD is unsupported
Quoted 10 lines · Christian Loehle
Syscall User Dispatch is unavailable on architectures without generic syscall entry. Such architectures return
-EINVALfor otherwise valid SUD ptrace requests.The test currently treats this as a failure even though the feature is not supported. Probe SUD with a valid disabled configuration before creating the tracee and skip the test when the kernel returns EINVAL. Other errors remain test failures, and kernels that support SUD continue to exercise the ptrace GET/SET requests.
Quoted 3 lines
Fixes 8c8fa605f7b8 ("selftest, ptrace: Add selftest for syscall user dispatch config api")Reported-by Rama Krishna Katta <[email protected]>Signed-off-by Christian Loehle <[email protected]>
Quoted 26 lines
--- tools/testing/selftests/ptrace/get_set_sud.c | 8 ++++++++ 1 file changed, 8 insertions(+)tools/testing/selftests/ptrace/get_set_sud.c +8
-0@@ -22,6 +22,14 @@ TEST(get_set_sud)int ret =0 ;int status; + ret =prctl (PR_SET_SYSCALL_USER_DISPATCH ,PR_SYS_DISPATCH_OFF , +0UL ,0UL ,0UL ); +if (ret ==-1 && errno ==EINVAL ) +SKIP (return,"Syscall User Dispatch is not supported" ); + ASSERT_EQ(0, ret) { +TH_LOG ("PR_SET_SYSCALL_USER_DISPATCH: %m" ); + } + child =fork ();ASSERT_GE (child,0 );if (child ==0 ) {Signature · 1 line
2.34.1
PATCH 2/3 selftests/syscall_user_dispatch: Skip tests if SUD is unsupported
In reply to Christian LoehleSyscall User Dispatch is unavailable on architectures without generic syscall entry. Such architectures return -EINVAL for otherwise valid SUD prctl requests, causing sud_test to report failures.
This also prevents bad_prctl_param from providing useful coverage. The unsupported stub returns EINVAL before argument validation, so valid operations fail and requests expected to fail with EFAULT return EINVAL.
Probe SUD with a valid disabled configuration at the start of each test and skip when the kernel returns EINVAL. Preserve failures for unexpected errors and continue to run the full test on supported kernels.
--- .../syscall_user_dispatch/sud_test.c | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+)
tools/testing/selftests/syscall_user_dispatch/sud_test.c +36 -0
@@ -41,6 +41,21 @@#define SYSCALL_DISPATCH_ON (x) ((x) = SYSCALL_DISPATCH_FILTER_BLOCK)#define SYSCALL_DISPATCH_OFF (x) ((x) = SYSCALL_DISPATCH_FILTER_ALLOW) +static bool require_sud (struct __test_metadata *_metadata) +{ +int ret; + + ret =prctl (PR_SET_SYSCALL_USER_DISPATCH ,PR_SYS_DISPATCH_OFF , +0UL ,0UL ,0UL ); +if (ret ==-1 && errno ==EINVAL ) + SKIP(return false, "Syscall User Dispatch is not supported"); + ASSERT_EQ(0, ret) { +TH_LOG ("PR_SET_SYSCALL_USER_DISPATCH: %m" ); + } + +return true; +} +/* Test Summary: * * - dispatch_trigger_sigsys: Verify if PR_SET_SYSCALL_USER_DISPATCH is
@@ -68,6 +83,9 @@ TEST_SIGNAL(dispatch_trigger_sigsys, SIGSYS)struct sysinfo info;int ret; +if (!require_sud (_metadata)) +return ; + ret =sysinfo (&info);ASSERT_EQ (0 , ret);
@@ -105,6 +123,9 @@ TEST(bad_prctl_param)char sel =SYSCALL_DISPATCH_FILTER_ALLOW ;int op; +if (!require_sud (_metadata)) +return ; +/* Invalid op */ op =-1 ;prctl_invalid (_metadata, op,0 ,0 , &sel,EINVAL );
@@ -211,6 +232,9 @@ TEST(dispatch_and_return) {long ret; +if (!require_sud (_metadata)) +return ; + glob_sel =0 ; nr_syscalls_emulated =0 ; si_code =0 ;
@@ -259,6 +283,9 @@ TEST_SIGNAL(bad_selector, SIGSYS)sigset_t mask;struct sysinfo info; +if (!require_sud (_metadata)) +return ; + glob_sel =SYSCALL_DISPATCH_FILTER_ALLOW ; nr_syscalls_emulated =0 ; si_code =0 ;
@@ -301,6 +328,9 @@ TEST(disable_dispatch)struct sysinfo info;char sel =0 ; +if (!require_sud (_metadata)) +return ; + ret =prctl (PR_SET_SYSCALL_USER_DISPATCH ,PR_SYS_DISPATCH_EXCLUSIVE_ON ,0 ,0 , &sel); ASSERT_EQ(0, ret) {TH_LOG ("Kernel does not support CONFIG_SYSCALL_USER_DISPATCH" );
@@ -329,6 +359,9 @@ TEST(direct_dispatch_range)struct sysinfo info;char sel =SYSCALL_DISPATCH_FILTER_ALLOW ; +if (!require_sud (_metadata)) +return ; +/* * Instead of calculating libc addresses; allow the entire * memory map and lock the selector.
@@ -365,6 +398,9 @@ static void test_range(struct __test_metadata *_metadata,TEST (dispatch_range) { +if (!require_sud (_metadata)) +return ; +ASSERT_EQ (0 ,setup_sigsys_handler ());test_range (_metadata,PR_SYS_DISPATCH_EXCLUSIVE_ON ,0 ,0 , true);test_range (_metadata,PR_SYS_DISPATCH_EXCLUSIVE_ON , syscall_addr,1 , false);
Signature · 1 line
2.34.1
Re: [PATCH 2/3] selftests/syscall_user_dispatch: Skip tests if SUD is unsupported
Quoted 4 lines · Christian Loehle
Syscall User Dispatch is unavailable on architectures without generic syscall entry. Such architectures return
-EINVALfor otherwise valid SUD prctl requests, causingsud_testto report failures.
Quoted 8 lines
This also prevents
bad_prctl_paramfrom providing useful coverage. The unsupported stub returns EINVAL before argument validation, so valid operations fail and requests expected to fail with EFAULT return EINVAL.Probe SUD with a valid disabled configuration at the start of each test and skip when the kernel returns EINVAL. Preserve failures for unexpected errors and continue to run the full test on supported kernels.
I suppose we should at least be testing for the EINVAL when not supported, so this makes sense vs skipping the entire suite.
Quoted 2 lines
Fixes 179ef035992e ("selftests: Add kselftest for syscall user dispatch")Signed-off-by Christian Loehle <[email protected]>
PATCH 3/3 selftests/syscall_user_dispatch: Skip benchmark if SUD is unsupported
In reply to Christian LoehleSyscall User Dispatch is unavailable on architectures without generic syscall entry. On such architectures, sud_benchmark spends several seconds calibrating before its SUD prctl fails with EINVAL.
Probe SUD with a valid disabled configuration before calibration and skip when the kernel returns EINVAL. Treat other probe errors as failures and continue to run the benchmark unchanged on supported kernels.
--- .../selftests/syscall_user_dispatch/sud_benchmark.c | 9 +++++++++ 1 file changed, 9 insertions(+)
tools/testing/selftests/syscall_user_dispatch/sud_benchmark.c +9 -0
@@ -18,6 +18,8 @@#include <sys/prctl.h> #include <sys/syscall.h> +#include "kselftest.h" +#ifndef PR_SET_SYSCALL_USER_DISPATCH # define PR_SET_SYSCALL_USER_DISPATCH 59# define PR_SYS_DISPATCH_OFF 0
@@ -140,6 +142,13 @@ int main(void)int ret;sigset_t mask; + ret =prctl (PR_SET_SYSCALL_USER_DISPATCH ,PR_SYS_DISPATCH_OFF , +0UL ,0UL ,0UL ); +if (ret ==-1 && errno ==EINVAL ) +ksft_exit_skip ("Syscall User Dispatch is not supported\n" ); +if (ret) +ksft_exit_fail_perror ("PR_SET_SYSCALL_USER_DISPATCH" ); +memset (&act,0 ,sizeof (act));sigemptyset (&mask);
Signature · 1 line
2.34.1
Re: [PATCH 3/3] selftests/syscall_user_dispatch: Skip benchmark if SUD is unsupported
Quoted 10 lines · Christian Loehle
Syscall User Dispatch is unavailable on architectures without generic syscall entry. On such architectures,
sud_benchmarkspends several seconds calibrating before its SUD prctl fails with EINVAL.Probe SUD with a valid disabled configuration before calibration and skip when the kernel returns EINVAL. Treat other probe errors as failures and continue to run the benchmark unchanged on supported kernels.
Fixes d87ae0fa21c2 ("selftests: Add benchmark for syscall user dispatch")Signed-off-by Christian Loehle <[email protected]>
Quoted 14 lines · Christian Loehle
Syscall User Dispatch (SUD) is unavailable on architectures without generic syscall entry. Such architectures return
-EINVALfor otherwise valid SUD prctl and ptrace requests, which the SUD selftests currently report as failures.Probe SUD with a valid disabled configuration and skip the affected tests when that probe returns EINVAL. Unexpected errors remain failures, and the existing coverage is unchanged on kernels that support SUD.
Christian Loehle (3):
selftests/ptrace: Skipget_set_sudif SUD is unsupported selftests/syscall_user_dispatch: Skip tests if SUD is unsupported selftests/syscall_user_dispatch: Skip benchmark if SUD is unsupported
Quoted 7 lines
tools/testing/selftests/ptrace/get_set_sud.c | 8 +++++ .../syscall_user_dispatch/sud_benchmark.c | 9 +++++ .../syscall_user_dispatch/sud_test.c | 36 +++++++++++++++++++ 3 files changed, 53 insertions(+)base-commit:
8d3ae59288f1e7d58d76558a6ee96d533bc5019f
Gentle ping on this
Quoted 21 lines · Christian Loehle
Quoted 20 lines · Christian Loehle
Syscall User Dispatch (SUD) is unavailable on architectures without generic syscall entry. Such architectures return
-EINVALfor otherwise valid SUD prctl and ptrace requests, which the SUD selftests currently report as failures.Probe SUD with a valid disabled configuration and skip the affected tests when that probe returns EINVAL. Unexpected errors remain failures, and the existing coverage is unchanged on kernels that support SUD.
Christian Loehle (3):
selftests/ptrace: Skipget_set_sudif SUD is unsupported selftests/syscall_user_dispatch: Skip tests if SUD is unsupported selftests/syscall_user_dispatch: Skip benchmark if SUD is unsupportedtools/testing/selftests/ptrace/get_set_sud.c | 8 +++++ .../syscall_user_dispatch/sud_benchmark.c | 9 +++++ .../syscall_user_dispatch/sud_test.c | 36 +++++++++++++++++++ 3 files changed, 53 insertions(+)
Quoted 3 lines
Quoted 1 line
base-commit:
8d3ae59288f1e7d58d76558a6ee96d533bc5019fGentle ping on this
Another gentle ping, this should have all the reviews to land, right?
Quoted 22 lines · Christian Loehle
Quoted 21 lines · Christian Loehle
Quoted 20 lines · Christian Loehle
Syscall User Dispatch (SUD) is unavailable on architectures without generic syscall entry. Such architectures return
-EINVALfor otherwise valid SUD prctl and ptrace requests, which the SUD selftests currently report as failures.Probe SUD with a valid disabled configuration and skip the affected tests when that probe returns EINVAL. Unexpected errors remain failures, and the existing coverage is unchanged on kernels that support SUD.
Christian Loehle (3):
selftests/ptrace: Skipget_set_sudif SUD is unsupported selftests/syscall_user_dispatch: Skip tests if SUD is unsupported selftests/syscall_user_dispatch: Skip benchmark if SUD is unsupportedtools/testing/selftests/ptrace/get_set_sud.c | 8 +++++ .../syscall_user_dispatch/sud_benchmark.c | 9 +++++ .../syscall_user_dispatch/sud_test.c | 36 +++++++++++++++++++ 3 files changed, 53 insertions(+)
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
base-commit:
8d3ae59288f1e7d58d76558a6ee96d533bc5019fGentle ping on this
Another gentle ping, this should have all the reviews to land, right?
Shuah, Thomas,
Either of you mind picking this up in either kselftest or core/entry?
Thanks!
Christian
Quoted 8 lines · Christian Loehle
Syscall User Dispatch (SUD) is unavailable on architectures without generic syscall entry. Such architectures return
-EINVALfor otherwise valid SUD prctl and ptrace requests, which the SUD selftests currently report as failures.Probe SUD with a valid disabled configuration and skip the affected tests when that probe returns EINVAL. Unexpected errors remain failures, and the existing coverage is unchanged on kernels that support SUD.
Signature · 1 line
Gabriel Krisman Bertazi