summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/syscalls/linux
diff options
context:
space:
mode:
authorZach Koopmans <zkoopmans@google.com>2018-12-06 09:25:57 -0800
committerShentubot <shentubot@google.com>2018-12-06 09:26:49 -0800
commit4d8c7ae869a4e9bf60c7ea9aff79a0bee551fbc9 (patch)
treec751dc61f391bb5b56d077e9b1fb8598125159ad /pkg/sentry/syscalls/linux
parent7f35daddd2cabef2e7ffb6899e1a54ff8c0475c6 (diff)
Fixing O_TRUNC behavior to match Linux.
PiperOrigin-RevId: 224351139 Change-Id: I9453bd75e5a8d38db406bb47fdc01038ac60922e
Diffstat (limited to 'pkg/sentry/syscalls/linux')
-rw-r--r--pkg/sentry/syscalls/linux/flags.go3
-rw-r--r--pkg/sentry/syscalls/linux/sys_file.go2
2 files changed, 4 insertions, 1 deletions
diff --git a/pkg/sentry/syscalls/linux/flags.go b/pkg/sentry/syscalls/linux/flags.go
index d1e0833fc..d2aec963a 100644
--- a/pkg/sentry/syscalls/linux/flags.go
+++ b/pkg/sentry/syscalls/linux/flags.go
@@ -22,6 +22,9 @@ 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) {
+ if mask&linux.O_TRUNC != 0 {
+ p.Write = true
+ }
switch mask & linux.O_ACCMODE {
case linux.O_WRONLY:
p.Write = true
diff --git a/pkg/sentry/syscalls/linux/sys_file.go b/pkg/sentry/syscalls/linux/sys_file.go
index 8673bca0d..7ad0c9517 100644
--- a/pkg/sentry/syscalls/linux/sys_file.go
+++ b/pkg/sentry/syscalls/linux/sys_file.go
@@ -170,7 +170,7 @@ func openAt(t *kernel.Task, dirFD kdefs.FD, addr usermem.Addr, flags uint) (fd u
if dirPath {
return syserror.ENOTDIR
}
- if fileFlags.Write && flags&linux.O_TRUNC != 0 {
+ if flags&linux.O_TRUNC != 0 {
if err := d.Inode.Truncate(t, d, 0); err != nil {
return err
}