-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Open
Labels
NeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.OS-Linuxhelp wanted
Milestone
Description
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version
)?
go version go1.9.4 linux/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env
)?
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/go"
GORACE=""
GOROOT="/usr/lib/golang"
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build203196509=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
What did you do?
package main
import (
"os"
)
func main() {
os.Mkdir("test", 0770 | os.ModeSetgid)
}
What did you expect to see?
# ls -la test
insgesamt 4
drwxr-s---. 2 root root 6 24. Mai 04:09 .
dr-xr-x---. 13 root root 4096 24. Mai 04:09 ..
#
What did you see instead?
# ls -la test
insgesamt 4
drwxr-x---. 2 root root 6 24. Mai 04:09 .
dr-xr-x---. 13 root root 4096 24. Mai 04:09 ..
#
Why did this happen?
According to strace -f ./mkdir
the Go stdlib behaves as expected...
[pid 6782] mkdirat(AT_FDCWD, "test", 02770 <unfinished ...>
[pid 6782] <... mkdirat resumed> ) = 0
... but on Linux this is not enough, see mkdirat(2)
:
The mkdirat() system call operates in exactly the same way as mkdir(2), (...)
... and mkdir(2)
:
The argument mode specifies the permissions to use.
It is modified (...): the permissions of the created directory are (mode & ~umask & 0777).
Other mode bits of the created directory depend on the operating system.
For Linux, see below.
(...)
That is, under Linux the created directory actually gets mode (mode & ~umask & 01777)
How could this be fixed?
Metadata
Metadata
Assignees
Labels
NeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.OS-Linuxhelp wanted
Type
Projects
Relationships
Development
Select code repository
Activity
[-]os.ModeSetgid has no effect while using with os.Mkdir() on Linux[/-][+]os: ModeSetgid has no effect while using with Mkdir() on Linux[/+]tklauser commentedon May 24, 2018
/cc @bradfitz @ianlancetaylor @rsc
ianlancetaylor commentedon May 24, 2018
Seems that we should fix that along the lines that you point out. Want to send a patch?
Al2Klimov commentedon May 25, 2018
I'm afraid I have to correct myself: It's not just Linux, it seems to be all *nix.
Discovered this by running this on my Mac workstation:
vs.
odeke-em commentedon Jun 1, 2018
/cc @jessfraz @lizrice too
jessfraz commentedon Jun 1, 2018
Dope, if you don't want to send a patch I can make one, just let me know
dnsmichi commentedon Jun 1, 2018
@jessfraz Thanks. Haven't tested the linked PR yet, I'll talk to @Al2Klimov in terms of signing the CLA on Monday :)
Al2Klimov commentedon Jun 4, 2018
As discussed w/ @dnsmichi (offline): I've just overseen an elephant:
I forgot to do this one.
22 remaining items