From 06920b3d1bb6346a20aa0e154b14e68116919dbc Mon Sep 17 00:00:00 2001 From: Jamie Liu Date: Tue, 10 Jul 2018 13:58:00 -0700 Subject: 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 --- pkg/sentry/fs/tmpfs/inode_file.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'pkg/sentry/fs') 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. -- cgit v1.2.3