summaryrefslogtreecommitdiff
path: root/internal/syscallcompat
diff options
context:
space:
mode:
authorJakob Unterwurzacher2017-12-06 00:05:28 +0100
committerJakob Unterwurzacher2017-12-06 00:06:31 +0100
commita3bdc2bf2b7b7ed34e2d68fc698e1dd136f2e67a (patch)
tree1f651ae683806188716b9cf212edb66d5571bb41 /internal/syscallcompat
parent03bf604fc08abc9bb2d75bde21c96c9df4894a3b (diff)
fusefrontend_reverse: secure GetAttr against symlink races
...by using the OpenNofollow helper & Fstatat. Also introduce a helper to convert from unix.Stat_t to syscall.Stat_t. Tracking ticket: https://github.com/rfjakob/gocryptfs/issues/165
Diffstat (limited to 'internal/syscallcompat')
-rw-r--r--internal/syscallcompat/unix2syscall.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/internal/syscallcompat/unix2syscall.go b/internal/syscallcompat/unix2syscall.go
new file mode 100644
index 0000000..3162025
--- /dev/null
+++ b/internal/syscallcompat/unix2syscall.go
@@ -0,0 +1,28 @@
+package syscallcompat
+
+import (
+ "syscall"
+
+ "golang.org/x/sys/unix"
+)
+
+// Unix2syscall converts a unix.Stat_t struct to a syscall.Stat_t struct.
+// A direct cast does not work because the padding is named differently in
+// unix.Stat_t for some reason ("X__unused" in syscall, "_" in unix).
+func Unix2syscall(u unix.Stat_t) syscall.Stat_t {
+ return syscall.Stat_t{
+ Dev: u.Dev,
+ Ino: u.Ino,
+ Nlink: u.Nlink,
+ Mode: u.Mode,
+ Uid: u.Uid,
+ Gid: u.Gid,
+ Rdev: u.Rdev,
+ Size: u.Size,
+ Blksize: u.Blksize,
+ Blocks: u.Blocks,
+ Atim: syscall.Timespec(u.Atim),
+ Mtim: syscall.Timespec(u.Mtim),
+ Ctim: syscall.Timespec(u.Ctim),
+ }
+}