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
This commit is contained in:
Jing Chen
2024-03-20 01:25:38 -07:00
committed by gVisor bot
parent 4a44f7d442
commit 5a6aadda2f
+8 -1
View File
@@ -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
}