From 4d8c7ae869a4e9bf60c7ea9aff79a0bee551fbc9 Mon Sep 17 00:00:00 2001 From: Zach Koopmans Date: Thu, 6 Dec 2018 09:25:57 -0800 Subject: Fixing O_TRUNC behavior to match Linux. PiperOrigin-RevId: 224351139 Change-Id: I9453bd75e5a8d38db406bb47fdc01038ac60922e --- pkg/sentry/syscalls/linux/flags.go | 3 +++ pkg/sentry/syscalls/linux/sys_file.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'pkg') 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 } -- cgit v1.2.3