diff options
author | Fabricio Voznika <fvoznika@google.com> | 2018-05-15 14:38:32 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2018-05-15 14:39:20 -0700 |
commit | 9889c29d6d26ba86b5e3590eac85bfb8393dd54e (patch) | |
tree | c28c99f01a67eab3441e30af8340ec97d107b1c5 | |
parent | 205f1027e6beb84101439172b3c776c2671b5be8 (diff) |
Fix problem with sendfile(2) writing less data
When the amount of data read is more than the amount written, sendfile would not
adjust 'in file' position and would resume from the wrong location.
Closes #33
PiperOrigin-RevId: 196731287
Change-Id: Ia219895dd765016ed9e571fd5b366963c99afb27
-rw-r--r-- | pkg/sentry/syscalls/linux/sys_file.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/pkg/sentry/syscalls/linux/sys_file.go b/pkg/sentry/syscalls/linux/sys_file.go index 5fbacc15e..1d61ac9f0 100644 --- a/pkg/sentry/syscalls/linux/sys_file.go +++ b/pkg/sentry/syscalls/linux/sys_file.go @@ -1929,8 +1929,16 @@ func Sendfile(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel.Sysc // If we don't have a provided offset. } else { // Send data using readv. + inOff := inFile.Offset() r := &io.LimitedReader{R: &fs.FileReader{t, inFile}, N: count} n, err = io.Copy(w, r) + inOff += n + if inFile.Offset() != inOff { + // Adjust file position in case more bytes were read than written. + if _, err := inFile.Seek(t, fs.SeekSet, inOff); err != nil { + return 0, nil, syserror.EIO + } + } } // We can only pass a single file to handleIOError, so pick inFile |