Skip to contentSkip to conversation

selftests: Skip SUD tests when unsupported

PATCH RESEND New Christian Loehle 1 participant 4 messages Oct 13 Kselftest

lore
Share & tools
lore
#0 lore raw

cover selftests: Skip SUD tests when unsupported

Hi Shuah,
the series is a resend which has picked up all the relevant tags and is ready to apply!
--

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.

Original posting:
https://lore.kernel.org/lkml/[email protected]/

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: 24a19b953e2a3d0ea5a8c4951a0ab8f32720c907

Signature · 1 line
2.34.1
#1 lore raw

PATCH RESEND 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.

Fixes 8c8fa605f7b8 ("selftest, ptrace: Add selftest for syscall user dispatch config api")
---
 tools/testing/selftests/ptrace/get_set_sud.c | 8 ++++++++
 1 file changed, 8 insertions(+)
tools/testing/selftests/ptrace/get_set_sud.c +8 -0
index 2e619c7599bb..395674f85964 100644
@@ -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
#2 lore raw

PATCH RESEND 2/3 selftests/syscall_user_dispatch: Skip tests if SUD is unsupported

In reply to Christian Loehle

Syscall 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.

Fixes 179ef035992e ("selftests: Add kselftest for syscall user dispatch")
---
 .../syscall_user_dispatch/sud_test.c          | 36 +++++++++++++++++++
 1 file changed, 36 insertions(+)
tools/testing/selftests/syscall_user_dispatch/sud_test.c +36 -0
index b855c6000287..1c84b86e24ba 100644
@@ -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
#3 lore raw

PATCH RESEND 3/3 selftests/syscall_user_dispatch: Skip benchmark if SUD is unsupported

In reply to Christian Loehle

Syscall 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.

Fixes d87ae0fa21c2 ("selftests: Add benchmark for syscall user dispatch")
---
 .../selftests/syscall_user_dispatch/sud_benchmark.c      | 9 +++++++++
 1 file changed, 9 insertions(+)
tools/testing/selftests/syscall_user_dispatch/sud_benchmark.c +9 -0
index 073a03702ff5..bb05fece301a 100644
@@ -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