From 8c9cbf0d9090c0473144d83376ec92f717ed5ba9 Mon Sep 17 00:00:00 2001 From: Andrei Vagin Date: Sun, 31 Mar 2024 02:27:38 -0700 Subject: [PATCH] systrap: handle syscall errors PiperOrigin-RevId: 620610190 --- pkg/sentry/platform/systrap/syscall_thread.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/sentry/platform/systrap/syscall_thread.go b/pkg/sentry/platform/systrap/syscall_thread.go index dd9b80af0..2dfdd96b7 100644 --- a/pkg/sentry/platform/systrap/syscall_thread.go +++ b/pkg/sentry/platform/systrap/syscall_thread.go @@ -167,6 +167,8 @@ func (t *syscallThread) attach() error { return nil } +const maxErrno = 4095 + func (t *syscallThread) syscall(sysno uintptr, args ...arch.SyscallArgument) (uintptr, error) { if t.subproc.dead.Load() { return 0, errDeadSubprocess @@ -192,5 +194,10 @@ func (t *syscallThread) syscall(sysno uintptr, args ...arch.SyscallArgument) (ui // returns only only when the other side will call FUTEX_WAKE. futexWaitWake(&sentryMsg.state, atomic.LoadUint32(&sentryMsg.state)) + errno := -uintptr(stubMsg.ret) + if errno > 0 && errno < maxErrno { + return 0, fmt.Errorf("stub syscall (%x, %#v) failed with %w", sysno, args, unix.Errno(errno)) + } + return uintptr(stubMsg.ret), nil }