aboutsummaryrefslogtreecommitdiff
path: root/tests/sys
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>2026-06-22 13:23:31 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>2026-06-22 13:23:48 +0000
commit080a4087014e1d19136cc77028019d98b5c69e1e (patch)
tree472183b814c504e245e3feaa75196e2d68a96824 /tests/sys
parent8f750231d4b58ac71cbd3ac3548e1d7eb849f04b (diff)
Diffstat (limited to 'tests/sys')
-rw-r--r--tests/sys/kern/Makefile1
-rw-r--r--tests/sys/kern/aslr.c16
2 files changed, 14 insertions, 3 deletions
diff --git a/tests/sys/kern/Makefile b/tests/sys/kern/Makefile
index 3b09ee3181d2..728917b062c5 100644
--- a/tests/sys/kern/Makefile
+++ b/tests/sys/kern/Makefile
@@ -92,6 +92,7 @@ PROGS+= coredump_phnum_helper
PROGS+= pdeathsig_helper
PROGS+= sendfile_helper
+CFLAGS.aslr+= -I${SRCTOP}/tests
LIBADD.aslr+= util
LIBADD.copy_file_range+= md
LIBADD.jail_lookup_root+= jail util
diff --git a/tests/sys/kern/aslr.c b/tests/sys/kern/aslr.c
index 13038054603c..7d5282fc7cf3 100644
--- a/tests/sys/kern/aslr.c
+++ b/tests/sys/kern/aslr.c
@@ -11,6 +11,7 @@
#include <sys/user.h>
#include <sys/wait.h>
+#include <fcntl.h>
#include <libutil.h>
#include <pwd.h>
#include <signal.h>
@@ -19,6 +20,7 @@
#include <unistd.h>
#include <atf-c.h>
+#include "freebsd_test_suite/macros.h"
/*
* Spawn an unprivileged child with ASLR force-disabled, which then execs
@@ -30,16 +32,21 @@ spawn_ping(const atf_tc_t *tc)
const char *user;
struct passwd *passwd;
pid_t child;
- int arg, error;
+ int arg, error, ctl[2];
+ char dummy;
user = atf_tc_get_config_var(tc, "unprivileged_user");
passwd = getpwnam(user);
ATF_REQUIRE(passwd != NULL);
+ ATF_REQUIRE(pipe2(ctl, O_CLOEXEC) == 0);
child = fork();
ATF_REQUIRE(child >= 0);
if (child == 0) {
- if (seteuid(passwd->pw_uid) != 0)
+ if (close(ctl[0]) != 0 ||
+ close(STDOUT_FILENO) != 0 ||
+ open("/dev/null", O_WRONLY | O_APPEND) != STDOUT_FILENO ||
+ seteuid(passwd->pw_uid) != 0)
_exit(1);
arg = PROC_ASLR_FORCE_DISABLE;
@@ -50,7 +57,9 @@ spawn_ping(const atf_tc_t *tc)
execl("/sbin/ping", "ping", "127.0.0.1", NULL);
_exit(127);
}
- usleep(500000); /* XXX-MJ */
+ ATF_REQUIRE(close(ctl[1]) == 0);
+ ATF_REQUIRE(read(ctl[0], &dummy, 1) == 0);
+ ATF_REQUIRE(close(ctl[0]) == 0);
return (child);
}
@@ -98,6 +107,7 @@ ATF_TC_BODY(aslr_setuid, tc)
pid_t child, pid;
int arg, error, st;
+ ATF_REQUIRE_FEATURE("inet");
if (!atf_tc_has_config_var(tc, "unprivileged_user"))
atf_tc_skip("unprivileged_user not set");