Fix race in fork_singalmasked

ELF RTLD after rtld.c r. 1.204 introduced locking that wraps the fork
syscall. This locking changes signal mask of the calling process during
the forking process.

Instead of comparing old and new signal mask, just after the forking
operation, check whether the expected signal is still masked and in
another test whether it is still ignored.
This commit is contained in:
kamil 2020-05-11 20:58:48 +00:00
parent a38f79e2a6
commit 9400a778fb
1 changed files with 15 additions and 18 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: t_ptrace_fork_wait.h,v 1.1 2020/05/04 22:34:22 kamil Exp $ */
/* $NetBSD: t_ptrace_fork_wait.h,v 1.2 2020/05/11 20:58:48 kamil Exp $ */
/*-
* Copyright (c) 2016, 2017, 2018, 2020 The NetBSD Foundation, Inc.
@ -1318,11 +1318,8 @@ fork2_body(const char *fn, bool masked, bool ignored)
FORKEE_ASSERT_EQ(sysctl(name, namelen, &kp, &len, NULL, 0), 0);
if (masked)
kp_sigmask = kp.p_sigmask;
if (ignored)
kp_sigignore = kp.p_sigignore;
kp_sigmask = kp.p_sigmask;
kp_sigignore = kp.p_sigignore;
DPRINTF("Set 0%s%s%s%s in EVENT_MASK for the child %d\n",
strcmp(fn, "spawn") == 0 ? "|PTRACE_POSIX_SPAWN" : "",
@ -1368,8 +1365,8 @@ fork2_body(const char *fn, bool masked, bool ignored)
kp.p_sigmask.__bits[0], kp.p_sigmask.__bits[1],
kp.p_sigmask.__bits[2], kp.p_sigmask.__bits[3]);
ATF_REQUIRE(!memcmp(&kp_sigmask, &kp.p_sigmask,
sizeof(kp_sigmask)));
ATF_REQUIRE(sigismember((sigset_t *)&kp.p_sigmask,
SIGTRAP));
}
if (ignored) {
@ -1385,8 +1382,8 @@ fork2_body(const char *fn, bool masked, bool ignored)
kp.p_sigignore.__bits[0], kp.p_sigignore.__bits[1],
kp.p_sigignore.__bits[2], kp.p_sigignore.__bits[3]);
ATF_REQUIRE(!memcmp(&kp_sigignore, &kp.p_sigignore,
sizeof(kp_sigignore)));
ATF_REQUIRE(sigismember((sigset_t *)&kp.p_sigignore,
SIGTRAP));
}
SYSCALL_REQUIRE(
@ -1431,8 +1428,8 @@ fork2_body(const char *fn, bool masked, bool ignored)
kp.p_sigmask.__bits[0], kp.p_sigmask.__bits[1],
kp.p_sigmask.__bits[2], kp.p_sigmask.__bits[3]);
ATF_REQUIRE(!memcmp(&kp_sigmask, &kp.p_sigmask,
sizeof(kp_sigmask)));
ATF_REQUIRE(sigismember((sigset_t *)&kp.p_sigmask,
SIGTRAP));
}
if (ignored) {
@ -1448,8 +1445,8 @@ fork2_body(const char *fn, bool masked, bool ignored)
kp.p_sigignore.__bits[0], kp.p_sigignore.__bits[1],
kp.p_sigignore.__bits[2], kp.p_sigignore.__bits[3]);
ATF_REQUIRE(!memcmp(&kp_sigignore, &kp.p_sigignore,
sizeof(kp_sigignore)));
ATF_REQUIRE(sigismember((sigset_t *)&kp.p_sigignore,
SIGTRAP));
}
SYSCALL_REQUIRE(
@ -1510,8 +1507,8 @@ fork2_body(const char *fn, bool masked, bool ignored)
kp.p_sigmask.__bits[0], kp.p_sigmask.__bits[1],
kp.p_sigmask.__bits[2], kp.p_sigmask.__bits[3]);
ATF_REQUIRE(!memcmp(&kp_sigmask, &kp.p_sigmask,
sizeof(kp_sigmask)));
ATF_REQUIRE(sigismember((sigset_t *)&kp.p_sigmask,
SIGTRAP));
}
if (ignored) {
@ -1527,8 +1524,8 @@ fork2_body(const char *fn, bool masked, bool ignored)
kp.p_sigignore.__bits[0], kp.p_sigignore.__bits[1],
kp.p_sigignore.__bits[2], kp.p_sigignore.__bits[3]);
ATF_REQUIRE(!memcmp(&kp_sigignore, &kp.p_sigignore,
sizeof(kp_sigignore)));
ATF_REQUIRE(sigismember((sigset_t *)&kp.p_sigignore,
SIGTRAP));
}
SYSCALL_REQUIRE(