summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/sentry')
-rw-r--r--pkg/sentry/fs/flags.go6
-rw-r--r--pkg/sentry/syscalls/linux/flags.go59
-rw-r--r--pkg/sentry/syscalls/linux/sys_file.go2
3 files changed, 39 insertions, 28 deletions
diff --git a/pkg/sentry/fs/flags.go b/pkg/sentry/fs/flags.go
index 7a8eefd02..810452584 100644
--- a/pkg/sentry/fs/flags.go
+++ b/pkg/sentry/fs/flags.go
@@ -45,6 +45,12 @@ type FileFlags struct {
// Async indicates that this file sends signals on IO events.
Async bool
+
+ // LargeFile indicates that this file should be opened even if it has
+ // size greater than linux's off_t. When running in 64-bit mode,
+ // Linux sets this flag for all files. Since gVisor is only compatible
+ // with 64-bit Linux, it also sets this flag for all files.
+ LargeFile bool
}
// SettableFileFlags is a subset of FileFlags above that can be changed
diff --git a/pkg/sentry/syscalls/linux/flags.go b/pkg/sentry/syscalls/linux/flags.go
index 3d39a20f4..b2e173f3e 100644
--- a/pkg/sentry/syscalls/linux/flags.go
+++ b/pkg/sentry/syscalls/linux/flags.go
@@ -15,8 +15,7 @@
package linux
import (
- "syscall"
-
+ "gvisor.googlesource.com/gvisor/pkg/abi/linux"
"gvisor.googlesource.com/gvisor/pkg/sentry/fs"
"gvisor.googlesource.com/gvisor/pkg/sentry/kernel"
)
@@ -24,13 +23,13 @@ import (
// flagsToPermissions returns a Permissions object from Linux flags.
// This includes truncate permission if O_TRUNC is set in the mask.
func flagsToPermissions(mask uint) (p fs.PermMask) {
- switch mask & syscall.O_ACCMODE {
- case syscall.O_WRONLY:
+ switch mask & linux.O_ACCMODE {
+ case linux.O_WRONLY:
p.Write = true
- case syscall.O_RDWR:
+ case linux.O_RDWR:
p.Write = true
p.Read = true
- case syscall.O_RDONLY:
+ case linux.O_RDONLY:
p.Read = true
}
return
@@ -39,7 +38,7 @@ func flagsToPermissions(mask uint) (p fs.PermMask) {
// fdFlagsToLinux converts a kernel.FDFlags object to a Linux representation.
func fdFlagsToLinux(flags kernel.FDFlags) (mask uint) {
if flags.CloseOnExec {
- mask |= syscall.FD_CLOEXEC
+ mask |= linux.FD_CLOEXEC
}
return
}
@@ -47,30 +46,33 @@ func fdFlagsToLinux(flags kernel.FDFlags) (mask uint) {
// flagsToLinux converts a FileFlags object to a Linux representation.
func flagsToLinux(flags fs.FileFlags) (mask uint) {
if flags.Direct {
- mask |= syscall.O_DIRECT
+ mask |= linux.O_DIRECT
}
if flags.NonBlocking {
- mask |= syscall.O_NONBLOCK
+ mask |= linux.O_NONBLOCK
}
if flags.Sync {
- mask |= syscall.O_SYNC
+ mask |= linux.O_SYNC
}
if flags.Append {
- mask |= syscall.O_APPEND
+ mask |= linux.O_APPEND
}
if flags.Directory {
- mask |= syscall.O_DIRECTORY
+ mask |= linux.O_DIRECTORY
}
if flags.Async {
- mask |= syscall.O_ASYNC
+ mask |= linux.O_ASYNC
+ }
+ if flags.LargeFile {
+ mask |= linux.O_LARGEFILE
}
switch {
case flags.Read && flags.Write:
- mask |= syscall.O_RDWR
+ mask |= linux.O_RDWR
case flags.Write:
- mask |= syscall.O_WRONLY
+ mask |= linux.O_WRONLY
case flags.Read:
- mask |= syscall.O_RDONLY
+ mask |= linux.O_RDONLY
}
return
}
@@ -78,23 +80,24 @@ func flagsToLinux(flags fs.FileFlags) (mask uint) {
// linuxToFlags converts linux file flags to a FileFlags object.
func linuxToFlags(mask uint) (flags fs.FileFlags) {
return fs.FileFlags{
- Direct: mask&syscall.O_DIRECT != 0,
- Sync: mask&syscall.O_SYNC != 0,
- NonBlocking: mask&syscall.O_NONBLOCK != 0,
- Read: (mask & syscall.O_ACCMODE) != syscall.O_WRONLY,
- Write: (mask & syscall.O_ACCMODE) != syscall.O_RDONLY,
- Append: mask&syscall.O_APPEND != 0,
- Directory: mask&syscall.O_DIRECTORY != 0,
- Async: mask&syscall.O_ASYNC != 0,
+ Direct: mask&linux.O_DIRECT != 0,
+ Sync: mask&linux.O_SYNC != 0,
+ NonBlocking: mask&linux.O_NONBLOCK != 0,
+ Read: (mask & linux.O_ACCMODE) != linux.O_WRONLY,
+ Write: (mask & linux.O_ACCMODE) != linux.O_RDONLY,
+ Append: mask&linux.O_APPEND != 0,
+ Directory: mask&linux.O_DIRECTORY != 0,
+ Async: mask&linux.O_ASYNC != 0,
+ LargeFile: mask&linux.O_LARGEFILE != 0,
}
}
// linuxToSettableFlags converts linux file flags to a SettableFileFlags object.
func linuxToSettableFlags(mask uint) fs.SettableFileFlags {
return fs.SettableFileFlags{
- Direct: mask&syscall.O_DIRECT != 0,
- NonBlocking: mask&syscall.O_NONBLOCK != 0,
- Append: mask&syscall.O_APPEND != 0,
- Async: mask&syscall.O_ASYNC != 0,
+ Direct: mask&linux.O_DIRECT != 0,
+ NonBlocking: mask&linux.O_NONBLOCK != 0,
+ Append: mask&linux.O_APPEND != 0,
+ Async: mask&linux.O_ASYNC != 0,
}
}
diff --git a/pkg/sentry/syscalls/linux/sys_file.go b/pkg/sentry/syscalls/linux/sys_file.go
index 66e6fd9d4..2f28fbea6 100644
--- a/pkg/sentry/syscalls/linux/sys_file.go
+++ b/pkg/sentry/syscalls/linux/sys_file.go
@@ -148,6 +148,8 @@ func openAt(t *kernel.Task, dirFD kdefs.FD, addr usermem.Addr, flags uint) (fd u
}
fileFlags := linuxToFlags(flags)
+ // Linux always adds the O_LARGEFILE flag when running in 64-bit mode.
+ fileFlags.LargeFile = true
if fs.IsDir(d.Inode.StableAttr) {
// Don't allow directories to be opened writable.
if fileFlags.Write {