diff options
| author | Jakob Unterwurzacher | 2026-11-11 21:02:25 +0100 |
|---|---|---|
| committer | Jakob Unterwurzacher | 2026-11-11 21:02:25 +0100 |
| commit | d61448ec88f064eba898b566f68324859df5f7ac (patch) | |
| tree | 63f5831e405bd9a12d16129d0b1277883361d599 | |
| parent | 756cd453d7afe69fd2a00a7592fd2d9869a6f756 (diff) | |
syscallcompat: drop Faccessat helper, use unix.Faccessat with AT_SYMLINK_NOFOLLOW
Our helper did Fstatat(AT_SYMLINK_NOFOLLOW) followed by a symlink-following
unix.Faccessat(..., 0). If the file is swapped for a symlink in between, we
check access on the symlink target.
x/sys now handles AT_SYMLINK_NOFOLLOW on all our platforms: faccessat2 with
fallback emulation on Linux, libc faccessat on Darwin, and the native
syscall on FreeBSD. The Darwin breakage that caused the revert in
3d6b2685 should no longer apply.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| -rw-r--r-- | internal/fusefrontend/node.go | 2 | ||||
| -rw-r--r-- | internal/fusefrontend/prepare_syscall_test.go | 19 | ||||
| -rw-r--r-- | internal/syscallcompat/sys_common.go | 15 | ||||
| -rw-r--r-- | tests/reverse/correctness_test.go | 5 |
4 files changed, 12 insertions, 29 deletions
diff --git a/internal/fusefrontend/node.go b/internal/fusefrontend/node.go index c531876..4f6ae45 100644 --- a/internal/fusefrontend/node.go +++ b/internal/fusefrontend/node.go @@ -132,7 +132,7 @@ func (n *Node) Access(ctx context.Context, mode uint32) syscall.Errno { } defer syscall.Close(dirfd) - err := syscallcompat.Faccessat(dirfd, cName, mode) + err := unix.Faccessat(dirfd, cName, mode, unix.AT_SYMLINK_NOFOLLOW) return fs.ToErrno(err) } diff --git a/internal/fusefrontend/prepare_syscall_test.go b/internal/fusefrontend/prepare_syscall_test.go index e2c7d08..5945720 100644 --- a/internal/fusefrontend/prepare_syscall_test.go +++ b/internal/fusefrontend/prepare_syscall_test.go @@ -10,7 +10,6 @@ import ( "github.com/hanwen/go-fuse/v2/fuse" - "github.com/rfjakob/gocryptfs/v2/internal/syscallcompat" "github.com/rfjakob/gocryptfs/v2/tests/test_helpers" ) @@ -53,11 +52,11 @@ func TestPrepareAtSyscall(t *testing.T) { t.Fatal("cName should be .") } - err := syscallcompat.Faccessat(dirfd, cName, unix.R_OK) + err := unix.Faccessat(dirfd, cName, unix.R_OK, unix.AT_SYMLINK_NOFOLLOW) if err != nil { t.Error(err) } - err = syscallcompat.Faccessat(dirfd, ".", unix.R_OK) + err = unix.Faccessat(dirfd, ".", unix.R_OK, unix.AT_SYMLINK_NOFOLLOW) if err != nil { t.Error(err) } @@ -70,7 +69,7 @@ func TestPrepareAtSyscall(t *testing.T) { if cName == "" { t.Fatal("cName should not be empty") } - err = syscallcompat.Faccessat(dirfd, cName, unix.R_OK) + err = unix.Faccessat(dirfd, cName, unix.R_OK, unix.AT_SYMLINK_NOFOLLOW) if err != nil { t.Error(err) } @@ -83,7 +82,7 @@ func TestPrepareAtSyscall(t *testing.T) { if cName == "" { t.Fatal("cName should not be empty") } - err = syscallcompat.Faccessat(dirfd, cName, unix.R_OK) + err = unix.Faccessat(dirfd, cName, unix.R_OK, unix.AT_SYMLINK_NOFOLLOW) if err != nil { t.Errorf("Faccessat(%d, %q): %v", dirfd, cName, err) } @@ -101,7 +100,7 @@ func TestPrepareAtSyscall(t *testing.T) { if len(cName) >= 255 { t.Fatalf("cName is too long: %q", cName) } - err = syscallcompat.Faccessat(dirfd, cName, unix.R_OK) + err = unix.Faccessat(dirfd, cName, unix.R_OK, unix.AT_SYMLINK_NOFOLLOW) if err != nil { t.Errorf("Faccessat(%d, %q): %v", dirfd, cName, err) } @@ -135,11 +134,11 @@ func TestPrepareAtSyscallPlaintextnames(t *testing.T) { if cName != "." { t.Fatal("cName should be .") } - err := syscallcompat.Faccessat(dirfd, cName, unix.R_OK) + err := unix.Faccessat(dirfd, cName, unix.R_OK, unix.AT_SYMLINK_NOFOLLOW) if err != nil { t.Error(err) } - err = syscallcompat.Faccessat(dirfd, ".", unix.R_OK) + err = unix.Faccessat(dirfd, ".", unix.R_OK, unix.AT_SYMLINK_NOFOLLOW) if err != nil { t.Error(err) } @@ -152,7 +151,7 @@ func TestPrepareAtSyscallPlaintextnames(t *testing.T) { if cName != "dir1" { t.Fatalf("wrong cName: %q", cName) } - err = syscallcompat.Faccessat(dirfd, cName, unix.R_OK) + err = unix.Faccessat(dirfd, cName, unix.R_OK, unix.AT_SYMLINK_NOFOLLOW) if err != nil { t.Error(err) } @@ -165,7 +164,7 @@ func TestPrepareAtSyscallPlaintextnames(t *testing.T) { if cName != "dir2" { t.Fatalf("wrong cName: %q", cName) } - err = syscallcompat.Faccessat(dirfd, cName, unix.R_OK) + err = unix.Faccessat(dirfd, cName, unix.R_OK, unix.AT_SYMLINK_NOFOLLOW) if err != nil { t.Error(err) } diff --git a/internal/syscallcompat/sys_common.go b/internal/syscallcompat/sys_common.go index 4f84d98..bdd2dac 100644 --- a/internal/syscallcompat/sys_common.go +++ b/internal/syscallcompat/sys_common.go @@ -29,21 +29,6 @@ func Readlinkat(dirfd int, path string) (string, error) { } } -// Faccessat exists both in Linux and in MacOS 10.10+, but the Linux version -// DOES NOT support any flags. Emulate AT_SYMLINK_NOFOLLOW like glibc does. -func Faccessat(dirfd int, path string, mode uint32) error { - var st unix.Stat_t - err := Fstatat(dirfd, path, &st, unix.AT_SYMLINK_NOFOLLOW) - if err != nil { - return err - } - if st.Mode&syscall.S_IFMT == syscall.S_IFLNK { - // Pretend that a symlink is always accessible - return nil - } - return unix.Faccessat(dirfd, path, mode, 0) -} - // Openat wraps the Openat syscall. // Retries on EINTR. func Openat(dirfd int, path string, flags int, mode uint32) (fd int, err error) { diff --git a/tests/reverse/correctness_test.go b/tests/reverse/correctness_test.go index 4028ac3..f0c6f54 100644 --- a/tests/reverse/correctness_test.go +++ b/tests/reverse/correctness_test.go @@ -12,7 +12,6 @@ import ( "golang.org/x/sys/unix" "github.com/rfjakob/gocryptfs/v2/ctlsock" - "github.com/rfjakob/gocryptfs/v2/internal/syscallcompat" "github.com/rfjakob/gocryptfs/v2/tests/test_helpers" ) @@ -160,12 +159,12 @@ func TestAccess(t *testing.T) { } for _, n := range names { // Check if file exists - this should never fail - err = syscallcompat.Faccessat(unix.AT_FDCWD, dirB+"/"+n, unix.F_OK) + err = unix.Faccessat(unix.AT_FDCWD, dirB+"/"+n, unix.F_OK, unix.AT_SYMLINK_NOFOLLOW) if err != nil { t.Errorf("%s: %v", n, err) } // Check if file is readable - err = syscallcompat.Faccessat(unix.AT_FDCWD, dirB+"/"+n, unix.R_OK) + err = unix.Faccessat(unix.AT_FDCWD, dirB+"/"+n, unix.R_OK, unix.AT_SYMLINK_NOFOLLOW) if err != nil { t.Logf("%s: %v", n, err) } |
