Skip to content

Commit dd96380

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 dd96380

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/os/pidfd_linux.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package os
1818
import (
1919
"errors"
2020
"internal/syscall/unix"
21+
"runtime"
2122
"sync"
2223
"syscall"
2324
"unsafe"
@@ -151,6 +152,12 @@ var checkPidfdOnce = sync.OnceValue(checkPidfd)
151152
// execution environment in which the above system calls are restricted by
152153
// seccomp or a similar technology.
153154
func checkPidfd() error {
155+
// In Android version < 12, pidfd-related system calls are not allowed by seccomp and trigger the SIGSYS signal. See issue #69065.
156+
if runtime.GOOS == "android" {
157+
ignoreSIGSYS()
158+
defer restoreSIGSYS()
159+
}
160+
154161
// Get a pidfd of the current process (opening of "/proc/self" won't
155162
// work for waitid).
156163
fd, err := unix.PidFDOpen(syscall.Getpid(), 0)
@@ -192,3 +199,9 @@ func checkPidfd() error {
192199
//
193200
//go:linkname checkClonePidfd
194201
func checkClonePidfd() error
202+
203+
//go:linkname ignoreSIGSYS
204+
func ignoreSIGSYS()
205+
206+
//go:linkname restoreSIGSYS
207+
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. See issue #69065.
609+
var sigsysIgnored uint32
610+
611+
//go:linkname ignoreSIGSYS os.ignoreSIGSYS
612+
func ignoreSIGSYS() {
613+
atomic.Store(&sigsysIgnored, 1)
614+
}
615+
616+
//go:linkname restoreSIGSYS os.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)