Re: [PATCH] syscall02: add invalid syscall number test

Petr Vorel <[email protected]>
Newsgroups gmane.linux.ltp
Message-ID <20260630102026.GB417625@pevik>
Hi Andrea, Wei,

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

Reviewed-by: Petr Vorel <[email protected]>

...
> > +++ b/testcases/kernel/syscalls/syscall/syscall02.c
> > @@ -0,0 +1,47 @@
> > +// SPDX-License-Identifier: GPL-2.0-or-later
> > +/*
> > + * Copyright (c) 2026 Andrea Cervesato <andrea.cervesato-IBi9RG/[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[] = {
> > +	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)

+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)

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.