Add O_EXITKILL to ptrace options.

This prevents a race before PDEATH_SIG can take effect during
a sentry crash.

Discovered and solution by avagin@.

PiperOrigin-RevId: 254871534
This commit is contained in:
Adin Scannell
2019-06-24 17:30:01 -07:00
committed by gVisor bot
parent 94a6bfab5d
commit 7f5d0afe52
+5 -2
View File
@@ -370,13 +370,16 @@ func (t *thread) destroy() {
// init initializes trace options.
func (t *thread) init() {
// Set our TRACESYSGOOD option to differeniate real SIGTRAP.
// Set our TRACESYSGOOD option to differeniate real SIGTRAP. We also
// set PTRACE_O_EXITKILL to ensure that the unexpected exit of the
// sentry will immediately kill the associated stubs.
const PTRACE_O_EXITKILL = 0x100000
_, _, errno := syscall.RawSyscall6(
syscall.SYS_PTRACE,
syscall.PTRACE_SETOPTIONS,
uintptr(t.tid),
0,
syscall.PTRACE_O_TRACESYSGOOD|syscall.PTRACE_O_TRACEEXIT,
syscall.PTRACE_O_TRACESYSGOOD|syscall.PTRACE_O_TRACEEXIT|PTRACE_O_EXITKILL,
0, 0)
if errno != 0 {
panic(fmt.Sprintf("ptrace set options failed: %v", errno))