Whitelist utimensat(2).

utimensat is used by hostfs for setting timestamps on imported fds. Previously,
this would crash the sandbox since utimensat was not allowed.

Correct the VFS2 version of hostfs to match the call in VFS1.

PiperOrigin-RevId: 301970121
This commit is contained in:
Dean Deng 2020-03-19 23:29:15 -07:00 committed by gVisor bot
parent 069f1edbe4
commit 248e46f320
5 changed files with 49 additions and 6 deletions

View File

@ -9,6 +9,7 @@ go_library(
"ioctl_unsafe.go", "ioctl_unsafe.go",
"tty.go", "tty.go",
"util.go", "util.go",
"util_unsafe.go",
], ],
visibility = ["//pkg/sentry:internal"], visibility = ["//pkg/sentry:internal"],
deps = [ deps = [

View File

@ -322,11 +322,11 @@ func (i *inode) SetStat(ctx context.Context, fs *vfs.Filesystem, creds *auth.Cre
} }
} }
if m&(linux.STATX_ATIME|linux.STATX_MTIME) != 0 { if m&(linux.STATX_ATIME|linux.STATX_MTIME) != 0 {
timestamps := []unix.Timespec{ ts := [2]syscall.Timespec{
toTimespec(s.Atime, m&linux.STATX_ATIME == 0), toTimespec(s.Atime, m&linux.STATX_ATIME == 0),
toTimespec(s.Mtime, m&linux.STATX_MTIME == 0), toTimespec(s.Mtime, m&linux.STATX_MTIME == 0),
} }
if err := unix.UtimesNanoAt(i.hostFD, "", timestamps, unix.AT_EMPTY_PATH); err != nil { if err := setTimestamps(i.hostFD, &ts); err != nil {
return err return err
} }
} }

View File

@ -22,15 +22,15 @@ import (
"gvisor.dev/gvisor/pkg/syserror" "gvisor.dev/gvisor/pkg/syserror"
) )
func toTimespec(ts linux.StatxTimestamp, omit bool) unix.Timespec { func toTimespec(ts linux.StatxTimestamp, omit bool) syscall.Timespec {
if omit { if omit {
return unix.Timespec{ return syscall.Timespec{
Sec: 0, Sec: 0,
Nsec: unix.UTIME_OMIT, Nsec: unix.UTIME_OMIT,
} }
} }
return unix.Timespec{ return syscall.Timespec{
Sec: int64(ts.Sec), Sec: ts.Sec,
Nsec: int64(ts.Nsec), Nsec: int64(ts.Nsec),
} }
} }

View File

@ -0,0 +1,34 @@
// Copyright 2020 The gVisor Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package host
import (
"syscall"
"unsafe"
)
func setTimestamps(fd int, ts *[2]syscall.Timespec) error {
_, _, errno := syscall.Syscall6(
syscall.SYS_UTIMENSAT,
uintptr(fd),
0, /* path */
uintptr(unsafe.Pointer(ts)),
0, /* flags */
0, 0)
if errno != 0 {
return errno
}
return nil
}

View File

@ -291,6 +291,14 @@ var allowedSyscalls = seccomp.SyscallRules{
seccomp.AllowValue(uint64(os.Getpid())), seccomp.AllowValue(uint64(os.Getpid())),
}, },
}, },
syscall.SYS_UTIMENSAT: []seccomp.Rule{
{
seccomp.AllowAny{},
seccomp.AllowValue(0), /* null pathname */
seccomp.AllowAny{},
seccomp.AllowValue(0), /* flags */
},
},
syscall.SYS_WRITE: {}, syscall.SYS_WRITE: {},
// The only user in rawfile.NonBlockingWrite3 always passes iovcnt with // The only user in rawfile.NonBlockingWrite3 always passes iovcnt with
// values 2 or 3. Three iovec-s are passed, when the PACKET_VNET_HDR // values 2 or 3. Three iovec-s are passed, when the PACKET_VNET_HDR