From 4a0bf841d90f4a9e7f512692b80a343451235501 Mon Sep 17 00:00:00 2001 From: Konstantin Bogomolov Date: Tue, 1 Oct 2024 10:25:54 -0700 Subject: [PATCH] Don't return r2 from RawSyscalls. In practice we don't seem to ever use it. PiperOrigin-RevId: 681073641 --- pkg/hostsyscall/hostsyscall.go | 4 ++-- pkg/hostsyscall/hostsyscall_amd64.s | 20 ++++++++----------- pkg/hostsyscall/hostsyscall_arm64.s | 20 ++++++++----------- .../platform/kvm/machine_amd64_unsafe.go | 2 +- .../platform/kvm/machine_arm64_unsafe.go | 2 +- 5 files changed, 20 insertions(+), 28 deletions(-) diff --git a/pkg/hostsyscall/hostsyscall.go b/pkg/hostsyscall/hostsyscall.go index bf1881be1..c4c70a1e1 100644 --- a/pkg/hostsyscall/hostsyscall.go +++ b/pkg/hostsyscall/hostsyscall.go @@ -28,10 +28,10 @@ import ( ) // RawSyscall6 is a copy of runtime.Syscall6. -func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, errno unix.Errno) +func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1 uintptr, errno unix.Errno) // RawSyscall is a copy of runtime.Syscall6, but only uses the first three arguments. -func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, errno unix.Errno) +func RawSyscall(trap, a1, a2, a3 uintptr) (r1 uintptr, errno unix.Errno) // Variants of runtime.Syscall6 that use slightly less stack space by only // returning errno. diff --git a/pkg/hostsyscall/hostsyscall_amd64.s b/pkg/hostsyscall/hostsyscall_amd64.s index 80444c8f2..fa5f4dd26 100644 --- a/pkg/hostsyscall/hostsyscall_amd64.s +++ b/pkg/hostsyscall/hostsyscall_amd64.s @@ -14,8 +14,8 @@ #include "textflag.h" -// func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, errno) -TEXT ·RawSyscall6(SB),NOSPLIT,$0-80 +// func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, errno) +TEXT ·RawSyscall6(SB),NOSPLIT,$0-72 MOVQ a1+8(FP), DI MOVQ a2+16(FP), SI MOVQ a3+24(FP), DX @@ -27,18 +27,16 @@ TEXT ·RawSyscall6(SB),NOSPLIT,$0-80 CMPQ AX, $0xfffffffffffff001 JLS ok MOVQ $-1, r1+56(FP) - MOVQ $0, r2+64(FP) NEGQ AX - MOVQ AX, errno+72(FP) + MOVQ AX, errno+64(FP) RET ok: MOVQ AX, r1+56(FP) - MOVQ DX, r2+64(FP) - MOVQ $0, errno+72(FP) + MOVQ $0, errno+64(FP) RET -// func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2, errno) -TEXT ·RawSyscall(SB),NOSPLIT,$0-56 +// func RawSyscall(trap, a1, a2, a3 uintptr) (r1, errno) +TEXT ·RawSyscall(SB),NOSPLIT,$0-48 MOVQ a1+8(FP), DI MOVQ a2+16(FP), SI MOVQ a3+24(FP), DX @@ -50,14 +48,12 @@ TEXT ·RawSyscall(SB),NOSPLIT,$0-56 CMPQ AX, $0xfffffffffffff001 JLS ok MOVQ $-1, r1+32(FP) - MOVQ $0, r2+40(FP) NEGQ AX - MOVQ AX, errno+48(FP) + MOVQ AX, errno+40(FP) RET ok: MOVQ AX, r1+32(FP) - MOVQ DX, r2+40(FP) - MOVQ $0, errno+48(FP) + MOVQ $0, errno+40(FP) RET diff --git a/pkg/hostsyscall/hostsyscall_arm64.s b/pkg/hostsyscall/hostsyscall_arm64.s index 6477d6f3d..1d0beed16 100644 --- a/pkg/hostsyscall/hostsyscall_arm64.s +++ b/pkg/hostsyscall/hostsyscall_arm64.s @@ -14,8 +14,8 @@ #include "textflag.h" -// func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, errno uintptr) -TEXT ·RawSyscall6(SB),NOSPLIT,$0-80 +// func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, errno) +TEXT ·RawSyscall6(SB),NOSPLIT,$0-72 MOVD trap+0(FP), R8 // syscall entry MOVD a1+8(FP), R0 MOVD a2+16(FP), R1 @@ -28,18 +28,16 @@ TEXT ·RawSyscall6(SB),NOSPLIT,$0-80 BCC ok MOVD $-1, R4 MOVD R4, r1+56(FP) - MOVD ZR, r2+64(FP) NEG R0, R0 - MOVD R0, errno+72(FP) + MOVD R0, errno+64(FP) RET ok: MOVD R0, r1+56(FP) - MOVD R1, r2+64(FP) - MOVD ZR, errno+72(FP) + MOVD ZR, errno+64(FP) RET -// func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2, errno uintptr) -TEXT ·RawSyscall(SB),NOSPLIT,$0-56 +// func RawSyscall(trap, a1, a2, a3 uintptr) (r1, errno) +TEXT ·RawSyscall(SB),NOSPLIT,$0-48 MOVD trap+0(FP), R8 // syscall entry MOVD a1+8(FP), R0 MOVD a2+16(FP), R1 @@ -52,14 +50,12 @@ TEXT ·RawSyscall(SB),NOSPLIT,$0-56 BCC ok MOVD $-1, R4 MOVD R4, r1+32(FP) - MOVD ZR, r2+40(FP) NEG R0, R0 - MOVD R0, errno+48(FP) + MOVD R0, errno+40(FP) RET ok: MOVD R0, r1+32(FP) - MOVD R1, r2+40(FP) - MOVD ZR, errno+48(FP) + MOVD ZR, errno+40(FP) RET // func RawSyscallErrno6(trap, a1, a2, a3, a4, a5, a6 uintptr) (errno unix.Errno) diff --git a/pkg/sentry/platform/kvm/machine_amd64_unsafe.go b/pkg/sentry/platform/kvm/machine_amd64_unsafe.go index aff0b13d8..d5394813d 100644 --- a/pkg/sentry/platform/kvm/machine_amd64_unsafe.go +++ b/pkg/sentry/platform/kvm/machine_amd64_unsafe.go @@ -190,7 +190,7 @@ func seccompMmapSyscall(context unsafe.Pointer) (uintptr, uintptr, unix.Errno) { ctx := bluepillArchContext(context) // MAP_DENYWRITE is deprecated and ignored by kernel. We use it only for seccomp filters. - addr, _, e := hostsyscall.RawSyscall6(uintptr(ctx.Rax), uintptr(ctx.Rdi), uintptr(ctx.Rsi), + addr, e := hostsyscall.RawSyscall6(uintptr(ctx.Rax), uintptr(ctx.Rdi), uintptr(ctx.Rsi), uintptr(ctx.Rdx), uintptr(ctx.R10)|unix.MAP_DENYWRITE, uintptr(ctx.R8), uintptr(ctx.R9)) ctx.Rax = uint64(addr) diff --git a/pkg/sentry/platform/kvm/machine_arm64_unsafe.go b/pkg/sentry/platform/kvm/machine_arm64_unsafe.go index dbfe9f525..950f914a9 100644 --- a/pkg/sentry/platform/kvm/machine_arm64_unsafe.go +++ b/pkg/sentry/platform/kvm/machine_arm64_unsafe.go @@ -355,7 +355,7 @@ func seccompMmapSyscall(context unsafe.Pointer) (uintptr, uintptr, unix.Errno) { ctx := bluepillArchContext(context) // MAP_DENYWRITE is deprecated and ignored by kernel. We use it only for seccomp filters. - addr, _, e := hostsyscall.RawSyscall6(uintptr(ctx.Regs[8]), uintptr(ctx.Regs[0]), uintptr(ctx.Regs[1]), + addr, e := hostsyscall.RawSyscall6(uintptr(ctx.Regs[8]), uintptr(ctx.Regs[0]), uintptr(ctx.Regs[1]), uintptr(ctx.Regs[2]), uintptr(ctx.Regs[3])|unix.MAP_DENYWRITE, uintptr(ctx.Regs[4]), uintptr(ctx.Regs[5])) ctx.Regs[0] = uint64(addr)