aboutsummaryrefslogtreecommitdiff
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-07-07 07:06:55 +0000
commit8adf49dac1a937c9a8dc6937d6d23af14df7597a (patch)
tree77c93fe17c8188c3b09571516eaed5812c37e2aa
parent4fff1e9f10766268a65aa9ba657bc070fc8dcf30 (diff)
tests: Fix race condition in aslr_setuid
Use a cloexec pipe to block the parent until the child is ready. While here, redirect the output from ping to /dev/null, and mark the test as requiring the inet feature since we ping the IPv4 loopback. PR: 296116 MFC after: 1 week Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D57734 (cherry picked from commit 080a4087014e1d19136cc77028019d98b5c69e1e) tests: Fix race condition in aslr_setuid, take 2 Instead of a cloexec pipe, ingest ping's stdout and block until it has printed its initial summary, then close the pipe and return to the main test loop. Run ping in quiet mode so it won't mind that stdout is gone. PR: 296116 MFC after: 1 week Fixes: 080a4087014e ("tests: Fix race condition in aslr_setuid") Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D57763 (cherry picked from commit 86950cf9ffe89b7978fca019019692b3ea492044)
-rw-r--r--tests/sys/kern/Makefile1
-rw-r--r--tests/sys/kern/aslr.c16
2 files changed, 13 insertions, 4 deletions
diff --git a/tests/sys/kern/Makefile b/tests/sys/kern/Makefile
index 03aca4f19a56..ab68fbf11a6e 100644
--- a/tests/sys/kern/Makefile
+++ b/tests/sys/kern/Makefile
@@ -94,6 +94,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..966ea5c3b83a 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
@@ -27,19 +29,22 @@
static pid_t
spawn_ping(const atf_tc_t *tc)
{
+ char line[64];
const char *user;
struct passwd *passwd;
pid_t child;
- int arg, error;
+ int arg, error, io[2];
user = atf_tc_get_config_var(tc, "unprivileged_user");
passwd = getpwnam(user);
ATF_REQUIRE(passwd != NULL);
+ ATF_REQUIRE(pipe2(io, O_CLOEXEC) == 0);
child = fork();
ATF_REQUIRE(child >= 0);
if (child == 0) {
- if (seteuid(passwd->pw_uid) != 0)
+ if (dup2(io[1], STDOUT_FILENO) != STDOUT_FILENO ||
+ seteuid(passwd->pw_uid) != 0)
_exit(1);
arg = PROC_ASLR_FORCE_DISABLE;
@@ -47,10 +52,12 @@ spawn_ping(const atf_tc_t *tc)
if (error != 0)
_exit(2);
- execl("/sbin/ping", "ping", "127.0.0.1", NULL);
+ execl("/sbin/ping", "ping", "-q", "127.0.0.1", NULL);
_exit(127);
}
- usleep(500000); /* XXX-MJ */
+ ATF_REQUIRE(close(io[1]) == 0);
+ ATF_REQUIRE(read(io[0], line, sizeof(line)) > 0);
+ ATF_REQUIRE(close(io[0]) == 0);
return (child);
}
@@ -98,6 +105,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");