diff options
author | Tamir Duberstein <tamird@google.com> | 2021-01-28 17:38:47 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-01-28 17:41:02 -0800 |
commit | c99e092a3bb986b03fd85d426e166ef2c73a8c51 (patch) | |
tree | ab1871187abfd6f90056075d7b71c298619e81bf | |
parent | 56fb2ec1194bff7c57c7bbb84b7b74f63142b915 (diff) |
Propagate reader error in ReadFrom
This was removed in 6c0e1d9cfe6adbfbb32e7020d6426608ac63ad37 but turns
out to be crucial to prevent flaky behaviour in sendfile.
PiperOrigin-RevId: 354434144
-rw-r--r-- | pkg/sentry/socket/netstack/netstack.go | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/pkg/sentry/socket/netstack/netstack.go b/pkg/sentry/socket/netstack/netstack.go index 3115a227d..30a31ef4c 100644 --- a/pkg/sentry/socket/netstack/netstack.go +++ b/pkg/sentry/socket/netstack/netstack.go @@ -459,17 +459,24 @@ func (s *SocketOperations) Write(ctx context.Context, _ *fs.File, src usermem.IO var _ tcpip.Payloader = (*limitedPayloader)(nil) type limitedPayloader struct { - io.LimitedReader + inner io.LimitedReader + err error } -func (l limitedPayloader) Len() int { - return int(l.N) +func (l *limitedPayloader) Read(p []byte) (int, error) { + n, err := l.inner.Read(p) + l.err = err + return n, err +} + +func (l *limitedPayloader) Len() int { + return int(l.inner.N) } // ReadFrom implements fs.FileOperations.ReadFrom. func (s *SocketOperations) ReadFrom(ctx context.Context, _ *fs.File, r io.Reader, count int64) (int64, error) { f := limitedPayloader{ - LimitedReader: io.LimitedReader{ + inner: io.LimitedReader{ R: r, N: count, }, @@ -480,7 +487,7 @@ func (s *SocketOperations) ReadFrom(ctx context.Context, _ *fs.File, r io.Reader Atomic: true, }) if err == tcpip.ErrBadBuffer { - err = nil + return n, f.err } return n, syserr.TranslateNetstackError(err).ToError() } |