mirror of
https://github.com/freebsd/freebsd-src.git
synced 2026-10-28 19:34:43 +01:00
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
This commit is contained in:
1 parent
8f750231d4
commit
080a408701
2 files changed
+14
-3
No files matched your search
@@ -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
|
||||
|
||||
+13
-3
@@ -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");
|
||||
|
||||
|
||||
Reference in new issue
Block a user