Skip to content

Commit 42e2e5c

Browse files
prattmicshentubot
authored andcommitted
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
1 parent 6739490 commit 42e2e5c

File tree

6 files changed

+89
-11
lines changed

6 files changed

+89
-11
lines changed

pkg/abi/flag.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ func (s FlagSet) Parse(val uint64) string {
4343
flags = append(flags, "0x"+strconv.FormatUint(val, 16))
4444
}
4545

46+
if len(flags) == 0 {
47+
// Prefer 0 to an empty string.
48+
return "0x0"
49+
}
50+
4651
return strings.Join(flags, "|")
4752
}
4853

pkg/abi/linux/signal.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,16 @@ const (
165165

166166
// Signal action flags for rt_sigaction(2), from uapi/asm-generic/signal.h
167167
const (
168-
SA_NOCLDSTOP = 0x00000001
169-
SA_NOCLDWAIT = 0x00000002
170-
SA_SIGINFO = 0x00000004
171-
SA_ONSTACK = 0x08000000
172-
SA_RESTART = 0x10000000
173-
SA_NODEFER = 0x40000000
174-
SA_RESTARTHAND = 0x80000000
175-
SA_NOMASK = SA_NODEFER
176-
SA_ONESHOT = SA_RESTARTHAND
168+
SA_NOCLDSTOP = 0x00000001
169+
SA_NOCLDWAIT = 0x00000002
170+
SA_SIGINFO = 0x00000004
171+
SA_RESTORER = 0x04000000
172+
SA_ONSTACK = 0x08000000
173+
SA_RESTART = 0x10000000
174+
SA_NODEFER = 0x40000000
175+
SA_RESETHAND = 0x80000000
176+
SA_NOMASK = SA_NODEFER
177+
SA_ONESHOT = SA_RESETHAND
177178
)
178179

179180
// Signal info types.

pkg/sentry/strace/linux64.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var linuxAMD64 = SyscallMap{
3030
10: makeSyscallInfo("mprotect", Hex, Hex, Hex),
3131
11: makeSyscallInfo("munmap", Hex, Hex),
3232
12: makeSyscallInfo("brk", Hex),
33-
13: makeSyscallInfo("rt_sigaction", Signal, Hex, Hex),
33+
13: makeSyscallInfo("rt_sigaction", Signal, SigAction, PostSigAction),
3434
14: makeSyscallInfo("rt_sigprocmask", SignalMaskAction, SigSet, PostSigSet, Hex),
3535
15: makeSyscallInfo("rt_sigreturn"),
3636
16: makeSyscallInfo("ioctl", Hex, Hex, Hex),

pkg/sentry/strace/signal.go

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,41 @@ var signalMaskActions = abi.ValueSet{
6565
linux.SIG_SETMASK: "SIG_SETMASK",
6666
}
6767

68+
var sigActionFlags = abi.FlagSet{
69+
{
70+
Flag: linux.SA_NOCLDSTOP,
71+
Name: "SA_NOCLDSTOP",
72+
},
73+
{
74+
Flag: linux.SA_NOCLDWAIT,
75+
Name: "SA_NOCLDWAIT",
76+
},
77+
{
78+
Flag: linux.SA_SIGINFO,
79+
Name: "SA_SIGINFO",
80+
},
81+
{
82+
Flag: linux.SA_RESTORER,
83+
Name: "SA_RESTORER",
84+
},
85+
{
86+
Flag: linux.SA_ONSTACK,
87+
Name: "SA_ONSTACK",
88+
},
89+
{
90+
Flag: linux.SA_RESTART,
91+
Name: "SA_RESTART",
92+
},
93+
{
94+
Flag: linux.SA_NODEFER,
95+
Name: "SA_NODEFER",
96+
},
97+
{
98+
Flag: linux.SA_RESETHAND,
99+
Name: "SA_RESETHAND",
100+
},
101+
}
102+
68103
func sigSet(t *kernel.Task, addr usermem.Addr) string {
69104
if addr == 0 {
70105
return "null"
@@ -77,10 +112,37 @@ func sigSet(t *kernel.Task, addr usermem.Addr) string {
77112

78113
set := linux.SignalSet(usermem.ByteOrder.Uint64(b[:]))
79114

115+
return fmt.Sprintf("%#x %s", addr, formatSigSet(set))
116+
}
117+
118+
func formatSigSet(set linux.SignalSet) string {
80119
var signals []string
81120
linux.ForEachSignal(set, func(sig linux.Signal) {
82121
signals = append(signals, signalNames.ParseDecimal(uint64(sig)))
83122
})
84123

85-
return fmt.Sprintf("%#x [%v]", addr, strings.Join(signals, " "))
124+
return fmt.Sprintf("[%v]", strings.Join(signals, " "))
125+
}
126+
127+
func sigAction(t *kernel.Task, addr usermem.Addr) string {
128+
if addr == 0 {
129+
return "null"
130+
}
131+
132+
sa, err := t.CopyInSignalAct(addr)
133+
if err != nil {
134+
return fmt.Sprintf("%#x (error copying sigaction: %v)", addr, err)
135+
}
136+
137+
var handler string
138+
switch sa.Handler {
139+
case linux.SIG_IGN:
140+
handler = "SIG_IGN"
141+
case linux.SIG_DFL:
142+
handler = "SIG_DFL"
143+
default:
144+
handler = fmt.Sprintf("%#x", sa.Handler)
145+
}
146+
147+
return fmt.Sprintf("%#x {Handler: %s, Flags: %s, Restorer: %#x, Mask: %s}", addr, handler, sigActionFlags.Parse(sa.Flags), sa.Restorer, formatSigSet(sa.Mask))
86148
}

pkg/sentry/strace/strace.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ func (i *SyscallInfo) pre(t *kernel.Task, args arch.SyscallArguments, maximumBlo
339339
output = append(output, signalMaskActions.Parse(uint64(args[arg].Int())))
340340
case SigSet:
341341
output = append(output, sigSet(t, args[arg].Pointer()))
342+
case SigAction:
343+
output = append(output, sigAction(t, args[arg].Pointer()))
342344
case Oct:
343345
output = append(output, "0o"+strconv.FormatUint(args[arg].Uint64(), 8))
344346
case Hex:
@@ -399,6 +401,8 @@ func (i *SyscallInfo) post(t *kernel.Task, args arch.SyscallArguments, rval uint
399401
output[arg] = rusage(t, args[arg].Pointer())
400402
case PostSigSet:
401403
output[arg] = sigSet(t, args[arg].Pointer())
404+
case PostSigAction:
405+
output[arg] = sigAction(t, args[arg].Pointer())
402406
}
403407
}
404408
}

pkg/sentry/strace/syscalls.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ const (
182182

183183
// PostSigSet is a signal set, formatted after syscall execution.
184184
PostSigSet
185+
186+
// SigAction is a struct sigaction.
187+
SigAction
188+
189+
// PostSigAction is a struct sigaction, formatted after syscall execution.
190+
PostSigAction
185191
)
186192

187193
// defaultFormat is the syscall argument format to use if the actual format is

0 commit comments

Comments
 (0)