diff --git a/pkg/abi/nvgpu/classes.go b/pkg/abi/nvgpu/classes.go index a1c19a0a65..a25d0f88e5 100644 --- a/pkg/abi/nvgpu/classes.go +++ b/pkg/abi/nvgpu/classes.go @@ -183,6 +183,12 @@ type NV_CHANNEL_ALLOC_PARAMS struct { ECCErrorNotifierMem NV_MEMORY_DESC_PARAMS ProcessID uint32 SubProcessID uint32 + // IV used for CPU-side encryption / GPU-side decryption. + EncryptIv [3]uint32 + // IV used for CPU-side decryption / GPU-side encryption. + DecryptIv [3]uint32 + // Nonce used CPU-side signing / GPU-side signature verification. + HmacNonce [8]uint32 } // NVB0B5_ALLOCATION_PARAMETERS is the alloc param type for TURING_DMA_COPY_A, diff --git a/pkg/sentry/devices/nvproxy/uvm.go b/pkg/sentry/devices/nvproxy/uvm.go index e46e2546da..a7dafcaa31 100644 --- a/pkg/sentry/devices/nvproxy/uvm.go +++ b/pkg/sentry/devices/nvproxy/uvm.go @@ -16,6 +16,7 @@ package nvproxy import ( "fmt" + "os" "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/abi/nvgpu" @@ -163,11 +164,12 @@ func uvmIoctlNoParams(ui *uvmIoctlState) (uintptr, error) { return uvmIoctlInvoke[byte](ui, nil) } -func uvmIoctlSimple[Params any, PParams marshalPtr[Params]](ui *uvmIoctlState) (uintptr, error) { +func uvmIoctlSimple[Params any, PParams marshalPtr[Params]](ui *uvmIoctlState) (foo uintptr, retErr error) { var ioctlParams Params if _, err := (PParams)(&ioctlParams).CopyIn(ui.t, ui.ioctlParamsAddr); err != nil { return 0, err } + n, err := uvmIoctlInvoke(ui, &ioctlParams) if err != nil { return n, err @@ -175,6 +177,22 @@ func uvmIoctlSimple[Params any, PParams marshalPtr[Params]](ui *uvmIoctlState) ( if _, err := (PParams)(&ioctlParams).CopyOut(ui.t, ui.ioctlParamsAddr); err != nil { return n, err } + + castedOut, ok := any(ioctlParams).(nvgpu.UVM_VALIDATE_VA_RANGE_PARAMS) + if ok { + ui.ctx.Debugf("UVM_VALIDATE_VA Out: 0x%x, 0x%x, 0x%x", castedOut.Base, castedOut.Length, castedOut.RMStatus) + + if castedOut.Length == 0x3ab000 { + ui.ctx.Debugf("sleeping for 1hr") + var foo string + fmt.Scanf("reading text %s\n", &foo) + } + // data, err := os.ReadFile("/proc/self/maps") + // if err == nil { + // ui.ctx.Debugf("%s", data) + // } + // ui.ctx.Debugf("ReadFile: %s", err) + } return n, nil } @@ -245,7 +263,12 @@ type hasRMCtrlFDPtr[T any] interface { nvgpu.HasRMCtrlFD } -func uvmIoctlHasRMCtrlFD[Params any, PParams hasRMCtrlFDPtr[Params]](ui *uvmIoctlState) (uintptr, error) { +func uvmIoctlHasRMCtrlFD[Params any, PParams hasRMCtrlFDPtr[Params]](ui *uvmIoctlState) (tmp uintptr, retErr error) { + fmt.Fprintf(os.Stderr, "uvmIoctlHasRMCtrlFD\n") + defer func(){ + fmt.Fprintf(os.Stderr, "uvmIoctlHasRMCtrlFD retErr: %s\n", retErr) + }() + var ioctlParams Params if _, err := (PParams)(&ioctlParams).CopyIn(ui.t, ui.ioctlParamsAddr); err != nil { return 0, err @@ -260,6 +283,11 @@ func uvmIoctlHasRMCtrlFD[Params any, PParams hasRMCtrlFDPtr[Params]](ui *uvmIoct if _, err := (PParams)(&ioctlParams).CopyOut(ui.t, ui.ioctlParamsAddr); err != nil { return n, err } + + // tmpSlice := make([]byte, 64) + // _ = (PParams)(&ioctlParams).MarshalBytes(tmpSlice) + // fmt.Fprintf(os.Stderr, "HELLOFROMVUM: 0x%x, 0x%x\n", tmpSlice[0:16], tmpSlice[36:40]) + return n, nil } @@ -286,5 +314,9 @@ func uvmIoctlHasRMCtrlFD[Params any, PParams hasRMCtrlFDPtr[Params]](ui *uvmIoct return n, err } + // tmpSlice := make([]byte, 64) + // _ = (PParams)(&outIoctlParams).MarshalBytes(tmpSlice) + // fmt.Fprintf(os.Stderr, "HELLOFROMVUM: 0x%x, 0x%x\n", tmpSlice[0:16], tmpSlice[36:40]) + return n, nil } diff --git a/pkg/sentry/kernel/task.go b/pkg/sentry/kernel/task.go index c0af03092e..73a64155fa 100644 --- a/pkg/sentry/kernel/task.go +++ b/pkg/sentry/kernel/task.go @@ -602,6 +602,10 @@ type Task struct { sessionKeyring *auth.Key } +func (t *Task) LogPrefix() string { + return (t.logPrefix.Load()).(string) +} + // Task related metrics var ( // syscallCounter is a metric that tracks how many syscalls the sentry has diff --git a/pkg/sentry/platform/ptrace/subprocess.go b/pkg/sentry/platform/ptrace/subprocess.go index 8f8364c2ea..3e59e1d353 100644 --- a/pkg/sentry/platform/ptrace/subprocess.go +++ b/pkg/sentry/platform/ptrace/subprocess.go @@ -484,7 +484,8 @@ func (t *thread) syscall(regs *arch.Registers) (uintptr, error) { func (t *thread) syscallIgnoreInterrupt( initRegs *arch.Registers, sysno uintptr, - args ...arch.SyscallArgument) (uintptr, error) { + args ...arch.SyscallArgument, +) (uintptr, error) { for { regs := createSyscallRegs(initRegs, sysno, args...) rval, err := t.syscall(®s) @@ -639,6 +640,9 @@ func (s *subprocess) MapFile(addr hostarch.Addr, f memmap.File, fr memmap.FileRa if precommit { flags |= unix.MAP_POPULATE } + + fmt.Printf("subprocess.MapFile: addr %x, prot %x, flags %x\n", addr, at.Prot(), flags) + _, err := s.syscall( unix.SYS_MMAP, arch.SyscallArgument{Value: uintptr(addr)}, diff --git a/pkg/sentry/syscalls/linux/sys_mmap.go b/pkg/sentry/syscalls/linux/sys_mmap.go index 2da71232fe..81200e27ac 100644 --- a/pkg/sentry/syscalls/linux/sys_mmap.go +++ b/pkg/sentry/syscalls/linux/sys_mmap.go @@ -16,6 +16,7 @@ package linux import ( "bytes" + "fmt" "gvisor.dev/gvisor/pkg/abi/linux" "gvisor.dev/gvisor/pkg/errors/linuxerr" @@ -47,6 +48,8 @@ func Mmap(t *kernel.Task, sysno uintptr, args arch.SyscallArguments) (uintptr, * anon := flags&linux.MAP_ANONYMOUS != 0 map32bit := flags&linux.MAP_32BIT != 0 + fmt.Printf("mmap entry: addr 0x%x, prot 0x%x, flags 0x%x\n", args[0].Pointer(), prot, flags) + // Require exactly one of MAP_PRIVATE and MAP_SHARED. if private == shared { return 0, nil, linuxerr.EINVAL