2019-04-29 21:25:05 +00:00
|
|
|
// Copyright 2018 The gVisor Authors.
|
2018-04-27 17:37:02 +00:00
|
|
|
//
|
|
|
|
// 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 (
|
2019-06-13 23:49:09 +00:00
|
|
|
"gvisor.dev/gvisor/pkg/abi"
|
|
|
|
"gvisor.dev/gvisor/pkg/sentry/arch"
|
|
|
|
"gvisor.dev/gvisor/pkg/sentry/kernel"
|
2018-04-27 17:37:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// FormatSpecifier values describe how an individual syscall argument should be
|
|
|
|
// formatted.
|
|
|
|
type FormatSpecifier int
|
|
|
|
|
|
|
|
// Valid FormatSpecifiers.
|
|
|
|
//
|
|
|
|
// Unless otherwise specified, values are formatted before syscall execution
|
|
|
|
// and not updated after syscall execution (the same value is output).
|
|
|
|
const (
|
|
|
|
// Hex is just a hexadecimal number.
|
|
|
|
Hex FormatSpecifier = iota
|
|
|
|
|
|
|
|
// Oct is just an octal number.
|
|
|
|
Oct
|
|
|
|
|
2019-04-11 23:47:26 +00:00
|
|
|
// FD is a file descriptor.
|
|
|
|
FD
|
|
|
|
|
2018-04-27 17:37:02 +00:00
|
|
|
// ReadBuffer is a buffer for a read-style call. The syscall return
|
|
|
|
// value is used for the length.
|
|
|
|
//
|
|
|
|
// Formatted after syscall execution.
|
|
|
|
ReadBuffer
|
|
|
|
|
|
|
|
// WriteBuffer is a buffer for a write-style call. The following arg is
|
|
|
|
// used for the length.
|
|
|
|
//
|
|
|
|
// Contents omitted after syscall execution.
|
|
|
|
WriteBuffer
|
|
|
|
|
|
|
|
// ReadIOVec is a pointer to a struct iovec for a writev-style call.
|
|
|
|
// The following arg is used for the length. The return value is used
|
|
|
|
// for the total length.
|
|
|
|
//
|
|
|
|
// Complete contents only formatted after syscall execution.
|
|
|
|
ReadIOVec
|
|
|
|
|
|
|
|
// WriteIOVec is a pointer to a struct iovec for a writev-style call.
|
|
|
|
// The following arg is used for the length.
|
|
|
|
//
|
|
|
|
// Complete contents only formatted before syscall execution, omitted
|
|
|
|
// after.
|
|
|
|
WriteIOVec
|
|
|
|
|
|
|
|
// IOVec is a generic pointer to a struct iovec. Contents are not dumped.
|
|
|
|
IOVec
|
|
|
|
|
|
|
|
// SendMsgHdr is a pointer to a struct msghdr for a sendmsg-style call.
|
|
|
|
// Contents formatted only before syscall execution, omitted after.
|
|
|
|
SendMsgHdr
|
|
|
|
|
|
|
|
// RecvMsgHdr is a pointer to a struct msghdr for a recvmsg-style call.
|
|
|
|
// Contents formatted only after syscall execution.
|
|
|
|
RecvMsgHdr
|
|
|
|
|
|
|
|
// Path is a pointer to a char* path.
|
|
|
|
Path
|
|
|
|
|
2018-07-20 19:58:59 +00:00
|
|
|
// PostPath is a pointer to a char* path, formatted after syscall
|
|
|
|
// execution.
|
|
|
|
PostPath
|
|
|
|
|
2018-04-27 17:37:02 +00:00
|
|
|
// ExecveStringVector is a NULL-terminated array of strings. Enforces
|
|
|
|
// the maximum execve array length.
|
|
|
|
ExecveStringVector
|
|
|
|
|
|
|
|
// PipeFDs is an array of two FDs, formatted after syscall execution.
|
|
|
|
PipeFDs
|
|
|
|
|
2018-05-03 21:05:25 +00:00
|
|
|
// Uname is a pointer to a struct uname, formatted after syscall execution.
|
2018-04-27 17:37:02 +00:00
|
|
|
Uname
|
|
|
|
|
|
|
|
// Stat is a pointer to a struct stat, formatted after syscall execution.
|
|
|
|
Stat
|
|
|
|
|
|
|
|
// SockAddr is a pointer to a struct sockaddr. The following arg is
|
|
|
|
// used for length.
|
|
|
|
SockAddr
|
|
|
|
|
|
|
|
// PostSockAddr is a pointer to a struct sockaddr, formatted after
|
|
|
|
// syscall execution. The following arg is a pointer to the socklen_t
|
|
|
|
// length.
|
|
|
|
PostSockAddr
|
|
|
|
|
|
|
|
// SockLen is a pointer to a socklen_t, formatted before and after
|
|
|
|
// syscall execution.
|
|
|
|
SockLen
|
|
|
|
|
|
|
|
// SockFamily is a socket protocol family value.
|
|
|
|
SockFamily
|
|
|
|
|
|
|
|
// SockType is a socket type and flags value.
|
|
|
|
SockType
|
|
|
|
|
|
|
|
// SockProtocol is a socket protocol value. Argument n-2 is the socket
|
|
|
|
// protocol family.
|
|
|
|
SockProtocol
|
|
|
|
|
|
|
|
// SockFlags are socket flags.
|
|
|
|
SockFlags
|
|
|
|
|
|
|
|
// Timespec is a pointer to a struct timespec.
|
|
|
|
Timespec
|
|
|
|
|
|
|
|
// PostTimespec is a pointer to a struct timespec, formatted after
|
|
|
|
// syscall execution.
|
|
|
|
PostTimespec
|
|
|
|
|
|
|
|
// UTimeTimespec is a pointer to a struct timespec. Formatting includes
|
|
|
|
// UTIME_NOW and UTIME_OMIT.
|
|
|
|
UTimeTimespec
|
|
|
|
|
|
|
|
// ItimerVal is a pointer to a struct itimerval.
|
|
|
|
ItimerVal
|
|
|
|
|
2018-09-13 21:06:34 +00:00
|
|
|
// PostItimerVal is a pointer to a struct itimerval, formatted after
|
2018-04-27 17:37:02 +00:00
|
|
|
// syscall execution.
|
|
|
|
PostItimerVal
|
|
|
|
|
2018-09-13 21:06:34 +00:00
|
|
|
// ItimerSpec is a pointer to a struct itimerspec.
|
|
|
|
ItimerSpec
|
|
|
|
|
|
|
|
// PostItimerSpec is a pointer to a struct itimerspec, formatted after
|
|
|
|
// syscall execution.
|
|
|
|
PostItimerSpec
|
|
|
|
|
2018-04-27 17:37:02 +00:00
|
|
|
// Timeval is a pointer to a struct timeval, formatted before and after
|
|
|
|
// syscall execution.
|
|
|
|
Timeval
|
|
|
|
|
|
|
|
// Utimbuf is a pointer to a struct utimbuf.
|
|
|
|
Utimbuf
|
|
|
|
|
2018-10-01 21:15:52 +00:00
|
|
|
// Rusage is a struct rusage, formatted after syscall execution.
|
|
|
|
Rusage
|
|
|
|
|
2018-04-27 17:37:02 +00:00
|
|
|
// CloneFlags are clone(2) flags.
|
|
|
|
CloneFlags
|
|
|
|
|
|
|
|
// OpenFlags are open(2) flags.
|
|
|
|
OpenFlags
|
|
|
|
|
|
|
|
// Mode is a mode_t.
|
|
|
|
Mode
|
|
|
|
|
|
|
|
// FutexOp is the futex(2) operation.
|
|
|
|
FutexOp
|
|
|
|
|
|
|
|
// PtraceRequest is the ptrace(2) request.
|
|
|
|
PtraceRequest
|
|
|
|
|
2018-10-01 21:15:52 +00:00
|
|
|
// ItimerType is an itimer type (ITIMER_REAL, etc).
|
|
|
|
ItimerType
|
Format signals, signal masks in strace
Sample:
I1205 16:51:49.869701 2492 x:0] [ 1] ioctl_test E rt_sigaction(SIGIO, 0x7e0e5b5e8500, 0x7e0e5b5e85a0)
I1205 16:51:49.869766 2492 x:0] [ 1] ioctl_test X rt_sigaction(SIGIO, 0x7e0e5b5e8500, 0x7e0e5b5e85a0) = 0x0 (44.336?s)
I1205 16:51:49.869831 2492 x:0] [ 1] ioctl_test E rt_sigprocmask(SIG_UNBLOCK, 0x7e0e5b5e8878 [SIGIO], 0x7e0e5b5e87c0, 0x8)
I1205 16:51:49.869866 2492 x:0] [ 1] ioctl_test X rt_sigprocmask(SIG_UNBLOCK, 0x7e0e5b5e8878 [SIGIO], 0x7e0e5b5e87c0 [SIGIO 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64], 0x8) = 0x0 (2.575?s)
PiperOrigin-RevId: 224422404
Change-Id: I3ed3f2ec6b1a639baa9cacd37ce7ee325c3703e4
2018-12-06 23:46:20 +00:00
|
|
|
|
|
|
|
// 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
|
Format sigaction in strace
Sample:
I1206 14:24:56.768520 3700 x:0] [ 1] ioctl_test E rt_sigaction(SIGSEGV, 0x7ee6edb0c590 {Handler: 0x559c6d915cf0, Flags: SA_SIGINFO|SA_RESTORER|SA_ONSTACK|SA_NODEFER, Restorer: 0x2a9901a259a0, Mask: []}, 0x7ee6edb0c630)
I1206 14:24:56.768530 3700 x:0] [ 1] ioctl_test X rt_sigaction(SIGSEGV, 0x7ee6edb0c590 {Handler: 0x559c6d915cf0, Flags: SA_SIGINFO|SA_RESTORER|SA_ONSTACK|SA_NODEFER, Restorer: 0x2a9901a259a0, Mask: []}, 0x7ee6edb0c630 {Handler: SIG_DFL, Flags: 0x0, Restorer: 0x0, Mask: []}) = 0x0 (2.701?s)
PiperOrigin-RevId: 224596606
Change-Id: I3512493aed99d3d75600249263da46686b1dc0e7
2018-12-08 00:27:35 +00:00
|
|
|
|
|
|
|
// SigAction is a struct sigaction.
|
|
|
|
SigAction
|
|
|
|
|
|
|
|
// PostSigAction is a struct sigaction, formatted after syscall execution.
|
|
|
|
PostSigAction
|
Format capget/capset arguments
I0225 15:32:10.795034 4166 x:0] [ 6] E capget(0x7f477fdff8c8 {Version: 3, Pid: 0}, 0x7f477fdff8b0)
I0225 15:32:10.795059 4166 x:0] [ 6] X capget(0x7f477fdff8c8 {Version: 3, Pid: 0}, 0x7f477fdff8b0 {Permitted: CAP_CHOWN|CAP_DAC_OVERRIDE|CAP_DAC_READ_SEARCH|CAP_FOWNER|CAP_FSETID|CAP_KILL|CAP_SETGID|CAP_SETUID|CAP_SETPCAP|CAP_LINUX_IMMUTABLE|CAP_NET_BIND_SERVICE|CAP_NET_BROADCAST|CAP_NET_ADMIN|CAP_NET_RAW|CAP_IPC_LOCK|CAP_IPC_OWNER|CAP_SYS_MODULE|CAP_SYS_RAWIO|CAP_SYS_CHROOT|CAP_SYS_PTRACE|CAP_SYS_PACCT|CAP_SYS_ADMIN|CAP_SYS_BOOT|CAP_SYS_NICE|CAP_SYS_RESOURCE|CAP_SYS_TIME|CAP_SYS_TTY_CONFIG|CAP_MKNOD|CAP_LEASE|CAP_AUDIT_WRITE|CAP_AUDIT_CONTROL|CAP_SETFCAP|CAP_MAC_OVERRIDE|CAP_MAC_ADMIN|CAP_SYSLOG|CAP_WAKE_ALARM|CAP_BLOCK_SUSPEND|CAP_AUDIT_READ, Inheritable: CAP_CHOWN|CAP_DAC_OVERRIDE|CAP_DAC_READ_SEARCH|CAP_FOWNER|CAP_FSETID|CAP_KILL|CAP_SETGID|CAP_SETUID|CAP_SETPCAP|CAP_LINUX_IMMUTABLE|CAP_NET_BIND_SERVICE|CAP_NET_BROADCAST|CAP_NET_ADMIN|CAP_NET_RAW|CAP_IPC_LOCK|CAP_IPC_OWNER|CAP_SYS_MODULE|CAP_SYS_RAWIO|CAP_SYS_CHROOT|CAP_SYS_PTRACE|CAP_SYS_PACCT|CAP_SYS_ADMIN|CAP_SYS_BOOT|CAP_SYS_NICE|CAP_SYS_RESOURCE|CAP_SYS_TIME|CAP_SYS_TTY_CONFIG|CAP_MKNOD|CAP_LEASE|CAP_AUDIT_WRITE|CAP_AUDIT_CONTROL|CAP_SETFCAP|CAP_MAC_OVERRIDE|CAP_MAC_ADMIN|CAP_SYSLOG|CAP_WAKE_ALARM|CAP_BLOCK_SUSPEND|CAP_AUDIT_READ, Effective: 0x0}) = 0x0 (3.399?s)
I0225 15:32:10.795114 4166 x:0] [ 6] E capset(0x7f477fdff8c8 {Version: 3, Pid: 0}, 0x7f477fdff8b0 {Permitted: CAP_CHOWN|CAP_DAC_OVERRIDE|CAP_DAC_READ_SEARCH|CAP_FOWNER|CAP_FSETID|CAP_KILL|CAP_SETGID|CAP_SETUID|CAP_SETPCAP|CAP_LINUX_IMMUTABLE|CAP_NET_BIND_SERVICE|CAP_NET_BROADCAST|CAP_NET_ADMIN|CAP_NET_RAW|CAP_IPC_LOCK|CAP_IPC_OWNER|CAP_SYS_MODULE|CAP_SYS_RAWIO|CAP_SYS_CHROOT|CAP_SYS_PTRACE|CAP_SYS_PACCT|CAP_SYS_ADMIN|CAP_SYS_BOOT|CAP_SYS_NICE|CAP_SYS_RESOURCE|CAP_SYS_TIME|CAP_SYS_TTY_CONFIG|CAP_MKNOD|CAP_LEASE|CAP_AUDIT_WRITE|CAP_AUDIT_CONTROL|CAP_SETFCAP|CAP_MAC_OVERRIDE|CAP_MAC_ADMIN|CAP_SYSLOG|CAP_WAKE_ALARM|CAP_BLOCK_SUSPEND|CAP_AUDIT_READ, Inheritable: CAP_CHOWN|CAP_DAC_OVERRIDE|CAP_DAC_READ_SEARCH|CAP_FOWNER|CAP_FSETID|CAP_KILL|CAP_SETGID|CAP_SETUID|CAP_SETPCAP|CAP_LINUX_IMMUTABLE|CAP_NET_BIND_SERVICE|CAP_NET_BROADCAST|CAP_NET_ADMIN|CAP_NET_RAW|CAP_IPC_LOCK|CAP_IPC_OWNER|CAP_SYS_MODULE|CAP_SYS_RAWIO|CAP_SYS_CHROOT|CAP_SYS_PTRACE|CAP_SYS_PACCT|CAP_SYS_ADMIN|CAP_SYS_BOOT|CAP_SYS_NICE|CAP_SYS_RESOURCE|CAP_SYS_TIME|CAP_SYS_TTY_CONFIG|CAP_MKNOD|CAP_LEASE|CAP_AUDIT_WRITE|CAP_AUDIT_CONTROL|CAP_SETFCAP|CAP_MAC_OVERRIDE|CAP_MAC_ADMIN|CAP_SYSLOG|CAP_WAKE_ALARM|CAP_BLOCK_SUSPEND|CAP_AUDIT_READ, Effective: CAP_FOWNER})
I0225 15:32:10.795127 4166 x:0] [ 6] X capset(0x7f477fdff8c8 {Version: 3, Pid: 0}, 0x7f477fdff8b0 {Permitted: CAP_CHOWN|CAP_DAC_OVERRIDE|CAP_DAC_READ_SEARCH|CAP_FOWNER|CAP_FSETID|CAP_KILL|CAP_SETGID|CAP_SETUID|CAP_SETPCAP|CAP_LINUX_IMMUTABLE|CAP_NET_BIND_SERVICE|CAP_NET_BROADCAST|CAP_NET_ADMIN|CAP_NET_RAW|CAP_IPC_LOCK|CAP_IPC_OWNER|CAP_SYS_MODULE|CAP_SYS_RAWIO|CAP_SYS_CHROOT|CAP_SYS_PTRACE|CAP_SYS_PACCT|CAP_SYS_ADMIN|CAP_SYS_BOOT|CAP_SYS_NICE|CAP_SYS_RESOURCE|CAP_SYS_TIME|CAP_SYS_TTY_CONFIG|CAP_MKNOD|CAP_LEASE|CAP_AUDIT_WRITE|CAP_AUDIT_CONTROL|CAP_SETFCAP|CAP_MAC_OVERRIDE|CAP_MAC_ADMIN|CAP_SYSLOG|CAP_WAKE_ALARM|CAP_BLOCK_SUSPEND|CAP_AUDIT_READ, Inheritable: CAP_CHOWN|CAP_DAC_OVERRIDE|CAP_DAC_READ_SEARCH|CAP_FOWNER|CAP_FSETID|CAP_KILL|CAP_SETGID|CAP_SETUID|CAP_SETPCAP|CAP_LINUX_IMMUTABLE|CAP_NET_BIND_SERVICE|CAP_NET_BROADCAST|CAP_NET_ADMIN|CAP_NET_RAW|CAP_IPC_LOCK|CAP_IPC_OWNER|CAP_SYS_MODULE|CAP_SYS_RAWIO|CAP_SYS_CHROOT|CAP_SYS_PTRACE|CAP_SYS_PACCT|CAP_SYS_ADMIN|CAP_SYS_BOOT|CAP_SYS_NICE|CAP_SYS_RESOURCE|CAP_SYS_TIME|CAP_SYS_TTY_CONFIG|CAP_MKNOD|CAP_LEASE|CAP_AUDIT_WRITE|CAP_AUDIT_CONTROL|CAP_SETFCAP|CAP_MAC_OVERRIDE|CAP_MAC_ADMIN|CAP_SYSLOG|CAP_WAKE_ALARM|CAP_BLOCK_SUSPEND|CAP_AUDIT_READ, Effective: CAP_FOWNER}) = 0x0 (3.062?s)
Not the most readable, but better than just a pointer.
PiperOrigin-RevId: 236338875
Change-Id: I4b83f778122ab98de3874e16f4258dae18da916b
2019-03-01 18:45:04 +00:00
|
|
|
|
|
|
|
// CapHeader is a cap_user_header_t.
|
|
|
|
CapHeader
|
|
|
|
|
|
|
|
// CapData is the data argument to capget(2)/capset(2). The previous
|
|
|
|
// argument must be CapHeader.
|
|
|
|
CapData
|
|
|
|
|
|
|
|
// PostCapData is the data argument to capget(2)/capset(2), formatted
|
|
|
|
// after syscall execution. The previous argument must be CapHeader.
|
|
|
|
PostCapData
|
2019-04-18 22:22:47 +00:00
|
|
|
|
|
|
|
// PollFDs is an array of struct pollfd. The number of entries in the
|
|
|
|
// array is in the next argument.
|
|
|
|
PollFDs
|
2018-04-27 17:37:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// defaultFormat is the syscall argument format to use if the actual format is
|
|
|
|
// not known. It formats all six arguments as hex.
|
|
|
|
var defaultFormat = []FormatSpecifier{Hex, Hex, Hex, Hex, Hex, Hex}
|
|
|
|
|
|
|
|
// SyscallInfo captures the name and printing format of a syscall.
|
|
|
|
type SyscallInfo struct {
|
|
|
|
// name is the name of the syscall.
|
|
|
|
name string
|
|
|
|
|
|
|
|
// format contains the format specifiers for each argument.
|
|
|
|
//
|
|
|
|
// Syscall calls can have up to six arguments. Arguments without a
|
|
|
|
// corresponding entry in format will not be printed.
|
|
|
|
format []FormatSpecifier
|
|
|
|
}
|
|
|
|
|
|
|
|
// makeSyscallInfo returns a SyscallInfo for a syscall.
|
|
|
|
func makeSyscallInfo(name string, f ...FormatSpecifier) SyscallInfo {
|
|
|
|
return SyscallInfo{name: name, format: f}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SyscallMap maps syscalls into names and printing formats.
|
|
|
|
type SyscallMap map[uintptr]SyscallInfo
|
|
|
|
|
|
|
|
var _ kernel.Stracer = (SyscallMap)(nil)
|
|
|
|
|
|
|
|
// syscallTable contains the syscalls for a specific OS/Arch.
|
|
|
|
type syscallTable struct {
|
|
|
|
// os is the operating system this table targets.
|
|
|
|
os abi.OS
|
|
|
|
|
|
|
|
// arch is the architecture this table targets.
|
|
|
|
arch arch.Arch
|
|
|
|
|
|
|
|
// syscalls contains the syscall mappings.
|
|
|
|
syscalls SyscallMap
|
|
|
|
}
|
|
|
|
|
|
|
|
// syscallTables contains all syscall tables.
|
|
|
|
var syscallTables = []syscallTable{
|
|
|
|
{
|
|
|
|
os: abi.Linux,
|
|
|
|
arch: arch.AMD64,
|
|
|
|
syscalls: linuxAMD64,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lookup returns the SyscallMap for the OS/Arch combination. The returned map
|
|
|
|
// must not be changed.
|
|
|
|
func Lookup(os abi.OS, a arch.Arch) (SyscallMap, bool) {
|
|
|
|
for _, s := range syscallTables {
|
|
|
|
if s.os == os && s.arch == a {
|
|
|
|
return s.syscalls, true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, false
|
|
|
|
}
|