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

[SR-15471] Race condition when launching Process on Linux can leak file descriptors #3946

Open
swift-ci opened this issue Nov 10, 2021 · 0 comments

Comments

@swift-ci
Copy link
Contributor

@swift-ci swift-ci commented Nov 10, 2021

Previous ID SR-15471
Radar None
Original Reporter george (JIRA User)
Type Bug
Environment

Any

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: 3ed8fbdf2dbfa24098e0dc3fa558bb98

Issue Description:

The code for launching a `Process` on Linux emulates the Apple-specific extensions POSIX_SPAWN_CLOEXEC_DEFAULT by iterating over the currently open file descriptors and adding them to the posix_file_actions_t. However, if a descriptor is opened from a different thread after iteration begins, but before `posx_spawn` is called, it is possible that it will not be closed. This could lead to a deadlock if a child process waits on a file descriptor that has unintentionally leaked into that child process.

The offending code is here:

// POSIX_SPAWN_CLOEXEC_DEFAULT is an Apple extension so emulate it.

In one of my projects, I have worked around this by reimplementing this functionality using `clone` and doing the file descriptor iteration in the cloned process (which is guaranteed to be single-threaded): https://github.com/GeorgeLyon/Shwift/blob/f92f0c599a4294f9e49fa482fc2fabba0cbe8011/Sources/CLinuxSupport/CLinuxSupport_Parent.c#L213

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant