diff --git a/pkg/sentry/devices/tpuproxy/seccomp_filter.go b/pkg/sentry/devices/tpuproxy/seccomp_filter.go index 4bedfc830..18bd2a299 100644 --- a/pkg/sentry/devices/tpuproxy/seccomp_filter.go +++ b/pkg/sentry/devices/tpuproxy/seccomp_filter.go @@ -52,6 +52,8 @@ func Filters() seccomp.SyscallRules { seccomp.AnyValue{}, seccomp.EqualTo(0), }, + unix.SYS_PREAD64: seccomp.MatchAll{}, + unix.SYS_PWRITE64: seccomp.MatchAll{}, unix.SYS_IOCTL: seccomp.Or{ seccomp.PerArg{ seccomp.NonNegativeFD{}, diff --git a/pkg/sentry/devices/tpuproxy/tpu.go b/pkg/sentry/devices/tpuproxy/tpu.go index 8cd612ab8..faef39be5 100644 --- a/pkg/sentry/devices/tpuproxy/tpu.go +++ b/pkg/sentry/devices/tpuproxy/tpu.go @@ -393,3 +393,31 @@ func (fd *pciDeviceFD) vfioSetIrqs(ctx context.Context, t *kernel.Task, arg host // No data type is specified or multiple data types are specified. return 0, linuxerr.EINVAL } + +// PRead implements vfs.FileDescriptionImpl.PRead. +func (fd *pciDeviceFD) PRead(ctx context.Context, dst usermem.IOSequence, offset int64, opts vfs.ReadOptions) (int64, error) { + if offset < 0 { + return 0, linuxerr.EINVAL + } + buf := make([]byte, dst.NumBytes()) + _, err := unix.Pread(int(fd.hostFD), buf, offset) + if err != nil { + return 0, err + } + n, err := dst.CopyOut(ctx, buf) + return int64(n), err +} + +// PWrite implements vfs.FileDescriptionImpl.PWrite. +func (fd *pciDeviceFD) PWrite(ctx context.Context, src usermem.IOSequence, offset int64, opts vfs.WriteOptions) (int64, error) { + if offset < 0 { + return 0, linuxerr.EINVAL + } + buf := make([]byte, src.NumBytes()) + _, err := src.CopyIn(ctx, buf) + if err != nil { + return 0, err + } + n, err := unix.Pwrite(int(fd.hostFD), buf, offset) + return int64(n), err +}