-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
os: ModeSetgid has no effect while using with Mkdir() on Linux #25539
Comments
Seems that we should fix that along the lines that you point out. Want to send a patch? |
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: #include <sys/stat.h>
int main() {
mkdir("test", 02770);
} vs. #include <sys/stat.h>
int main() {
mkdir("test", 02770);
chmod("test", 02770);
} |
Dope, if you don't want to send a patch I can make one, just let me know |
@jessfraz Thanks. Haven't tested the linked PR yet, I'll talk to @Al2Klimov in terms of signing the CLA on Monday :) |
Change https://golang.org/cl/116075 mentions this issue: |
I would like to make a motion that this is not a bug, but the expected behavior and therefore should not be fixed. With the proposed |
@paulzhol I think the counter argument is that passing these bits in the mode argument to
I don't see any particular reason to require Go programmers to be familiar with libc behavior. And I don't see any particular reason why people familiar with the libc behavior would choose to pass |
@ianlancetaylor I would argue that the current documentation states one should be passing only permission bits:
Note the use of
I suggest the documentation should be updated to state the special handling of |
LibC? I thought I was programming in Go... 😕 Seriously, I has programmed in C/POSIX and I've expected Go to handle 04755, but (surprise, surprise) it handles 040000755 and only 040000755. 04755 has literally no effect compared to 0755 – whether libc/kernel would handle it or not. 07000 gets taken away and replaced w/ the bits from 070000000. TL;DRGo's os package seems not to be bound to any libc constraints – and IMO shouldn't be. |
@paulzhol I agree that we could document the restriction, but that just changes the surprise from the person writing the code to the person reading the documentation. That is better, but it still seems odd. After all, there isn't any fundamental reason that it shouldn't work. |
You can pass a
(the quote above is from the Because the
To emphasize my point, what about The interface of a method is not just it's signature, but also the accompanied doc comment, you can't ignore one or the other. |
@ianlancetaylor The restriction is already documented (maybe not as clearly as we'd like). What happens when you add |
Note that as of earlier today the code does now check whether the I'm still not really seeing the real problem with handling I do now think that we should be checking for mode bits we aren't going to handle and returning an error if we see any. |
There is another (IMO even more) popular OS called MacOS X that has a different behavior than Linux. (mode & 0777 & ~umask) |
That makes sense.
I'm aware of it (I was a reviewer) and I have been trying to explain there will be an inconsistency if we treat ModeSetuid in the same way as ModeSticky:
Behaviour 1 is probably valid for ModeSticky because the sticky bit has no real effect on a regular file, I don't think it's valid for ModeSetuid. |
Was curious if there is any movement on this issue? One reason it would be useful to have this is in combination with |
I guess this stalled out. |
PHP has the same issue for like 20 years, you have to set 02777 or the like separately. At least PHP's chmod equivalent works. In Go nothing works and you have to call the system's chmod to set a setgid bit lmao. Both seem to be issues from their copying of glibc or something. |
Underlying issue is a can of worms: golang/go#25539
In go version go1.17.7 linux/amd64 it still does not work in os.Mkdir to have masks like 02755 . Why on earth Golang choose not respect standard Linux behaviour, is hard to understand. Documentation of os.Mkdir or os.Chown is silent about the issue as well, so it is a surprise to discover. One would naively wish a module called "os" to support ALL of each OS functionality its platform, rather than a minimal common subset of functionalities that can be found between each and every OS that there is. |
@gshamov update your Go This isn't in many languages because it requires 2 things, first making the folder then setting the permissions... it isn't possible to do both at once. which to most of us doesn't matter to 99% of us, apparently it does to them. |
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?
What did you expect to see?
What did you see instead?
Why did this happen?
According to
strace -f ./mkdir
the Go stdlib behaves as expected...... but on Linux this is not enough, see
mkdirat(2)
:... and
mkdir(2)
:How could this be fixed?
Similar to #8383, via Chmod.
The text was updated successfully, but these errors were encountered: