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

syscall: fs_nacl.go: Link needs to check if target exists #22383

Closed
tenortim opened this issue Oct 22, 2017 · 6 comments
Closed

syscall: fs_nacl.go: Link needs to check if target exists #22383

tenortim opened this issue Oct 22, 2017 · 6 comments
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done. OS-NaCl GOOS=nacl, Native Client sandbox, as used by the playground
Milestone

Comments

@tenortim
Copy link
Contributor

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go1.9

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

Go playground using GOOS=nacl

What did you do?

I was actually testing for race conditions (both Link and Rename are missing calls to lock
the filesystem for which I will create a separate issue), but there's actually no need to
run concurrent goroutines here. Simply attempting to Link(a, b) twice will corrupt the
internal filesystem by leaving two files but a link count of three.

See the stat output https://play.golang.org/p/GfxaxuqQIt

What did you expect to see?

Any attempt to link to an existing file should fail with EEXIST

What did you see instead?

Corrupted filesystem (two files, link count = 3).

@tenortim
Copy link
Contributor Author

tenortim commented Oct 22, 2017

Suggested change, here, cribbing from the open code. Add:

_, _, err := fs.dirlookup(dp, elem)
if err == nil {
        return EEXIST
}

before the call to fs.dirlink() at line 639

@ianlancetaylor ianlancetaylor changed the title syscall: go/fs_nacl.go Link needs to check if target exists syscall: fs_nacl.go: Link needs to check if target exists Oct 23, 2017
@ianlancetaylor ianlancetaylor added this to the Go1.10 milestone Oct 23, 2017
@ianlancetaylor ianlancetaylor added the OS-NaCl GOOS=nacl, Native Client sandbox, as used by the playground label Oct 23, 2017
@bradfitz
Copy link
Contributor

bradfitz commented Nov 1, 2017

@tenortim, do you want to send a change? (and include a new test)

@bradfitz bradfitz added help wanted NeedsFix The path to resolution is known, but the work has not been done. labels Nov 1, 2017
@tenortim
Copy link
Contributor Author

tenortim commented Nov 2, 2017

@bradfitz Will do. Any pointers on how to test this (since it only lives in the NACL code)?

@bradfitz
Copy link
Contributor

bradfitz commented Nov 2, 2017

@tenortim, just add tests in package "net", or "os", or "syscall", wherever's convenient. You can protect it with runtime.GOOS == "nacl" if needed.

See the src/nacltest.bash test file for how to run the tests.

@gopherbot
Copy link

Change https://golang.org/cl/76110 mentions this issue: fix NaCl Link() syscall error handling (EEXIST)

@tenortim
Copy link
Contributor Author

tenortim commented Nov 5, 2017

Fix submitted.
Test added first and verified that it fails.
Fix added to fs_nacl.go. It's not tied to GOOS since it's a valid test regardless (though unlikely to fail on any other platform). The test is a modified copy of part of the existing rename tests.
Verified that the test passes both for the NaCl build and for linux x64.

@golang golang locked and limited conversation to collaborators Nov 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done. OS-NaCl GOOS=nacl, Native Client sandbox, as used by the playground
Projects
None yet
Development

No branches or pull requests

4 participants