Commit e974f4fd authored by Jess Frazelle's avatar Jess Frazelle Committed by Jessie Frazelle

syscall: move ptrace setup to right before exec

This will prevent any ptrace calls from getting trace output from the runtime
itself setting up after fork.

Fixes #21428.

Change-Id: I9d835bd5a8f404394eb6237679f2111a72e5bc17
Reviewed-on: https://go-review.googlesource.com/55811
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
Reviewed-by: 's avatarAvelino <t@avelino.xxx>
parent 0c7fd569
...@@ -199,14 +199,6 @@ func forkAndExecInChild1(argv0 *byte, argv, envv []*byte, chroot, dir *byte, att ...@@ -199,14 +199,6 @@ func forkAndExecInChild1(argv0 *byte, argv, envv []*byte, chroot, dir *byte, att
} }
} }
// Enable tracing if requested.
if sys.Ptrace {
_, _, err1 = RawSyscall(SYS_PTRACE, uintptr(PTRACE_TRACEME), 0, 0)
if err1 != 0 {
goto childerror
}
}
// Session ID // Session ID
if sys.Setsid { if sys.Setsid {
_, _, err1 = RawSyscall(SYS_SETSID, 0, 0, 0) _, _, err1 = RawSyscall(SYS_SETSID, 0, 0, 0)
...@@ -402,6 +394,16 @@ func forkAndExecInChild1(argv0 *byte, argv, envv []*byte, chroot, dir *byte, att ...@@ -402,6 +394,16 @@ func forkAndExecInChild1(argv0 *byte, argv, envv []*byte, chroot, dir *byte, att
} }
} }
// Enable tracing if requested.
// Do this right before exec so that we don't unnecessarily trace the runtime
// setting up after the fork. See issue #21428.
if sys.Ptrace {
_, _, err1 = RawSyscall(SYS_PTRACE, uintptr(PTRACE_TRACEME), 0, 0)
if err1 != 0 {
goto childerror
}
}
// Time to exec. // Time to exec.
_, _, err1 = RawSyscall(SYS_EXECVE, _, _, err1 = RawSyscall(SYS_EXECVE,
uintptr(unsafe.Pointer(argv0)), uintptr(unsafe.Pointer(argv0)),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment