From 7446cb625e6c290fc287c2bcf7ade6df0957742e Mon Sep 17 00:00:00 2001 From: kamil Date: Mon, 11 May 2020 20:58:48 +0000 Subject: 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. --- tests/lib/libc/sys/t_ptrace_fork_wait.h | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'tests/lib/libc/sys') diff --git a/tests/lib/libc/sys/t_ptrace_fork_wait.h b/tests/lib/libc/sys/t_ptrace_fork_wait.h index de4099b92ab..27fe431fec2 100644 --- a/tests/lib/libc/sys/t_ptrace_fork_wait.h +++ b/tests/lib/libc/sys/t_ptrace_fork_wait.h @@ -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( -- cgit