mirror of
https://github.com/criyle/go-sandbox.git
synced 2025-11-04 14:49:53 +08:00
add execveat to ptrace
This commit is contained in:
parent
988d521f25
commit
c7679b02fb
@ -95,6 +95,8 @@ func (h *tracerHandler) Handle(ctx *tracer.Context) tracer.TraceAction {
|
|||||||
|
|
||||||
case "execve":
|
case "execve":
|
||||||
action = h.checkRead(ctx, ctx.Arg0())
|
action = h.checkRead(ctx, ctx.Arg0())
|
||||||
|
case "execveat":
|
||||||
|
action = h.checkRead(ctx, ctx.Arg1())
|
||||||
|
|
||||||
case "chmod":
|
case "chmod":
|
||||||
action = h.checkWrite(ctx, ctx.Arg0())
|
action = h.checkWrite(ctx, ctx.Arg0())
|
||||||
|
|||||||
@ -14,7 +14,7 @@ func ptraceReadStr(pid int, addr uintptr, buff []byte) {
|
|||||||
|
|
||||||
func processVMReadv(pid int, localIov, remoteIov []unix.Iovec,
|
func processVMReadv(pid int, localIov, remoteIov []unix.Iovec,
|
||||||
flags uintptr) (r1, r2 uintptr, err syscall.Errno) {
|
flags uintptr) (r1, r2 uintptr, err syscall.Errno) {
|
||||||
return syscall.RawSyscall6(unix.SYS_PROCESS_VM_READV, uintptr(pid),
|
return syscall.Syscall6(unix.SYS_PROCESS_VM_READV, uintptr(pid),
|
||||||
uintptr(unsafe.Pointer(&localIov[0])), uintptr(len(localIov)),
|
uintptr(unsafe.Pointer(&localIov[0])), uintptr(len(localIov)),
|
||||||
uintptr(unsafe.Pointer(&remoteIov[0])), uintptr(len(remoteIov)),
|
uintptr(unsafe.Pointer(&remoteIov[0])), uintptr(len(remoteIov)),
|
||||||
flags)
|
flags)
|
||||||
|
|||||||
@ -238,7 +238,8 @@ func handleTrap(handler Handler, pid int) error {
|
|||||||
|
|
||||||
switch act {
|
switch act {
|
||||||
case TraceBan:
|
case TraceBan:
|
||||||
// Set the syscallno to -1 and return value into register. https://www.kernel.org/doc/Documentation/prctl/seccomp_filter.txt
|
// Set the syscallno to -1 and return value into register to skip syscall.
|
||||||
|
// https://www.kernel.org/doc/Documentation/prctl/seccomp_filter.txt
|
||||||
return ctx.skipSyscall()
|
return ctx.skipSyscall()
|
||||||
|
|
||||||
case TraceKill:
|
case TraceKill:
|
||||||
@ -256,8 +257,9 @@ func handleTrap(handler Handler, pid int) error {
|
|||||||
|
|
||||||
// set Ptrace option that set up seccomp, exit kill and all mult-process actions
|
// set Ptrace option that set up seccomp, exit kill and all mult-process actions
|
||||||
func setPtraceOption(pid int) error {
|
func setPtraceOption(pid int) error {
|
||||||
return unix.PtraceSetOptions(pid, unix.PTRACE_O_TRACESECCOMP|unix.PTRACE_O_EXITKILL|
|
const ptraceFlags = unix.PTRACE_O_TRACESECCOMP | unix.PTRACE_O_EXITKILL | unix.PTRACE_O_TRACEFORK |
|
||||||
unix.PTRACE_O_TRACEFORK|unix.PTRACE_O_TRACECLONE|unix.PTRACE_O_TRACEEXEC|unix.PTRACE_O_TRACEVFORK)
|
unix.PTRACE_O_TRACECLONE | unix.PTRACE_O_TRACEEXEC | unix.PTRACE_O_TRACEVFORK
|
||||||
|
return unix.PtraceSetOptions(pid, ptraceFlags)
|
||||||
}
|
}
|
||||||
|
|
||||||
// kill all tracee according to pids
|
// kill all tracee according to pids
|
||||||
@ -267,10 +269,10 @@ func killAll(pgid int) {
|
|||||||
|
|
||||||
// collect died child processes
|
// collect died child processes
|
||||||
func collectZombie(pgid int) {
|
func collectZombie(pgid int) {
|
||||||
|
var wstatus unix.WaitStatus
|
||||||
// collect zombies
|
// collect zombies
|
||||||
for {
|
for {
|
||||||
var wstatus unix.WaitStatus
|
if _, err := unix.Wait4(-pgid, &wstatus, unix.WALL|unix.WNOHANG, nil); err != nil {
|
||||||
if _, err := unix.Wait4(-pgid, &wstatus, unix.WALL|unix.WNOWAIT, nil); err != nil {
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user