From 5bc1bf864597e50a76d0081e4b8e3d47da005a26 Mon Sep 17 00:00:00 2001 From: anton Date: Tue, 11 Oct 2022 05:45:41 +0000 Subject: [PATCH] Run noexec tests in a new thread, leveraging the fact that pthread_create() allocates a new stack which has mutable permissions. Allows the temporary expected failures to be dropped. ok deraadt@ --- regress/sys/kern/noexec/Makefile | 6 ++---- regress/sys/kern/noexec/noexec.c | 37 ++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/regress/sys/kern/noexec/Makefile b/regress/sys/kern/noexec/Makefile index 74c866fb606..9c78ed73af7 100644 --- a/regress/sys/kern/noexec/Makefile +++ b/regress/sys/kern/noexec/Makefile @@ -1,8 +1,9 @@ -# $OpenBSD: Makefile,v 1.24 2022/10/10 05:26:11 anton Exp $ +# $OpenBSD: Makefile,v 1.25 2022/10/11 05:45:41 anton Exp $ PROG= noexec SRCS= noexec.c testfly.S CFLAGS= -Wall -fno-inline +LDFLAGS= -pthread LDSTATIC= ${STATIC} REGRESS_TARGETS= nxtext-mmap nxtext-mprotect \ @@ -13,9 +14,6 @@ REGRESS_TARGETS= nxtext-mmap nxtext-mprotect \ nxstack nxstack-mmap nxstack-mprotect .PHONY: ${REGRESS_TARGETS} -REGRESS_EXPECTED_FAILURES+= nxstack-mmap -REGRESS_EXPECTED_FAILURES+= nxstack-mprotect - nxtext-mmap: ${PROG} ./${PROG} -T -m diff --git a/regress/sys/kern/noexec/noexec.c b/regress/sys/kern/noexec/noexec.c index b98bc91fc7e..950082321ad 100644 --- a/regress/sys/kern/noexec/noexec.c +++ b/regress/sys/kern/noexec/noexec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: noexec.c,v 1.21 2021/12/13 16:56:50 deraadt Exp $ */ +/* $OpenBSD: noexec.c,v 1.22 2022/10/11 05:45:41 anton Exp $ */ /* * Copyright (c) 2002,2003 Michael Shalayeff @@ -37,6 +37,12 @@ #include #include #include +#include + +struct context { + char **argv; + int argc; +}; volatile sig_atomic_t fail; int page_size; @@ -177,9 +183,10 @@ usage(void) exit(2); } -int -main(int argc, char *argv[]) +static void * +worker(void *arg) { + struct context *ctx = arg; u_int64_t stack[TESTSZ/8]; /* assuming the testfly() will fit */ struct sigaction sa; int (*func)(void *, size_t); @@ -198,7 +205,7 @@ main(int argc, char *argv[]) pflags = MAP_PRIVATE|MAP_ANON|MAP_FIXED; func = &noexec; size = TESTSZ; - while ((ch = getopt(argc, argv, "TDBHSmps:")) != -1) { + while ((ch = getopt(ctx->argc, ctx->argv, "TDBHSmps:")) != -1) { if (p == NULL) { switch (ch) { case 'T': @@ -267,10 +274,10 @@ main(int argc, char *argv[]) usage(); } } - argc -= optind; - argv += optind; + ctx->argc -= optind; + ctx->argv += optind; - if (argc > 0) + if (ctx->argc > 0) usage(); if (p == NULL) @@ -287,4 +294,20 @@ main(int argc, char *argv[]) } exit((*func)(p, size)); + /* NOTREACHED */ + return NULL; +} + +int +main(int argc, char *argv[]) +{ + struct context ctx = {.argc = argc, .argv = argv}; + pthread_t th; + int error; + + if ((error = pthread_create(&th, NULL, worker, (void *)&ctx))) + errc(1, error, "pthread_create"); + if ((error = pthread_join(th, NULL))) + errc(1, error, "pthread_join"); + return 0; } -- 2.20.1