From 5a6aadda2f17e1d91582260ff28b0a9ba2024256 Mon Sep 17 00:00:00 2001 From: Jing Chen Date: Wed, 20 Mar 2024 01:21:46 -0700 Subject: [PATCH] Change the way gVisor TPUProxy passes string arguments to IOCTL syscalls. Passing the address of the string can't be recognized by the syscall, the syscall expects the address to the first byte of the string which is NUL-terminated. PiperOrigin-RevId: 617430240 --- pkg/sentry/devices/tpuproxy/tpu.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/sentry/devices/tpuproxy/tpu.go b/pkg/sentry/devices/tpuproxy/tpu.go index 59f509cba..0a558a05e 100644 --- a/pkg/sentry/devices/tpuproxy/tpu.go +++ b/pkg/sentry/devices/tpuproxy/tpu.go @@ -124,7 +124,14 @@ func (fd *tpuFD) getPciDeviceFd(t *kernel.Task, arg hostarch.Addr) (uintptr, fun if err != nil { return 0, func() {}, err } - hostFD, err := IOCTLInvokePtrArg[uint32](fd.hostFD, linux.VFIO_GROUP_GET_DEVICE_FD, &pciAddress) + // Build a NUL-terminated slice of bytes containing the PCI address. + pciAddressBytes, err := unix.ByteSliceFromString(pciAddress) + if err != nil { + return 0, func() {}, err + } + // Pass the address of the PCI address' first byte which can be + // recognized by the IOCTL syscall. + hostFD, err := IOCTLInvokePtrArg[uint32](fd.hostFD, linux.VFIO_GROUP_GET_DEVICE_FD, &pciAddressBytes[0]) if err != nil { return 0, func() {}, err }