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

cmd/go: SECURITY: go build creates world-writable result files #7240

Closed
gopherbot opened this issue Jan 30, 2014 · 3 comments
Closed

cmd/go: SECURITY: go build creates world-writable result files #7240

gopherbot opened this issue Jan 30, 2014 · 3 comments

Comments

@gopherbot
Copy link

go build creates world-writable files under certain circumstances.

This happens on tip but not 1.2. The commit that introduces bad behavior is
https://code.google.com/p/go/source/detail?r=e8c8b0e2a52f1540f5059311a137c6fabb02d573

$ go build -o bar && ls -l bar
-rwxrwxrwx 1 tv tv 3971520 Jan 30 14:40 bar*
$ umask
0002

The trigger is $WORK residing on the same filesystem as the destination file.

In src/cmd/go/build.go *builder.moveOrCopyFile:

    if err := os.Chmod(src, perm); err == nil {
        if err := os.Rename(src, dst); err == nil {
            if buildX {
                b.showcmd("", "mv %s %s", src, dst)
            }
            return nil
        }
    }

    return b.copyFile(a, dst, src, perm)

perm is given by the caller as 0777 or 0666. Chmod does not respect umask, but sets the
file mode to exactly perm.

This does not trigger if Chmod or Rename fail, and b.copyFile is used (though Chmod
working and Rename failing may temporarily leave a world-writable file under $WORK --
not good either).

Adding `&& false` at the end of the first if gets the right results in all
circumstances.

Perhaps it's not the best idea to have 0777 modes in the source, waiting for this
mistake? (Then again, only 0700 is safe enough for all environments..)
And Go doesn't seem to let programmer access umask easily, either.
@ianlancetaylor
Copy link
Contributor

Comment 1:

Labels changed: added release-go1.3, repo-main, security.

@minux
Copy link
Member

minux commented Feb 6, 2014

Comment 2:

https://golang.org/cl/60480045

Status changed to Started.

@minux
Copy link
Member

minux commented Feb 6, 2014

Comment 3:

This issue was closed by revision c66956c.

Status changed to Fixed.

@rsc rsc added this to the Go1.3 milestone Apr 14, 2015
@rsc rsc removed the release-go1.3 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants