Skip to content

Commit a04e9a9

Browse files
committed
os: ignore SIGSYS in checkPidfd
In Android version 11 and earlier, pidfd-related system calls are not allowed by the seccomp policy, which causes crashes due to SIGSYS signals. Fixes #69065
1 parent 165bf24 commit a04e9a9

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/os/pidfd_linux.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ var checkPidfdOnce = sync.OnceValue(checkPidfd)
151151
// execution environment in which the above system calls are restricted by
152152
// seccomp or a similar technology.
153153
func checkPidfd() error {
154+
// In Android version < 12, pidfd-related system calls are not allowed by seccomp and trigger the SIGSYS signal.
155+
ignoreSIGSYS()
156+
defer restoreSIGSYS()
157+
154158
// Get a pidfd of the current process (opening of "/proc/self" won't
155159
// work for waitid).
156160
fd, err := unix.PidFDOpen(syscall.Getpid(), 0)
@@ -192,3 +196,9 @@ func checkPidfd() error {
192196
//
193197
//go:linkname checkClonePidfd
194198
func checkClonePidfd() error
199+
200+
//go:linkname ignoreSIGSYS runtime.ignoreSIGSYS
201+
func ignoreSIGSYS()
202+
203+
//go:linkname restoreSIGSYS runtime.restoreSIGSYS
204+
func restoreSIGSYS()

src/runtime/signal_unix.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,19 @@ var crashing atomic.Int32
605605
var testSigtrap func(info *siginfo, ctxt *sigctxt, gp *g) bool
606606
var testSigusr1 func(gp *g) bool
607607

608+
// sigsysIgnored is non-zero if we are currently ignoring SIGSYS.
609+
var sigsysIgnored uint32
610+
611+
//go:linkname ignoreSIGSYS
612+
func ignoreSIGSYS() {
613+
atomic.Store(&sigsysIgnored, 1)
614+
}
615+
616+
//go:linkname restoreSIGSYS
617+
func restoreSIGSYS() {
618+
atomic.Store(&sigsysIgnored, 0)
619+
}
620+
608621
// sighandler is invoked when a signal occurs. The global g will be
609622
// set to a gsignal goroutine and we will be running on the alternate
610623
// signal stack. The parameter gp will be the value of the global g
@@ -715,6 +728,10 @@ func sighandler(sig uint32, info *siginfo, ctxt unsafe.Pointer, gp *g) {
715728
return
716729
}
717730

731+
if sig == _SIGSYS && atomic.Load(&sigsysIgnored) != 0 {
732+
return
733+
}
734+
718735
if flags&_SigKill != 0 {
719736
dieFromSignal(sig)
720737
}

0 commit comments

Comments
 (0)