-
Notifications
You must be signed in to change notification settings - Fork 18k
os.RemoveAll: openFdAt function without O_CLOEXEC and cause fd escape to child process #33405
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
Comments
I think it's a bug of go-1.12, child process will accidentally inherit fd opened by parent process doing |
Change https://golang.org/cl/188537 mentions this issue: |
Hi @oiooj @ianlancetaylor Thanks for quick response! Could we please make patch to 1.12 release? I think it is like kind of security issue and it impact the behaviour of children process. WDYT? |
Yes, I think it should be backport to 1.12. Hi, @gopherbot please open backport to 1.12 |
Backport issue(s) opened: #33424 (for 1.12). Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases. |
@oiooj Thanks! |
Change https://golang.org/cl/188538 mentions this issue: |
There's a race here with fork/exec, enable the close-on-exec flag for the new file descriptor. Updates #33405 Fixes #33424 Change-Id: Ib1e405c3b48b11c867f183fd13eff8b73d95e3b4 Reviewed-on: https://go-review.googlesource.com/c/go/+/188537 Run-TryBot: Baokun Lee <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> (cherry picked from commit 2d6ee6e) Reviewed-on: https://go-review.googlesource.com/c/go/+/188538 Run-TryBot: Ian Lance Taylor <[email protected]>
Hi @oiooj Is there any schedule to release v1.12.8? |
From Brad:
I think it's very soon, maybe in a week. |
@oiooj Thanks! |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
This is concurrent issue. When parent process has goroutine to remove the folder, other goroutine try to exec child process. But the
os.RemoveAll
callesopenFdAt
function which open file without O_CLOEXEC. The opened file at parent process will escape to child process.https://github.com/golang/go/blob/release-branch.go1.12/src/os/removeall_at.go#L156-L178
unix.Openat
works withoutO_CLOEXEC
.What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I use the following script to reproduce issue instead of complex concurrent one.
When I add the
O_CLOEXEC
intounix.Openat
, the/tmp
will be gone.What did you expect to see?
child process should not have any opened fd from parent.
I check go1.10, go.11 code base and found that the RemoveAll use os.Open with O_CLOEXEC. I think go1.12 might miss this part for
openat
.What did you see instead?
fd escape to child - leaking
@yyb196 @Ace-Tang @rudyfly
The text was updated successfully, but these errors were encountered: