Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/sys/unix: Faccessat has unused flags parameter on Linux #25845

Closed
rudis opened this issue Jun 12, 2018 · 12 comments
Closed

x/sys/unix: Faccessat has unused flags parameter on Linux #25845

rudis opened this issue Jun 12, 2018 · 12 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. OS-Linux
Milestone

Comments

@rudis
Copy link

rudis commented Jun 12, 2018

The faccessat(2) syscall on Linux takes three arguments (see https://github.com/torvalds/linux/blob/8efcf34a263965e471e3999904f94d1f6799d42a/fs/open.c#L434), but Go's signature has an additional flags argument:

 //sys   Faccessat(dirfd int, path string, mode uint32, flags int) (err error)

This is problematic as the extra argument is ignored by the kernel but there's no indication in the source code/during compilation. As the only possible argument AT_SYMLINK_NOFOLLOW can be used to prevent following symlinks this omission might have a security impact.

@gopherbot gopherbot added this to the Unreleased milestone Jun 12, 2018
@ianlancetaylor
Copy link
Contributor

Hmmm, the C function faccessat takes four arguments. But I see that it seems to be implemented in glibc directly. So I agree that we should change x/sys/unix. Want to send a patch?

@ianlancetaylor ianlancetaylor added the NeedsFix The path to resolution is known, but the work has not been done. label Jun 12, 2018
@tklauser
Copy link
Member

tklauser commented Jun 12, 2018

The faccessat syscall on Darwin and FreeBSD (also NetBSD and OpenBSD, but these aren't implemented in x/sys/unix) takes a 4th flag argument and it would be nice to keep the Linux version of Faccessat compatible. Maybe change it to faccessat on Linux and only take 3 arguments and then add Faccessat as a wrapper taking 4 arguments which just ignores the 4th argument, i.e.

//sys   faccessat(dirfd int, path string, mode uint32) (err error)

func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) {
    return faccessat(dirfd, path, mode)
} 

@tklauser tklauser changed the title x/sys: Faccessat has unused flags parameter on Linux x/sys/unix: Faccessat has unused flags parameter on Linux Jun 12, 2018
@ianlancetaylor
Copy link
Contributor

@rudis
Copy link
Author

rudis commented Jun 13, 2018 via email

@tklauser
Copy link
Member

@rudis thanks for elaborating. Checking flags like in Fchmodat sounds good to me. Feel free to send a CL.

As for making the Fchmodat change in syscall: The package is frozen as per the comment in https://github.com/golang/go/blob/master/src/syscall/syscall.go#L21-L28, but occasional changes following the Go 1 compatibility promise are sometimes allowed. I'm not sure whether such a change would be acceptable, so l'll let @ianlancetaylor and @bradfitz decide.

@ianlancetaylor
Copy link
Contributor

I'm OK with backporting the Fchmodat flags check to the syscall package.

@gopherbot
Copy link

Change https://golang.org/cl/118658 mentions this issue: syscall: check Fchmodat flags parameter on Linux

gopherbot pushed a commit that referenced this issue Jun 13, 2018
As mentioned in #25845, port CL 46474 from golang.org/x/sys/unix to the
syscall package.

Currently Linux' fchmodat(2) syscall implementation doesn't support the
flags parameter (though it might in future versions [1]). Fchmodat in
the syscall package takes the parameter and (wrongly) passes it on to the
syscall which will ignore it.

According to the POSIX.1-2008 manual page [2], AT_SYMLINK_NOFOLLOW is
the only valid value for the flags parameter and EOPNOTSUPP should be
returned in case changing the mode of a symbolic link is not supported
by the underlying system. EINVAL should be returned for any other value
of the flags parameter.

  [1] https://patchwork.kernel.org/patch/9596301/
  [2] http://pubs.opengroup.org/onlinepubs/9699919799/functions/chmod.html

Updates #20130
Updates #25845

Change-Id: I1021dd0e6a4f4cb3557cb1c1b34dd618c378cda6
Reviewed-on: https://go-review.googlesource.com/118658
Reviewed-by: Ian Lance Taylor <iant@golang.org>
dna2github pushed a commit to dna2fork/go that referenced this issue Jun 14, 2018
As mentioned in golang#25845, port CL 46474 from golang.org/x/sys/unix to the
syscall package.

Currently Linux' fchmodat(2) syscall implementation doesn't support the
flags parameter (though it might in future versions [1]). Fchmodat in
the syscall package takes the parameter and (wrongly) passes it on to the
syscall which will ignore it.

According to the POSIX.1-2008 manual page [2], AT_SYMLINK_NOFOLLOW is
the only valid value for the flags parameter and EOPNOTSUPP should be
returned in case changing the mode of a symbolic link is not supported
by the underlying system. EINVAL should be returned for any other value
of the flags parameter.

  [1] https://patchwork.kernel.org/patch/9596301/
  [2] http://pubs.opengroup.org/onlinepubs/9699919799/functions/chmod.html

Updates golang#20130
Updates golang#25845

Change-Id: I1021dd0e6a4f4cb3557cb1c1b34dd618c378cda6
Reviewed-on: https://go-review.googlesource.com/118658
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@gopherbot
Copy link

Change https://golang.org/cl/119495 mentions this issue: unix: check faccessat flags parameter on Linux

@gopherbot
Copy link

Change https://golang.org/cl/120015 mentions this issue: syscall: check faccessat flags parameter on Linux

@wingyplus
Copy link
Contributor

@ianlancetaylor @tklauser Should we need to port CL120015 back to syscall package?

@tklauser
Copy link
Member

@wingyplus Thanks, I sent https://golang.org/cl/120015 doing that and let @ianlancetaylor decide whether that changeis acceptable for syscall (and if yes, within Go 1.11 or not).

gopherbot pushed a commit that referenced this issue Jun 21, 2018
Port CL 119495 from golang.org/x/sys/unix to the syscall package.

Currently Linux faccessat(2) syscall implementation doesn't support the
flags parameter. As per the discussion in #25845, permit the same flags
as glibc [1].

[1] https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/faccessat.c;h=ea42b2303ff4b2d2d6548ea04376fb265f773436;hb=HEAD

Updates #25845

Change-Id: I132b33275a9cc72b3a97acea5482806c7f47d7f7
Reviewed-on: https://go-review.googlesource.com/120015
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@wingyplus
Copy link
Contributor

@tklauser Thanks

@golang golang locked and limited conversation to collaborators Jun 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. OS-Linux
Projects
None yet
Development

No branches or pull requests

5 participants