aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>2026-06-23 15:20:26 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>2026-06-23 15:20:38 +0000
commit86950cf9ffe89b7978fca019019692b3ea492044 (patch)
tree6697bfccc4f7b69b66ac7eca794c35004847c9ce
parent141bb8579882f9d1f7e95351573e30f10689f4bf (diff)
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
-rw-r--r--tests/sys/kern/aslr.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/tests/sys/kern/aslr.c b/tests/sys/kern/aslr.c
index 7d5282fc7cf3..966ea5c3b83a 100644
--- a/tests/sys/kern/aslr.c
+++ b/tests/sys/kern/aslr.c
@@ -29,23 +29,21 @@
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, ctl[2];
- char dummy;
+ int arg, error, io[2];
user = atf_tc_get_config_var(tc, "unprivileged_user");
passwd = getpwnam(user);
ATF_REQUIRE(passwd != NULL);
- ATF_REQUIRE(pipe2(ctl, O_CLOEXEC) == 0);
+ ATF_REQUIRE(pipe2(io, O_CLOEXEC) == 0);
child = fork();
ATF_REQUIRE(child >= 0);
if (child == 0) {
- if (close(ctl[0]) != 0 ||
- close(STDOUT_FILENO) != 0 ||
- open("/dev/null", O_WRONLY | O_APPEND) != STDOUT_FILENO ||
+ if (dup2(io[1], STDOUT_FILENO) != STDOUT_FILENO ||
seteuid(passwd->pw_uid) != 0)
_exit(1);
@@ -54,12 +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);
}
- ATF_REQUIRE(close(ctl[1]) == 0);
- ATF_REQUIRE(read(ctl[0], &dummy, 1) == 0);
- ATF_REQUIRE(close(ctl[0]) == 0);
+ ATF_REQUIRE(close(io[1]) == 0);
+ ATF_REQUIRE(read(io[0], line, sizeof(line)) > 0);
+ ATF_REQUIRE(close(io[0]) == 0);
return (child);
}