Skip to content

Commit 07c388f

Browse files
tklausergopherbot
authored andcommitted
syscall: use fchmodat2 in Fchmodat
The fchmodat2 syscall was added in Linux kernel 6.6. Mirror the implementation in golang.org/x/sys/unix.Fchmodat (CL 539635) and use fchmodat2 in Fchmodat if flags are given. It will return ENOSYS on older kernels (or EINVAL or any other bogus error in some container implementations). Also update ztypes_linux_$GOARCH.go for all linux platforms to add _AT_EMPTY_PATH. It was added to linux/types in CL 407694 but was only updated for linux/loong64 at that time. Updates #61636 Change-Id: I863d06e35cd366f1cf99052e9f77c22ab8168b3f Reviewed-on: https://go-review.googlesource.com/c/go/+/540435 Reviewed-by: Mauri de Souza Meneguzzo <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Tobias Klauser <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Auto-Submit: Tobias Klauser <[email protected]>
1 parent 0889b39 commit 07c388f

36 files changed

+234
-9
lines changed

src/syscall/syscall_linux.go

+17-9
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,23 @@ func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) {
241241
}
242242

243243
//sys fchmodat(dirfd int, path string, mode uint32) (err error)
244-
245-
func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) {
246-
// Linux fchmodat doesn't support the flags parameter. Mimic glibc's behavior
247-
// and check the flags. Otherwise the mode would be applied to the symlink
248-
// destination which is not what the user expects.
249-
if flags&^_AT_SYMLINK_NOFOLLOW != 0 {
250-
return EINVAL
251-
} else if flags&_AT_SYMLINK_NOFOLLOW != 0 {
252-
return EOPNOTSUPP
244+
//sys fchmodat2(dirfd int, path string, mode uint32, flags int) (err error) = _SYS_fchmodat2
245+
246+
func Fchmodat(dirfd int, path string, mode uint32, flags int) error {
247+
// Linux fchmodat doesn't support the flags parameter, but fchmodat2 does.
248+
// Try fchmodat2 if flags are specified.
249+
if flags != 0 {
250+
err := fchmodat2(dirfd, path, mode, flags)
251+
if err == ENOSYS {
252+
// fchmodat2 isn't available. If the flags are known to be valid,
253+
// return EOPNOTSUPP to indicate that fchmodat doesn't support them.
254+
if flags&^(_AT_SYMLINK_NOFOLLOW|_AT_EMPTY_PATH) != 0 {
255+
return EINVAL
256+
} else if flags&(_AT_SYMLINK_NOFOLLOW|_AT_EMPTY_PATH) != 0 {
257+
return EOPNOTSUPP
258+
}
259+
}
260+
return err
253261
}
254262
return fchmodat(dirfd, path, mode)
255263
}

src/syscall/syscall_linux_386.go

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const (
1111
_SYS_clone3 = 435
1212
_SYS_faccessat2 = 439
1313
_SYS_pidfd_send_signal = 424
14+
_SYS_fchmodat2 = 452
1415
)
1516

1617
func setTimespec(sec, nsec int64) Timespec {

src/syscall/syscall_linux_amd64.go

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const (
1313
_SYS_clone3 = 435
1414
_SYS_faccessat2 = 439
1515
_SYS_pidfd_send_signal = 424
16+
_SYS_fchmodat2 = 452
1617
)
1718

1819
//sys Dup2(oldfd int, newfd int) (err error)

src/syscall/syscall_linux_arm.go

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const (
1111
_SYS_clone3 = 435
1212
_SYS_faccessat2 = 439
1313
_SYS_pidfd_send_signal = 424
14+
_SYS_fchmodat2 = 452
1415
)
1516

1617
func setTimespec(sec, nsec int64) Timespec {

src/syscall/syscall_linux_arm64.go

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const (
1111
_SYS_clone3 = 435
1212
_SYS_faccessat2 = 439
1313
_SYS_pidfd_send_signal = 424
14+
_SYS_fchmodat2 = 452
1415
)
1516

1617
//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) = SYS_EPOLL_PWAIT

src/syscall/syscall_linux_loong64.go

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const (
1111
_SYS_clone3 = 435
1212
_SYS_faccessat2 = 439
1313
_SYS_pidfd_send_signal = 424
14+
_SYS_fchmodat2 = 452
1415
)
1516

1617
//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) = SYS_EPOLL_PWAIT

src/syscall/syscall_linux_mips64x.go

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const (
1515
_SYS_clone3 = 5435
1616
_SYS_faccessat2 = 5439
1717
_SYS_pidfd_send_signal = 5424
18+
_SYS_fchmodat2 = 5452
1819
)
1920

2021
//sys Dup2(oldfd int, newfd int) (err error)

src/syscall/syscall_linux_mipsx.go

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const (
1313
_SYS_clone3 = 4435
1414
_SYS_faccessat2 = 4439
1515
_SYS_pidfd_send_signal = 4424
16+
_SYS_fchmodat2 = 4452
1617
)
1718

1819
func Syscall9(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err Errno)

src/syscall/syscall_linux_ppc64x.go

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const (
1515
_SYS_clone3 = 435
1616
_SYS_faccessat2 = 439
1717
_SYS_pidfd_send_signal = 424
18+
_SYS_fchmodat2 = 452
1819
)
1920

2021
//sys Dup2(oldfd int, newfd int) (err error)

src/syscall/syscall_linux_riscv64.go

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const (
1111
_SYS_clone3 = 435
1212
_SYS_faccessat2 = 439
1313
_SYS_pidfd_send_signal = 424
14+
_SYS_fchmodat2 = 452
1415
)
1516

1617
//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) = SYS_EPOLL_PWAIT

src/syscall/syscall_linux_s390x.go

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const (
1111
_SYS_clone3 = 435
1212
_SYS_faccessat2 = 439
1313
_SYS_pidfd_send_signal = 424
14+
_SYS_fchmodat2 = 452
1415
)
1516

1617
//sys Dup2(oldfd int, newfd int) (err error)

src/syscall/zsyscall_linux_386.go

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/syscall/zsyscall_linux_amd64.go

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/syscall/zsyscall_linux_arm.go

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/syscall/zsyscall_linux_arm64.go

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/syscall/zsyscall_linux_loong64.go

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/syscall/zsyscall_linux_mips.go

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/syscall/zsyscall_linux_mips64.go

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/syscall/zsyscall_linux_mips64le.go

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/syscall/zsyscall_linux_mipsle.go

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/syscall/zsyscall_linux_ppc64.go

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/syscall/zsyscall_linux_ppc64le.go

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/syscall/zsyscall_linux_riscv64.go

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/syscall/zsyscall_linux_s390x.go

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)