From df0892cbf854e76fae6e875043b05c194e37f52d Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Mon, 12 Jun 2017 22:36:03 -0700 Subject: runtime, syscall: reset signal handlers to default in child Block all signals during a fork. In the parent process, after the fork, restore the signal mask. In the child process, reset all currently handled signals to the default handler, and then restore the signal mask. The effect of this is that the child will be operating using the same signal regime as the program it is about to exec, as exec resets all non-ignored signals to the default, and preserves the signal mask. We do this so that in the case of a signal sent to the process group, the child process will not try to run a signal handler while in the precarious state after a fork. Fixes #18600. Change-Id: I9f39aaa3884035908d687ee323c975f349d5faaa Reviewed-on: https://go-review.googlesource.com/45471 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Austin Clements --- src/syscall/exec_linux.go | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/syscall/exec_linux.go') diff --git a/src/syscall/exec_linux.go b/src/syscall/exec_linux.go index 5f53eaaa36..e631cd6470 100644 --- a/src/syscall/exec_linux.go +++ b/src/syscall/exec_linux.go @@ -50,6 +50,7 @@ var ( // Implemented in runtime package. func runtime_BeforeFork() func runtime_AfterFork() +func runtime_AfterForkInChild() // Fork, dup fd onto 0..len(fd), and exec(argv0, argvv, envv) in child. // If a dup or exec fails, write the errno error to pipe. @@ -133,6 +134,8 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr // Fork succeeded, now in child. + runtime_AfterForkInChild() + // Wait for User ID/Group ID mappings to be written. if sys.UidMappings != nil || sys.GidMappings != nil { if _, _, err1 = RawSyscall(SYS_CLOSE, uintptr(p[1]), 0, 0); err1 != 0 { -- cgit v1.3