diff options
Diffstat (limited to 'pkg/sentry/strace')
-rw-r--r-- | pkg/sentry/strace/BUILD | 1 | ||||
-rw-r--r-- | pkg/sentry/strace/linux64.go | 20 | ||||
-rw-r--r-- | pkg/sentry/strace/signal.go | 86 | ||||
-rw-r--r-- | pkg/sentry/strace/strace.go | 8 | ||||
-rw-r--r-- | pkg/sentry/strace/syscalls.go | 12 |
5 files changed, 117 insertions, 10 deletions
diff --git a/pkg/sentry/strace/BUILD b/pkg/sentry/strace/BUILD index 52c7f325c..8517db1ac 100644 --- a/pkg/sentry/strace/BUILD +++ b/pkg/sentry/strace/BUILD @@ -11,6 +11,7 @@ go_library( "linux64.go", "open.go", "ptrace.go", + "signal.go", "socket.go", "strace.go", "syscalls.go", diff --git a/pkg/sentry/strace/linux64.go b/pkg/sentry/strace/linux64.go index 99714f12c..a2ca1a456 100644 --- a/pkg/sentry/strace/linux64.go +++ b/pkg/sentry/strace/linux64.go @@ -30,8 +30,8 @@ var linuxAMD64 = SyscallMap{ 10: makeSyscallInfo("mprotect", Hex, Hex, Hex), 11: makeSyscallInfo("munmap", Hex, Hex), 12: makeSyscallInfo("brk", Hex), - 13: makeSyscallInfo("rt_sigaction", Hex, Hex, Hex), - 14: makeSyscallInfo("rt_sigprocmask", Hex, Hex, Hex, Hex), + 13: makeSyscallInfo("rt_sigaction", Signal, Hex, Hex), + 14: makeSyscallInfo("rt_sigprocmask", SignalMaskAction, SigSet, PostSigSet, Hex), 15: makeSyscallInfo("rt_sigreturn"), 16: makeSyscallInfo("ioctl", Hex, Hex, Hex), 17: makeSyscallInfo("pread64", Hex, ReadBuffer, Hex, Hex), @@ -79,7 +79,7 @@ var linuxAMD64 = SyscallMap{ 59: makeSyscallInfo("execve", Path, ExecveStringVector, ExecveStringVector), 60: makeSyscallInfo("exit", Hex), 61: makeSyscallInfo("wait4", Hex, Hex, Hex, Rusage), - 62: makeSyscallInfo("kill", Hex, Hex), + 62: makeSyscallInfo("kill", Hex, Signal), 63: makeSyscallInfo("uname", Uname), 64: makeSyscallInfo("semget", Hex, Hex, Hex), 65: makeSyscallInfo("semop", Hex, Hex, Hex), @@ -145,8 +145,8 @@ var linuxAMD64 = SyscallMap{ 125: makeSyscallInfo("capget", Hex, Hex), 126: makeSyscallInfo("capset", Hex, Hex), 127: makeSyscallInfo("rt_sigpending", Hex), - 128: makeSyscallInfo("rt_sigtimedwait", Hex, Hex, Timespec, Hex), - 129: makeSyscallInfo("rt_sigqueueinfo", Hex, Hex, Hex), + 128: makeSyscallInfo("rt_sigtimedwait", SigSet, Hex, Timespec, Hex), + 129: makeSyscallInfo("rt_sigqueueinfo", Hex, Signal, Hex), 130: makeSyscallInfo("rt_sigsuspend", Hex), 131: makeSyscallInfo("sigaltstack", Hex, Hex), 132: makeSyscallInfo("utime", Path, Utimbuf), @@ -217,7 +217,7 @@ var linuxAMD64 = SyscallMap{ 197: makeSyscallInfo("removexattr", Path, Path), 198: makeSyscallInfo("lremovexattr", Path, Path), 199: makeSyscallInfo("fremovexattr", Hex, Path), - 200: makeSyscallInfo("tkill", Hex, Hex), + 200: makeSyscallInfo("tkill", Hex, Signal), 201: makeSyscallInfo("time", Hex), 202: makeSyscallInfo("futex", Hex, FutexOp, Hex, Timespec, Hex, Hex), 203: makeSyscallInfo("sched_setaffinity", Hex, Hex, Hex), @@ -251,7 +251,7 @@ var linuxAMD64 = SyscallMap{ 231: makeSyscallInfo("exit_group", Hex), 232: makeSyscallInfo("epoll_wait", Hex, Hex, Hex, Hex), 233: makeSyscallInfo("epoll_ctl", Hex, Hex, Hex, Hex), - 234: makeSyscallInfo("tgkill", Hex, Hex, Hex), + 234: makeSyscallInfo("tgkill", Hex, Hex, Signal), 235: makeSyscallInfo("utimes", Path, Timeval), // 236: vserver (not implemented in the Linux kernel) 237: makeSyscallInfo("mbind", Hex, Hex, Hex, Hex, Hex, Hex), @@ -288,7 +288,7 @@ var linuxAMD64 = SyscallMap{ 268: makeSyscallInfo("fchmodat", Hex, Path, Mode), 269: makeSyscallInfo("faccessat", Hex, Path, Oct, Hex), 270: makeSyscallInfo("pselect6", Hex, Hex, Hex, Hex, Hex, Hex), - 271: makeSyscallInfo("ppoll", Hex, Hex, Timespec, Hex, Hex), + 271: makeSyscallInfo("ppoll", Hex, Hex, Timespec, SigSet, Hex), 272: makeSyscallInfo("unshare", Hex), 273: makeSyscallInfo("set_robust_list", Hex, Hex), 274: makeSyscallInfo("get_robust_list", Hex, Hex, Hex), @@ -298,7 +298,7 @@ var linuxAMD64 = SyscallMap{ 278: makeSyscallInfo("vmsplice", Hex, Hex, Hex, Hex), 279: makeSyscallInfo("move_pages", Hex, Hex, Hex, Hex, Hex, Hex), 280: makeSyscallInfo("utimensat", Hex, Path, UTimeTimespec, Hex), - 281: makeSyscallInfo("epoll_pwait", Hex, Hex, Hex, Hex, Hex, Hex), + 281: makeSyscallInfo("epoll_pwait", Hex, Hex, Hex, Hex, SigSet, Hex), 282: makeSyscallInfo("signalfd", Hex, Hex, Hex), 283: makeSyscallInfo("timerfd_create", Hex, Hex), 284: makeSyscallInfo("eventfd", Hex), @@ -314,7 +314,7 @@ var linuxAMD64 = SyscallMap{ 294: makeSyscallInfo("inotify_init1", Hex), 295: makeSyscallInfo("preadv", Hex, ReadIOVec, Hex, Hex), 296: makeSyscallInfo("pwritev", Hex, WriteIOVec, Hex, Hex), - 297: makeSyscallInfo("rt_tgsigqueueinfo", Hex, Hex, Hex, Hex), + 297: makeSyscallInfo("rt_tgsigqueueinfo", Hex, Hex, Signal, Hex), 298: makeSyscallInfo("perf_event_open", Hex, Hex, Hex, Hex, Hex), 299: makeSyscallInfo("recvmmsg", Hex, Hex, Hex, Hex, Hex), 300: makeSyscallInfo("fanotify_init", Hex, Hex), diff --git a/pkg/sentry/strace/signal.go b/pkg/sentry/strace/signal.go new file mode 100644 index 000000000..00ed02a3c --- /dev/null +++ b/pkg/sentry/strace/signal.go @@ -0,0 +1,86 @@ +// Copyright 2018 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package strace + +import ( + "fmt" + "strings" + + "gvisor.googlesource.com/gvisor/pkg/abi" + "gvisor.googlesource.com/gvisor/pkg/abi/linux" + "gvisor.googlesource.com/gvisor/pkg/sentry/kernel" + "gvisor.googlesource.com/gvisor/pkg/sentry/usermem" +) + +// signalNames contains the names of all named signals. +var signalNames = abi.ValueSet{ + uint64(linux.SIGABRT): "SIGABRT", + uint64(linux.SIGALRM): "SIGALRM", + uint64(linux.SIGBUS): "SIGBUS", + uint64(linux.SIGCHLD): "SIGCHLD", + uint64(linux.SIGCONT): "SIGCONT", + uint64(linux.SIGFPE): "SIGFPE", + uint64(linux.SIGHUP): "SIGHUP", + uint64(linux.SIGILL): "SIGILL", + uint64(linux.SIGINT): "SIGINT", + uint64(linux.SIGIO): "SIGIO", + uint64(linux.SIGKILL): "SIGKILL", + uint64(linux.SIGPIPE): "SIGPIPE", + uint64(linux.SIGPROF): "SIGPROF", + uint64(linux.SIGPWR): "SIGPWR", + uint64(linux.SIGQUIT): "SIGQUIT", + uint64(linux.SIGSEGV): "SIGSEGV", + uint64(linux.SIGSTKFLT): "SIGSTKFLT", + uint64(linux.SIGSTOP): "SIGSTOP", + uint64(linux.SIGSYS): "SIGSYS", + uint64(linux.SIGTERM): "SIGTERM", + uint64(linux.SIGTRAP): "SIGTRAP", + uint64(linux.SIGTSTP): "SIGTSTP", + uint64(linux.SIGTTIN): "SIGTTIN", + uint64(linux.SIGTTOU): "SIGTTOU", + uint64(linux.SIGURG): "SIGURG", + uint64(linux.SIGUSR1): "SIGUSR1", + uint64(linux.SIGUSR2): "SIGUSR2", + uint64(linux.SIGVTALRM): "SIGVTALRM", + uint64(linux.SIGWINCH): "SIGWINCH", + uint64(linux.SIGXCPU): "SIGXCPU", + uint64(linux.SIGXFSZ): "SIGXFSZ", +} + +var signalMaskActions = abi.ValueSet{ + linux.SIG_BLOCK: "SIG_BLOCK", + linux.SIG_UNBLOCK: "SIG_UNBLOCK", + linux.SIG_SETMASK: "SIG_SETMASK", +} + +func sigSet(t *kernel.Task, addr usermem.Addr) string { + if addr == 0 { + return "null" + } + + var b [linux.SignalSetSize]byte + if _, err := t.CopyInBytes(addr, b[:]); err != nil { + return fmt.Sprintf("%#x (error copying sigset: %v)", addr, err) + } + + set := linux.SignalSet(usermem.ByteOrder.Uint64(b[:])) + + var signals []string + linux.ForEachSignal(set, func(sig linux.Signal) { + signals = append(signals, signalNames.ParseDecimal(uint64(sig))) + }) + + return fmt.Sprintf("%#x [%v]", addr, strings.Join(signals, " ")) +} diff --git a/pkg/sentry/strace/strace.go b/pkg/sentry/strace/strace.go index e40e0b57c..6df84e690 100644 --- a/pkg/sentry/strace/strace.go +++ b/pkg/sentry/strace/strace.go @@ -333,6 +333,12 @@ func (i *SyscallInfo) pre(t *kernel.Task, args arch.SyscallArguments, maximumBlo output = append(output, PtraceRequestSet.Parse(args[arg].Uint64())) case ItimerType: output = append(output, ItimerTypes.Parse(uint64(args[arg].Int()))) + case Signal: + output = append(output, signalNames.ParseDecimal(args[arg].Uint64())) + case SignalMaskAction: + output = append(output, signalMaskActions.Parse(uint64(args[arg].Int()))) + case SigSet: + output = append(output, sigSet(t, args[arg].Pointer())) case Oct: output = append(output, "0o"+strconv.FormatUint(args[arg].Uint64(), 8)) case Hex: @@ -391,6 +397,8 @@ func (i *SyscallInfo) post(t *kernel.Task, args arch.SyscallArguments, rval uint output[arg] = timeval(t, args[arg].Pointer()) case Rusage: output[arg] = rusage(t, args[arg].Pointer()) + case PostSigSet: + output[arg] = sigSet(t, args[arg].Pointer()) } } } diff --git a/pkg/sentry/strace/syscalls.go b/pkg/sentry/strace/syscalls.go index 9eeb18a03..22aecc009 100644 --- a/pkg/sentry/strace/syscalls.go +++ b/pkg/sentry/strace/syscalls.go @@ -170,6 +170,18 @@ const ( // ItimerType is an itimer type (ITIMER_REAL, etc). ItimerType + + // Signal is a signal number. + Signal + + // SignalMaskAction is a signal mask action passed to rt_sigprocmask(2). + SignalMaskAction + + // SigSet is a signal set. + SigSet + + // PostSigSet is a signal set, formatted after syscall execution. + PostSigSet ) // defaultFormat is the syscall argument format to use if the actual format is |