syscall02: add invalid syscall number test
PATCH 1/1 syscall02: add invalid syscall number test
From: Andrea Cervesato <[email protected]>
Add a test verifying that syscall() returns ENOSYS when called with unimplemented syscall numbers. The chosen numbers stay above the syscall table and below the architecture-specific private ranges, so they are reliably invalid on every supported architecture.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/syscall/.gitignore | 1 + testcases/kernel/syscalls/syscall/syscall02.c | 47 +++++++++++++++++++++++++++ 3 files changed, 49 insertions(+)
runtest/syscalls +1 -0
@@ -1678,6 +1678,7 @@ sync_file_range01 sync_file_range01 sync_file_range02 sync_file_range02 syscall01 syscall01 +syscall02 syscall02 sysconf01 sysconf01
testcases/kernel/syscalls/syscall/.gitignore +1 -0
@@ -1 +1,2 @@ /syscall01 +/syscall02
testcases/kernel/syscalls/syscall/syscall02.c new file +47 -0
47 lines not on this page · raw message
---
base-commit: ad68429b9cfd55b233733e45e600ffafa1458ac5
change-id: 20260629-invalid_syscalls-0476c52d7d0c
Best regards,
Signature · 5 lines
Andrea Cervesato <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Andrea,
Quoted 1 line · Andrea Cervesato
syscall02: add invalid syscall number test
Verdict - Reviewed
---
Note:
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 64 lines · Andrea Cervesato
From: Andrea Cervesato <[email protected]>
Add a test verifying that
syscall()returns ENOSYS when called with unimplemented syscall numbers. The chosen numbers stay above the syscall table and below the architecture-specific private ranges, so they are reliably invalid on every supported architecture.Signed-off-by Andrea Cervesato <[email protected]>--- runtest/syscalls | 1 + testcases/kernel/syscalls/syscall/.gitignore | 1 + testcases/kernel/syscalls/syscall/syscall02.c | 47 +++++++++++++++++++++++++++ 3 files changed, 49 insertions(+)runtest/syscalls +1
-0@@ -1678,6 +1678,7 @@ sync_file_range01 sync_file_range01 sync_file_range02 sync_file_range02 syscall01 syscall01 +syscall02 syscall02 sysconf01 sysconf01testcases/kernel/syscalls/syscall/.gitignore +1
-0@@ -1 +1,2 @@ /syscall01 +/syscall02testcases/kernel/syscalls/syscall/syscall02.c new file +25
-0@@ -0,0 +1,47 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2026 Andrea Cervesato <[email protected]> +*/ + +/*\ +* Verify that :manpage:`syscall(2)` fails with ENOSYS when invoked with +* invalid syscall numbers. +* +* The syscall number is dispatched as an unsigned value on Linux. A value is +* reliably unimplemented on every supported architecture when it is: +* +* - above the syscall table +* - below the architecture-specific private syscall ranges (e.g. ARM's +* 0x0f0000 base) +* - without the x32 ABI bit (0x40000000) set +* +* Such a number is routed to sys_ni_syscall and returns ENOSYS. +*/ + +#include <unistd.h> +#include <sys/syscall.h> + +#include "tst_test.h" +
testcases/kernel/syscalls/syscall/syscall02.c line 35
Quoted 10 lines
testcases/kernel/syscalls/syscall/syscall02.c new file +10
-0+#define TC (x) {.scno = (long)(x), .desc = #x} + +static struct tcase { +long scno; +const char *desc; +} tcases[] = { +TC (0x8000 ), +TC (0xf000 ), +TC (0xfffe ), +};
I suggest add two more cases check:
1) -1
2) __NR_syscalls +1 (Base arch/powerpc/kernel/syscall.c)
Quoted 24 lines
testcases/kernel/syscalls/syscall/syscall02.c new file +12
-1+ +static void verify_syscall (unsigned int n) +{ +struct tcase *tc = &tcases[n]; + +TST_EXP_FAIL2 (syscall (tc->scno),ENOSYS ,"syscall(%s)" , tc->desc); +} + +static struct tst_test test = { + .test = verify_syscall, + .tcnt =ARRAY_SIZE (tcases), +}; ---base-commit:
ad68429b9cfd55b233733e45e600ffafa1458ac5
change-id: 20260629-invalid_syscalls-0476c52d7d0cBest regards,
Signature · 5 lines
Andrea Cervesato <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Petr Vorel
Reviewed-byHi Andrea, Wei,
Quoted 4 lines
Quoted 4 lines
Add a test verifying that
syscall()returns ENOSYS when called with unimplemented syscall numbers. The chosen numbers stay above the syscall table and below the architecture-specific private ranges, so they are reliably invalid on every supported architecture.
+1
...
Quoted 33 lines
Quoted 33 lines
+++
b/testcases/kernel/syscalls/syscall/syscall02.ctestcases/kernel/syscalls/syscall/syscall02.c new file +31
-0@@ -0,0 +1,47 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2026 Andrea Cervesato <[email protected]> +*/ + +/*\ +* Verify that :manpage:`syscall(2)` fails with ENOSYS when invoked with +* invalid syscall numbers. +* +* The syscall number is dispatched as an unsigned value on Linux. A value is +* reliably unimplemented on every supported architecture when it is: +* +* - above the syscall table +* - below the architecture-specific private syscall ranges (e.g. ARM's +* 0x0f0000 base) +* - without the x32 ABI bit (0x40000000) set +* +* Such a number is routed to sys_ni_syscall and returns ENOSYS. +*/ + +#include <unistd.h> +#include <sys/syscall.h> + +#include "tst_test.h" + +#define TC (x) {.scno = (long)(x), .desc = #x} + +static struct tcase { +long scno; +const char *desc; +} tcases[] = {
Quoted 8 lines
testcases/kernel/syscalls/syscall/syscall02.c line 35
Quoted 4 lines
testcases/kernel/syscalls/syscall/syscall02.c new file +4
-0+TC (0x8000 ), +TC (0xf000 ), + TC(0xfffe), +};I suggest add two more cases check:
1) -1
2)__NR_syscalls+1 (Basearch/powerpc/kernel/syscall.c)
+1. Something like this wouldn't harm (tested only on x86_64 and x86).
Kind regards,
Petr
+++ testcases/kernel/syscalls/syscall/syscall02.c
@@ -14,12 +14,15 @@
* - below the architecture-specific private syscall ranges (e.g. ARM's
* 0x0f0000 base)
* - without the x32 ABI bit (0x40000000) set
+ * - -1
+ * - __NR_syscalls + 1
*
* Such a number is routed to sys_ni_syscall and returns ENOSYS. */
#include <unistd.h>
#include <sys/syscall.h>
+#include <asm-generic/unistd.h>
#include "tst_test.h"
@@ -32,6 +35,8 @@ static struct tcase {
TC(0x8000),
TC(0xf000),
TC(0xfffe),
+ TC(-1),
+ TC(__NR_syscalls + 1),
};
static void verify_syscall(unsigned int n)
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Petr,
Quoted 4 lines
Quoted 3 lines
I suggest add two more cases check:
1) -1
2)__NR_syscalls+1 (Basearch/powerpc/kernel/syscall.c)
that was my initial idea, but different architectures are starting from a different value and I wanted to make it generic. I guess the right way would be to include syscalls.h and use __LTP__NR_INVALID_SYSCALL at this point. WDYT?
Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Andrea,
Quoted 11 lines
Hi Petr,
Quoted 3 lines
Quoted 3 lines
I suggest add two more cases check:
1) -1
2)__NR_syscalls+1 (Basearch/powerpc/kernel/syscall.c)that was my initial idea, but different architectures are starting from a different value and I wanted to make it generic. I guess the right way would be to include
syscalls.hand use__LTP__NR_INVALID_SYSCALLat this point. WDYT?
Yes, __LTP__NR_INVALID_SYSCALL is better than -1 (for all archs we have #define __LTP__NR_INVALID_SYSCALL -1)
But I'd also use __NR_syscalls from <asm-generic/unistd.h> (the second suggested case), i.e. have arch dependent value based on UAPI headers.
Also, you could add a real description to the values to .desc.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp