systrap: don't fail if seccomp_unotify isn't supported

Fixes #10633

PiperOrigin-RevId: 652717946
This commit is contained in:
Andrei Vagin
2024-07-15 23:54:37 -07:00
committed by gVisor bot
parent 6e9ad24d64
commit 940cd91305
3 changed files with 25 additions and 5 deletions
+15
View File
@@ -178,6 +178,21 @@ type subprocess struct {
dead atomicbitops.Bool
}
var seccompNotifyIsSupported = false
func initSeccompNotify() {
_, _, errno := unix.Syscall(seccomp.SYS_SECCOMP, linux.SECCOMP_SET_MODE_FILTER, linux.SECCOMP_FILTER_FLAG_NEW_LISTENER, 0)
switch errno {
case unix.EFAULT:
// seccomp unotify is supported.
case unix.EINVAL:
log.Warningf("Seccomp user-space notification mechanism isn't " +
"supported by the kernel (available since Linux 5.0).")
default:
panic(fmt.Sprintf("seccomp returns unexpected code: %d", errno))
}
}
func (s *subprocess) initSyscallThread(ptraceThread *thread, seccompNotify bool) error {
s.syscallThreadMu.Lock()
defer s.syscallThreadMu.Unlock()
@@ -97,8 +97,11 @@ func (t *syscallThread) init(seccompNotify bool) error {
return err
}
if seccompNotify {
t.seccompNotify = t.installSeccompNotify()
if seccompNotify && seccompNotifyIsSupported {
if t.seccompNotify, err = t.installSeccompNotify(); err != nil {
t.destroy()
return fmt.Errorf("failed to install seccomp notify rules: %w", err)
}
}
// Map the stack into the sentry.
@@ -142,19 +145,19 @@ func (t *syscallThread) destroy() {
t.subproc.sysmsgStackPool.Put(t.thread.sysmsgStackID)
}
func (t *syscallThread) installSeccompNotify() *os.File {
func (t *syscallThread) installSeccompNotify() (*os.File, error) {
fd, err := t.thread.syscallIgnoreInterrupt(&t.thread.initRegs, seccomp.SYS_SECCOMP,
arch.SyscallArgument{Value: uintptr(linux.SECCOMP_SET_MODE_FILTER)},
arch.SyscallArgument{Value: uintptr(linux.SECCOMP_FILTER_FLAG_NEW_LISTENER)},
arch.SyscallArgument{Value: stubSyscallRules})
if err != nil {
panic(fmt.Sprintf("seccomp failed: %v", err))
return nil, err
}
_, _, errno := unix.RawSyscall(unix.SYS_IOCTL, fd, linux.SECCOMP_IOCTL_NOTIF_SET_FLAGS, linux.SECCOMP_USER_NOTIF_FD_SYNC_WAKE_UP)
if errno != 0 {
t.thread.Debugf("failed to set SECCOMP_USER_NOTIF_FD_SYNC_WAKE_UP")
}
return os.NewFile(fd, "seccomp_notify")
return os.NewFile(fd, "seccomp_notify"), nil
}
// mapMessageIntoStub maps the syscall message into the stub process address space.
+2
View File
@@ -350,6 +350,8 @@ func New() (*Systrap, error) {
globalPool.source = source
initSysmsgThreadPriority()
initSeccompNotify()
})
latencyMonitoring.Do(func() {