public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] tools/nolibc: avoid coredumps and speed up tests
@ 2023-05-26  6:30 Thomas Weißschuh
  2023-05-26  6:30 ` [PATCH 1/2] tools/nolibc: add support for prctl() Thomas Weißschuh
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Thomas Weißschuh @ 2023-05-26  6:30 UTC (permalink / raw)
  To: Willy Tarreau, Shuah Khan
  Cc: linux-kernel, linux-kselftest, Thomas Weißschuh

Small optimization to avoid coredump writing during the stack protector
tests.
Adds prctl() as prerequisite.

This series is based on nolibc/20230524-nolibc-rv32+stkp4

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
Thomas Weißschuh (2):
      tools/nolibc: add support for prctl()
      selftests/nolibc: prevent coredumps during test execution

 tools/include/nolibc/sys.h                   | 27 +++++++++++++++++++++++++++
 tools/testing/selftests/nolibc/nolibc-test.c |  3 +++
 2 files changed, 30 insertions(+)
---
base-commit: 1974a2b5fd434812b32952b09df7b79fdee8104d
change-id: 20230526-nolibc-test-no-dump-a1b1d9557df8

Best regards,
-- 
Thomas Weißschuh <linux@weissschuh.net>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] tools/nolibc: add support for prctl()
  2023-05-26  6:30 [PATCH 0/2] tools/nolibc: avoid coredumps and speed up tests Thomas Weißschuh
@ 2023-05-26  6:30 ` Thomas Weißschuh
  2023-05-26  6:30 ` [PATCH 2/2] selftests/nolibc: prevent coredumps during test execution Thomas Weißschuh
  2023-05-28  7:31 ` [PATCH 0/2] tools/nolibc: avoid coredumps and speed up tests Willy Tarreau
  2 siblings, 0 replies; 4+ messages in thread
From: Thomas Weißschuh @ 2023-05-26  6:30 UTC (permalink / raw)
  To: Willy Tarreau, Shuah Khan
  Cc: linux-kernel, linux-kselftest, Thomas Weißschuh

It will be used to disable core dumps from the child spawned to validate
the stack protector functionality.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 tools/include/nolibc/sys.h                   | 27 +++++++++++++++++++++++++++
 tools/testing/selftests/nolibc/nolibc-test.c |  2 ++
 2 files changed, 29 insertions(+)

diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
index 7874062bea95..3d521feffad6 100644
--- a/tools/include/nolibc/sys.h
+++ b/tools/include/nolibc/sys.h
@@ -22,6 +22,7 @@
 #include <linux/fcntl.h> /* for O_* and AT_* */
 #include <linux/stat.h>  /* for statx() */
 #include <linux/reboot.h> /* for LINUX_REBOOT_* */
+#include <linux/prctl.h>
 
 #include "arch.h"
 #include "errno.h"
@@ -894,6 +895,32 @@ int open(const char *path, int flags, ...)
 }
 
 
+/*
+ * int prctl(int option, unsigned long arg2, unsigned long arg3,
+ *                       unsigned long arg4, unsigned long arg5);
+ */
+
+static __attribute__((unused))
+int sys_prctl(int option, unsigned long arg2, unsigned long arg3,
+		          unsigned long arg4, unsigned long arg5)
+{
+	return my_syscall5(__NR_prctl, option, arg2, arg3, arg4, arg5);
+}
+
+static __attribute__((unused))
+int prctl(int option, unsigned long arg2, unsigned long arg3,
+		      unsigned long arg4, unsigned long arg5)
+{
+	int ret = sys_prctl(option, arg2, arg3, arg4, arg5);
+
+	if (ret < 0) {
+		SET_ERRNO(-ret);
+		ret = -1;
+	}
+	return ret;
+}
+
+
 /*
  * int pivot_root(const char *new, const char *old);
  */
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 6e0a4dbe321e..76a9a0f362b1 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -22,6 +22,7 @@
 #include <sys/ioctl.h>
 #include <sys/mman.h>
 #include <sys/mount.h>
+#include <sys/prctl.h>
 #include <sys/reboot.h>
 #include <sys/stat.h>
 #include <sys/syscall.h>
@@ -580,6 +581,7 @@ int run_syscall(int min, int max)
 		CASE_TEST(poll_null);         EXPECT_SYSZR(1, poll(NULL, 0, 0)); break;
 		CASE_TEST(poll_stdout);       EXPECT_SYSNE(1, ({ struct pollfd fds = { 1, POLLOUT, 0}; poll(&fds, 1, 0); }), -1); break;
 		CASE_TEST(poll_fault);        EXPECT_SYSER(1, poll((void *)1, 1, 0), -1, EFAULT); break;
+		CASE_TEST(prctl);             EXPECT_SYSER(1, prctl(PR_SET_NAME, NULL, 0, 0, 0), -1, EFAULT); break;
 		CASE_TEST(read_badf);         EXPECT_SYSER(1, read(-1, &tmp, 1), -1, EBADF); break;
 		CASE_TEST(sched_yield);       EXPECT_SYSZR(1, sched_yield()); break;
 		CASE_TEST(select_null);       EXPECT_SYSZR(1, ({ struct timeval tv = { 0 }; select(0, NULL, NULL, NULL, &tv); })); break;

-- 
2.40.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] selftests/nolibc: prevent coredumps during test execution
  2023-05-26  6:30 [PATCH 0/2] tools/nolibc: avoid coredumps and speed up tests Thomas Weißschuh
  2023-05-26  6:30 ` [PATCH 1/2] tools/nolibc: add support for prctl() Thomas Weißschuh
@ 2023-05-26  6:30 ` Thomas Weißschuh
  2023-05-28  7:31 ` [PATCH 0/2] tools/nolibc: avoid coredumps and speed up tests Willy Tarreau
  2 siblings, 0 replies; 4+ messages in thread
From: Thomas Weißschuh @ 2023-05-26  6:30 UTC (permalink / raw)
  To: Willy Tarreau, Shuah Khan
  Cc: linux-kernel, linux-kselftest, Thomas Weißschuh

The child process forked during stackprotector tests intentionally gets
killed with SIGABRT. By default this will trigger writing a coredump.
The writing of the coredump can spam the systems coredump machinery and
take some time.

Timings for the full run of nolibc-test:
Before: 200ms
After:   20ms

This is on a desktop x86 system with systemd-coredumpd enabled.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 tools/testing/selftests/nolibc/nolibc-test.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 76a9a0f362b1..40fb684eaac9 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -831,6 +831,7 @@ static int run_protection(int min, int max)
 		close(STDOUT_FILENO);
 		close(STDERR_FILENO);
 
+		prctl(PR_SET_DUMPABLE, 0, 0, 0, 0);
 		smash_stack();
 		return 1;
 

-- 
2.40.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] tools/nolibc: avoid coredumps and speed up tests
  2023-05-26  6:30 [PATCH 0/2] tools/nolibc: avoid coredumps and speed up tests Thomas Weißschuh
  2023-05-26  6:30 ` [PATCH 1/2] tools/nolibc: add support for prctl() Thomas Weißschuh
  2023-05-26  6:30 ` [PATCH 2/2] selftests/nolibc: prevent coredumps during test execution Thomas Weißschuh
@ 2023-05-28  7:31 ` Willy Tarreau
  2 siblings, 0 replies; 4+ messages in thread
From: Willy Tarreau @ 2023-05-28  7:31 UTC (permalink / raw)
  To: Thomas Weißschuh; +Cc: Shuah Khan, linux-kernel, linux-kselftest

On Fri, May 26, 2023 at 08:30:34AM +0200, Thomas Weißschuh wrote:
> Small optimization to avoid coredump writing during the stack protector
> tests.
> Adds prctl() as prerequisite.
> 
> This series is based on nolibc/20230524-nolibc-rv32+stkp4

Looks good and now queued, thank you Thomas,
Willy

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-05-28  7:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-26  6:30 [PATCH 0/2] tools/nolibc: avoid coredumps and speed up tests Thomas Weißschuh
2023-05-26  6:30 ` [PATCH 1/2] tools/nolibc: add support for prctl() Thomas Weißschuh
2023-05-26  6:30 ` [PATCH 2/2] selftests/nolibc: prevent coredumps during test execution Thomas Weißschuh
2023-05-28  7:31 ` [PATCH 0/2] tools/nolibc: avoid coredumps and speed up tests Willy Tarreau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox