summaryrefslogtreecommitdiffhomepage
path: root/pkg
diff options
context:
space:
mode:
authorJamie Liu <jamieliu@google.com>2018-07-10 13:58:00 -0700
committerShentubot <shentubot@google.com>2018-07-10 13:58:54 -0700
commit06920b3d1bb6346a20aa0e154b14e68116919dbc (patch)
tree4e70e7ce124368765fa99d115e6b9e104554cfb8 /pkg
parentbf580cf64dbea1c70a3269914fad6490f7a4968d (diff)
Exit tmpfs.fileInodeOperations.Translate early if required.Start >= EOF.
Otherwise required and optional can be empty or have negative length. PiperOrigin-RevId: 204007079 Change-Id: I59e472a87a8caac11ffb9a914b8d79bf0cd70995
Diffstat (limited to 'pkg')
-rw-r--r--pkg/sentry/fs/tmpfs/inode_file.go14
1 files changed, 10 insertions, 4 deletions
diff --git a/pkg/sentry/fs/tmpfs/inode_file.go b/pkg/sentry/fs/tmpfs/inode_file.go
index 66bc934ae..4e803c9ff 100644
--- a/pkg/sentry/fs/tmpfs/inode_file.go
+++ b/pkg/sentry/fs/tmpfs/inode_file.go
@@ -451,9 +451,12 @@ func (f *fileInodeOperations) Translate(ctx context.Context, required, optional
// Constrain translations to f.attr.Unstable.Size (rounded up) to prevent
// translation to pages that may be concurrently truncated.
pgend := fs.OffsetPageEnd(f.attr.Unstable.Size)
- var buserr error
+ var beyondEOF bool
if required.End > pgend {
- buserr = &memmap.BusError{io.EOF}
+ if required.Start >= pgend {
+ return nil, &memmap.BusError{io.EOF}
+ }
+ beyondEOF = true
required.End = pgend
}
if optional.End > pgend {
@@ -481,9 +484,12 @@ func (f *fileInodeOperations) Translate(ctx context.Context, required, optional
// Don't return the error returned by f.data.Fill if it occurred outside of
// required.
if translatedEnd < required.End && cerr != nil {
- return ts, cerr
+ return ts, &memmap.BusError{cerr}
+ }
+ if beyondEOF {
+ return ts, &memmap.BusError{io.EOF}
}
- return ts, buserr
+ return ts, nil
}
// InvalidateUnsavable implements memmap.Mappable.InvalidateUnsavable.