systrap: set PDEATHSIG right after forking a sysmsg thread

container_test:TestGoferExits fails by timeout, because there are some
sysmsg threads survived sandbox process death. When we fork a new sysmsg
thread, it is traced with PTRACE_O_EXITKILL, so we need to set PDEATHSIG
before detaching from it.

Signed-off-by: Andrei Vagin <avagin@gmail.com>
This commit is contained in:
Andrei Vagin
2023-09-20 20:19:36 -07:00
parent 4cd842b20a
commit 814eaf3b77
2 changed files with 15 additions and 16 deletions
+14 -1
View File
@@ -228,6 +228,20 @@ func (s *subprocess) handlePtraceSyscallRequest(req any) {
panic(fmt.Sprintf("error waiting for new clone: expected SIGSTOP, got %v", sig))
}
t.initRegs = ptraceThread.initRegs
// Set the parent death signal to SIGKILL.
_, err = t.syscallIgnoreInterrupt(&t.initRegs, unix.SYS_PRCTL,
arch.SyscallArgument{Value: linux.PR_SET_PDEATHSIG},
arch.SyscallArgument{Value: uintptr(unix.SIGKILL)},
arch.SyscallArgument{Value: 0},
arch.SyscallArgument{Value: 0},
arch.SyscallArgument{Value: 0},
arch.SyscallArgument{Value: 0},
)
if err != nil {
panic(fmt.Sprintf("prctl: %v", err))
}
id, ok := s.sysmsgStackPool.Get()
if !ok {
panic("unable to allocate a sysmsg stub thread")
@@ -240,7 +254,6 @@ func (s *subprocess) handlePtraceSyscallRequest(req any) {
// Detach the thread.
t.detach()
t.initRegs = ptraceThread.initRegs
// Return the thread.
r.thread <- t
@@ -39,20 +39,6 @@ func (p *sysmsgThread) setMsg(addr uintptr) {
func (p *sysmsgThread) init(sentryAddr, guestAddr uintptr) {
t := p.thread
// Set the parent death signal to SIGKILL.
_, err := t.syscallIgnoreInterrupt(&t.initRegs, unix.SYS_PRCTL,
arch.SyscallArgument{Value: linux.PR_SET_PDEATHSIG},
arch.SyscallArgument{Value: uintptr(unix.SIGKILL)},
arch.SyscallArgument{Value: 0},
arch.SyscallArgument{Value: 0},
arch.SyscallArgument{Value: 0},
arch.SyscallArgument{Value: 0},
)
if err != nil {
panic(fmt.Sprintf("prctl: %v", err))
}
// Set the sysmsg signal stack.
//
// sentryAddr is from the stub mapping which is mapped once and never
@@ -61,7 +47,7 @@ func (p *sysmsgThread) init(sentryAddr, guestAddr uintptr) {
*alt = linux.SignalStack{}
alt.Addr = uint64(guestAddr)
alt.Size = uint64(sysmsg.MsgOffsetFromSharedStack)
_, err = t.syscallIgnoreInterrupt(&t.initRegs, unix.SYS_SIGALTSTACK,
_, err := t.syscallIgnoreInterrupt(&t.initRegs, unix.SYS_SIGALTSTACK,
arch.SyscallArgument{Value: guestAddr},
arch.SyscallArgument{Value: 0},
arch.SyscallArgument{Value: 0},