* [LTP] [PATCH] getcpu: Add testcase for EFAULT
@ 2024-07-17 2:27 Ma Xinjian via ltp
2024-07-17 14:01 ` Cyril Hrubis
0 siblings, 1 reply; 6+ messages in thread
From: Ma Xinjian via ltp @ 2024-07-17 2:27 UTC (permalink / raw)
To: ltp
Add a testcase with the arguments point to an invalid address.
Signed-off-by: Ma Xinjian <maxj.fnst@fujitsu.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/getcpu/.gitignore | 1 +
testcases/kernel/syscalls/getcpu/getcpu02.c | 31 +++++++++++++++++++++
3 files changed, 33 insertions(+)
create mode 100644 testcases/kernel/syscalls/getcpu/getcpu02.c
diff --git a/runtest/syscalls b/runtest/syscalls
index 136fd03fa..31922bc9f 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -440,6 +440,7 @@ futimesat01 futimesat01
getcontext01 getcontext01
getcpu01 getcpu01
+getcpu02 getcpu02
getcwd01 getcwd01
getcwd02 getcwd02
diff --git a/testcases/kernel/syscalls/getcpu/.gitignore b/testcases/kernel/syscalls/getcpu/.gitignore
index 31fec5d35..cd3022bbb 100644
--- a/testcases/kernel/syscalls/getcpu/.gitignore
+++ b/testcases/kernel/syscalls/getcpu/.gitignore
@@ -1 +1,2 @@
/getcpu01
+/getcpu02
diff --git a/testcases/kernel/syscalls/getcpu/getcpu02.c b/testcases/kernel/syscalls/getcpu/getcpu02.c
new file mode 100644
index 000000000..0857a0598
--- /dev/null
+++ b/testcases/kernel/syscalls/getcpu/getcpu02.c
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2024 FUJITSU LIMITED. All Rights Reserved.
+ * Copyright (c) Linux Test Project, 2024
+ * Author: Ma Xinjian <maxj.fnst@fujitsu.com>
+ *
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that getcpu(2) fails with
+ *
+ * - EFAULT arguments point outside the calling process's address
+ * space.
+ */
+
+#define _GNU_SOURCE
+#include "tst_test.h"
+#include "lapi/sched.h"
+
+static void run(void) {
+ unsigned int cpu_id, node_id = 0;
+
+ TST_EXP_FAIL(getcpu(tst_get_bad_addr(NULL), &node_id), EFAULT);
+ TST_EXP_FAIL(getcpu(&cpu_id, tst_get_bad_addr(NULL)), EFAULT);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+};
--
2.18.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [LTP] [PATCH] getcpu: Add testcase for EFAULT
2024-07-17 2:27 [LTP] [PATCH] getcpu: Add testcase for EFAULT Ma Xinjian via ltp
@ 2024-07-17 14:01 ` Cyril Hrubis
2024-07-18 6:55 ` [LTP] [PATCH v2] " Ma Xinjian via ltp
0 siblings, 1 reply; 6+ messages in thread
From: Cyril Hrubis @ 2024-07-17 14:01 UTC (permalink / raw)
To: Ma Xinjian; +Cc: ltp
Hi!
Please run make check and fix all the errors.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 6+ messages in thread
* [LTP] [PATCH v2] getcpu: Add testcase for EFAULT
2024-07-17 14:01 ` Cyril Hrubis
@ 2024-07-18 6:55 ` Ma Xinjian via ltp
2024-07-29 22:57 ` Petr Vorel
0 siblings, 1 reply; 6+ messages in thread
From: Ma Xinjian via ltp @ 2024-07-18 6:55 UTC (permalink / raw)
To: ltp
Add a testcase with the arguments point to an invalid address.
Signed-off-by: Ma Xinjian <maxj.fnst@fujitsu.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/getcpu/.gitignore | 1 +
testcases/kernel/syscalls/getcpu/getcpu02.c | 32 +++++++++++++++++++++
3 files changed, 34 insertions(+)
create mode 100644 testcases/kernel/syscalls/getcpu/getcpu02.c
diff --git a/runtest/syscalls b/runtest/syscalls
index 136fd03fa..31922bc9f 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -440,6 +440,7 @@ futimesat01 futimesat01
getcontext01 getcontext01
getcpu01 getcpu01
+getcpu02 getcpu02
getcwd01 getcwd01
getcwd02 getcwd02
diff --git a/testcases/kernel/syscalls/getcpu/.gitignore b/testcases/kernel/syscalls/getcpu/.gitignore
index 31fec5d35..cd3022bbb 100644
--- a/testcases/kernel/syscalls/getcpu/.gitignore
+++ b/testcases/kernel/syscalls/getcpu/.gitignore
@@ -1 +1,2 @@
/getcpu01
+/getcpu02
diff --git a/testcases/kernel/syscalls/getcpu/getcpu02.c b/testcases/kernel/syscalls/getcpu/getcpu02.c
new file mode 100644
index 000000000..81a8dd871
--- /dev/null
+++ b/testcases/kernel/syscalls/getcpu/getcpu02.c
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2024 FUJITSU LIMITED. All Rights Reserved.
+ * Copyright (c) Linux Test Project, 2024
+ * Author: Ma Xinjian <maxj.fnst@fujitsu.com>
+ *
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that getcpu(2) fails with
+ *
+ * - EFAULT arguments point outside the calling process's address
+ * space.
+ */
+
+#define _GNU_SOURCE
+#include "tst_test.h"
+#include "lapi/sched.h"
+
+static void run(void)
+{
+ unsigned int cpu_id, node_id = 0;
+
+ TST_EXP_FAIL(getcpu(tst_get_bad_addr(NULL), &node_id), EFAULT);
+ TST_EXP_FAIL(getcpu(&cpu_id, tst_get_bad_addr(NULL)), EFAULT);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+};
--
2.18.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [LTP] [PATCH v2] getcpu: Add testcase for EFAULT
2024-07-18 6:55 ` [LTP] [PATCH v2] " Ma Xinjian via ltp
@ 2024-07-29 22:57 ` Petr Vorel
2024-08-01 9:06 ` Cyril Hrubis
0 siblings, 1 reply; 6+ messages in thread
From: Petr Vorel @ 2024-07-29 22:57 UTC (permalink / raw)
To: Ma Xinjian; +Cc: ltp
Hi Ma, Cyril,
...
> +static void run(void)
> +{
> + unsigned int cpu_id, node_id = 0;
> +
> + TST_EXP_FAIL(getcpu(tst_get_bad_addr(NULL), &node_id), EFAULT);
I'm not sure why, but I get SIGSEGV due tst_get_bad_addr(NULL) on various
kernels (SLES 5.14.21, Tumbleweed 6.5.1, 6.10, Debian 6.9, ...).
But the test works on SLES 4.4.180.
Kind regards,
Petr
> + TST_EXP_FAIL(getcpu(&cpu_id, tst_get_bad_addr(NULL)), EFAULT);
> +}
> +
> +static struct tst_test test = {
> + .test_all = run,
> +};
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [LTP] [PATCH v2] getcpu: Add testcase for EFAULT
2024-07-29 22:57 ` Petr Vorel
@ 2024-08-01 9:06 ` Cyril Hrubis
2024-08-01 9:41 ` Petr Vorel
0 siblings, 1 reply; 6+ messages in thread
From: Cyril Hrubis @ 2024-08-01 9:06 UTC (permalink / raw)
To: Petr Vorel; +Cc: ltp
Hi!
> > +static void run(void)
> > +{
> > + unsigned int cpu_id, node_id = 0;
> > +
> > + TST_EXP_FAIL(getcpu(tst_get_bad_addr(NULL), &node_id), EFAULT);
> I'm not sure why, but I get SIGSEGV due tst_get_bad_addr(NULL) on various
> kernels (SLES 5.14.21, Tumbleweed 6.5.1, 6.10, Debian 6.9, ...).
>
> But the test works on SLES 4.4.180.
If you are getting SIGSEGV that means that the address is used in
userspace. Looking at man getcpu() it suggests that on some
architectures it may be implemented as VDSO, which would explain it.
So I suppose that the easies solution here would be to run the test in a
child process and accepting SIGSEGV as a correct outcome as well.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [LTP] [PATCH v2] getcpu: Add testcase for EFAULT
2024-08-01 9:06 ` Cyril Hrubis
@ 2024-08-01 9:41 ` Petr Vorel
0 siblings, 0 replies; 6+ messages in thread
From: Petr Vorel @ 2024-08-01 9:41 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
> Hi!
> > > +static void run(void)
> > > +{
> > > + unsigned int cpu_id, node_id = 0;
> > > +
> > > + TST_EXP_FAIL(getcpu(tst_get_bad_addr(NULL), &node_id), EFAULT);
> > I'm not sure why, but I get SIGSEGV due tst_get_bad_addr(NULL) on various
> > kernels (SLES 5.14.21, Tumbleweed 6.5.1, 6.10, Debian 6.9, ...).
> > But the test works on SLES 4.4.180.
> If you are getting SIGSEGV that means that the address is used in
> userspace. Looking at man getcpu() it suggests that on some
> architectures it may be implemented as VDSO, which would explain it.
> So I suppose that the easies solution here would be to run the test in a
> child process and accepting SIGSEGV as a correct outcome as well.
Thanks, Cyril.
Ma Xinjian, could you please send another version?
You can get inspiration in:
testcases/kernel/syscalls/setrlimit/setrlimit05.c
Or in others:
$ git grep -l .forks_child $(git grep -l SIGSEGV)
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-08-01 9:41 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-17 2:27 [LTP] [PATCH] getcpu: Add testcase for EFAULT Ma Xinjian via ltp
2024-07-17 14:01 ` Cyril Hrubis
2024-07-18 6:55 ` [LTP] [PATCH v2] " Ma Xinjian via ltp
2024-07-29 22:57 ` Petr Vorel
2024-08-01 9:06 ` Cyril Hrubis
2024-08-01 9:41 ` Petr Vorel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox