diff options
author | gVisor bot <gvisor-bot@google.com> | 2020-01-29 01:07:21 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-01-29 01:07:21 +0000 |
commit | 3c4a7fb34fca7c949d3b6fdb47306f53a1531f75 (patch) | |
tree | f241b8efbaa4cadc07af331d09d462e6aed80c47 | |
parent | 0ff8f6cdad988e02ebee3cda89492038360b0173 (diff) | |
parent | 3d046fef06ece6ba20770fa62e0a21569226adaa (diff) |
Merge release-20200115.0-127-g3d046fe (automated)
-rw-r--r-- | pkg/sentry/kernel/fd_table.go | 18 | ||||
-rw-r--r-- | pkg/sentry/syscalls/linux/sys_read.go | 2 | ||||
-rwxr-xr-x | pkg/sentry/syscalls/linux/vfs2/sys_read.go | 16 |
3 files changed, 18 insertions, 18 deletions
diff --git a/pkg/sentry/kernel/fd_table.go b/pkg/sentry/kernel/fd_table.go index 56b70ce96..23b88f7a6 100644 --- a/pkg/sentry/kernel/fd_table.go +++ b/pkg/sentry/kernel/fd_table.go @@ -15,9 +15,9 @@ package kernel import ( - "bytes" "fmt" "math" + "strings" "sync/atomic" "syscall" @@ -221,24 +221,24 @@ func (f *FDTable) forEach(fn func(fd int32, file *fs.File, fileVFS2 *vfs.FileDes // String is a stringer for FDTable. func (f *FDTable) String() string { - var b bytes.Buffer + var buf strings.Builder f.forEach(func(fd int32, file *fs.File, fileVFS2 *vfs.FileDescription, flags FDFlags) { switch { case file != nil: n, _ := file.Dirent.FullName(nil /* root */) - b.WriteString(fmt.Sprintf("\tfd:%d => name %s\n", fd, n)) + fmt.Fprintf(&buf, "\tfd:%d => name %s\n", fd, n) case fileVFS2 != nil: - fs := fileVFS2.VirtualDentry().Mount().Filesystem().VirtualFilesystem() - // TODO(gvisor.dev/issue/1623): We have no context nor root. Will this work? - name, err := fs.PathnameWithDeleted(context.Background(), vfs.VirtualDentry{}, fileVFS2.VirtualDentry()) + vfsObj := fileVFS2.Mount().Filesystem().VirtualFilesystem() + name, err := vfsObj.PathnameWithDeleted(context.Background(), vfs.VirtualDentry{}, fileVFS2.VirtualDentry()) if err != nil { - b.WriteString(fmt.Sprintf("<err: %v>\n", err)) + fmt.Fprintf(&buf, "<err: %v>\n", err) + return } - b.WriteString(fmt.Sprintf("\tfd:%d => name %s\n", fd, name)) + fmt.Fprintf(&buf, "\tfd:%d => name %s\n", fd, name) } }) - return b.String() + return buf.String() } // NewFDs allocates new FDs guaranteed to be the lowest number available diff --git a/pkg/sentry/syscalls/linux/sys_read.go b/pkg/sentry/syscalls/linux/sys_read.go index f9f594190..227692f06 100644 --- a/pkg/sentry/syscalls/linux/sys_read.go +++ b/pkg/sentry/syscalls/linux/sys_read.go @@ -29,7 +29,7 @@ import ( ) const ( - // EventMaskRead contains events that can be triggerd on reads. + // EventMaskRead contains events that can be triggered on reads. EventMaskRead = waiter.EventIn | waiter.EventHUp | waiter.EventErr ) diff --git a/pkg/sentry/syscalls/linux/vfs2/sys_read.go b/pkg/sentry/syscalls/linux/vfs2/sys_read.go index b9fb58464..7667524c7 100755 --- a/pkg/sentry/syscalls/linux/vfs2/sys_read.go +++ b/pkg/sentry/syscalls/linux/vfs2/sys_read.go @@ -24,6 +24,11 @@ import ( "gvisor.dev/gvisor/pkg/waiter" ) +const ( + // EventMaskRead contains events that can be triggered on reads. + EventMaskRead = waiter.EventIn | waiter.EventHUp | waiter.EventErr +) + // Read implements linux syscall read(2). Note that we try to get a buffer that // is exactly the size requested because some applications like qemu expect // they can do large reads all at once. Bug for bug. Same for other read @@ -39,11 +44,6 @@ func Read(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel.SyscallC } defer file.DecRef() - // Check that the file is readable. - if !file.IsReadable() { - return 0, nil, syserror.EBADF - } - // Check that the size is legitimate. si := int(size) if si < 0 { @@ -70,8 +70,8 @@ func read(t *kernel.Task, file *vfs.FileDescription, dst usermem.IOSequence, opt } // Register for notifications. - _, ch := waiter.NewChannelEntry(nil) - // file.EventRegister(&w, EventMaskRead) + w, ch := waiter.NewChannelEntry(nil) + file.EventRegister(&w, EventMaskRead) total := n for { @@ -89,7 +89,7 @@ func read(t *kernel.Task, file *vfs.FileDescription, dst usermem.IOSequence, opt break } } - //file.EventUnregister(&w) + file.EventUnregister(&w) return total, err } |