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:
parent
069f1edbe4
commit
248e46f320
|
@ -9,6 +9,7 @@ go_library(
|
|||
"ioctl_unsafe.go",
|
||||
"tty.go",
|
||||
"util.go",
|
||||
"util_unsafe.go",
|
||||
],
|
||||
visibility = ["//pkg/sentry:internal"],
|
||||
deps = [
|
||||
|
|
|
@ -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 {
|
||||
timestamps := []unix.Timespec{
|
||||
ts := [2]syscall.Timespec{
|
||||
toTimespec(s.Atime, m&linux.STATX_ATIME == 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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,15 +22,15 @@ import (
|
|||
"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 {
|
||||
return unix.Timespec{
|
||||
return syscall.Timespec{
|
||||
Sec: 0,
|
||||
Nsec: unix.UTIME_OMIT,
|
||||
}
|
||||
}
|
||||
return unix.Timespec{
|
||||
Sec: int64(ts.Sec),
|
||||
return syscall.Timespec{
|
||||
Sec: ts.Sec,
|
||||
Nsec: int64(ts.Nsec),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -291,6 +291,14 @@ var allowedSyscalls = seccomp.SyscallRules{
|
|||
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: {},
|
||||
// The only user in rawfile.NonBlockingWrite3 always passes iovcnt with
|
||||
// values 2 or 3. Three iovec-s are passed, when the PACKET_VNET_HDR
|
||||
|
|
Loading…
Reference in New Issue