summaryrefslogtreecommitdiffhomepage
path: root/runsc/fsgofer/fsgofer_unsafe.go
diff options
context:
space:
mode:
authorFabricio Voznika <fvoznika@google.com>2020-08-19 18:03:15 -0700
committerAndrei Vagin <avagin@gmail.com>2020-09-09 17:53:10 -0700
commit00ee4cb1a26d8f3cabbbb7fc05d719d8aabbee60 (patch)
treed68a1d75fd2f281b932212770bde241635a2102c /runsc/fsgofer/fsgofer_unsafe.go
parent59a394f856108dcb33f242a61ff6e1700161b4f3 (diff)
Remove path walk from localFile.Mknod
Replace mknod call with mknodat equivalent to protect against symlink attacks. Also added Mknod tests. Remove goferfs reliance on gofer to check for file existence before creating a synthetic entry. Updates #2923 PiperOrigin-RevId: 327544516
Diffstat (limited to 'runsc/fsgofer/fsgofer_unsafe.go')
-rw-r--r--runsc/fsgofer/fsgofer_unsafe.go18
1 files changed, 9 insertions, 9 deletions
diff --git a/runsc/fsgofer/fsgofer_unsafe.go b/runsc/fsgofer/fsgofer_unsafe.go
index 542b54365..f11fea40d 100644
--- a/runsc/fsgofer/fsgofer_unsafe.go
+++ b/runsc/fsgofer/fsgofer_unsafe.go
@@ -15,18 +15,18 @@
package fsgofer
import (
- "syscall"
"unsafe"
+ "golang.org/x/sys/unix"
"gvisor.dev/gvisor/pkg/syserr"
)
-func utimensat(dirFd int, name string, times [2]syscall.Timespec, flags int) error {
+func utimensat(dirFd int, name string, times [2]unix.Timespec, flags int) error {
// utimensat(2) doesn't accept empty name, instead name must be nil to make it
// operate directly on 'dirFd' unlike other *at syscalls.
var namePtr unsafe.Pointer
if name != "" {
- nameBytes, err := syscall.BytePtrFromString(name)
+ nameBytes, err := unix.BytePtrFromString(name)
if err != nil {
return err
}
@@ -35,8 +35,8 @@ func utimensat(dirFd int, name string, times [2]syscall.Timespec, flags int) err
timesPtr := unsafe.Pointer(&times[0])
- if _, _, errno := syscall.Syscall6(
- syscall.SYS_UTIMENSAT,
+ if _, _, errno := unix.Syscall6(
+ unix.SYS_UTIMENSAT,
uintptr(dirFd),
uintptr(namePtr),
uintptr(timesPtr),
@@ -52,7 +52,7 @@ func utimensat(dirFd int, name string, times [2]syscall.Timespec, flags int) err
func renameat(oldDirFD int, oldName string, newDirFD int, newName string) error {
var oldNamePtr unsafe.Pointer
if oldName != "" {
- nameBytes, err := syscall.BytePtrFromString(oldName)
+ nameBytes, err := unix.BytePtrFromString(oldName)
if err != nil {
return err
}
@@ -60,15 +60,15 @@ func renameat(oldDirFD int, oldName string, newDirFD int, newName string) error
}
var newNamePtr unsafe.Pointer
if newName != "" {
- nameBytes, err := syscall.BytePtrFromString(newName)
+ nameBytes, err := unix.BytePtrFromString(newName)
if err != nil {
return err
}
newNamePtr = unsafe.Pointer(nameBytes)
}
- if _, _, errno := syscall.Syscall6(
- syscall.SYS_RENAMEAT,
+ if _, _, errno := unix.Syscall6(
+ unix.SYS_RENAMEAT,
uintptr(oldDirFD),
uintptr(oldNamePtr),
uintptr(newDirFD),