-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8210549: Runtime.exec: in closeDescriptors(), use FD_CLOEXEC instead of close() #25301
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
Conversation
|
👋 Welcome back stuefe! A progress list of the required criteria for merging this PR into |
4eef7ba to
cc80bb3
Compare
|
@tstuefe This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 48 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
3e17175 to
cd9c002
Compare
cd9c002 to
c5dc302
Compare
Webrevs
|
|
Ping @RogerRiggs ? And @simonis, perhaps? |
RogerRiggs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
|
@RogerRiggs Thank you. I hold this up a few days until JDK26 since its not super critical. Would one review be sufficient or do I need more? |
|
Leaving it to 26 is good. One review is ok. |
…escriptors-use-FD_CLOEXEC-instead-of-close-
…escriptors-use-FD_CLOEXEC-instead-of-close-
|
@tstuefe this pull request can not be integrated into git checkout JDK-8210549-Runtime-exec-in-closeDescriptors-use-FD_CLOEXEC-instead-of-close-
git fetch https://git.openjdk.org/jdk.git master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push |
…rs-use-FD_CLOEXEC-instead-of-close-
| // - a library invoked with -agentlib that ensures that, in the parent JVM, we open a native fd without setting | ||
| // FD_CLOEXEC (libFDLeaker.c). This is necessary because there is no way to do this from Java: if Java functions | ||
| // correctly, all files the user could open via its APIs should be marked with FD_CLOEXEC. | ||
| // - a small native executable that tests - without using /proc - whether any file descriptors other than | ||
| // stdin/out/err are open. | ||
| // | ||
| // What should happen: In the child process, between the initial fork and the exec of the target binary, we should | ||
| // close all filedescriptors that are not stdin/out/err. If that works, the child process should not see any other |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you shorten the long lines to < 100 chars. It makes side-by-side reviews easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RogerRiggs need a re-review
RogerRiggs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates.
|
Thank you, Roger! /integrate |
|
Going to push as commit afa52e4.
Your commit was automatically rebased without conflicts. |
Hi, please consider the following patch.
This patch replaces the existing close-file-descriptors-logic we follow before exec'ing a target binary: instead of explicitly closing the file descriptors, we mark them as CLOEXEC. That simplifies the logic: it gets rid of the awkward tiptoeing around the fact that we need to keep alive a few file descriptors: the fail pipe fd needs to be kept open right up to the exec(), and we cause opening internal file descriptors during our iteration of open file handles from /proc.
This patch also makes future developments easier: I am working on improving logging during child process spawning (https://bugs.openjdk.org/browse/JDK-8357100), and there we have a similar problem where we need to keep a logfile fd open right up to the point exec() happens).
Note: Using fcntl() with FD_CLOEXEC should work on all our POSIX platforms, since we rely on it already, see unconditional use of that flag here:
jdk/src/java.base/unix/native/libjava/childproc.c
Lines 408 to 409 in 3acfa9e
This patch also fixes two subtle bugs:
Testing:
We already have the PipelineLeak test, but I also added a new test that checks that we don't accidentally leak file descriptors even if those had been opened outside the JVM and without FD_CLOEXEC.
I verified that the test correctly detects a broken implementation that leaks file descriptors.
I verified that with this patch, we close all file descriptors. I also verified the fallback path (where we brute-force-iterate all descriptors up to _SC_OPEN_MAX).
I ran manually all tests from test/jdk/java/base/Process*, and verified that these tests run as part of the GHAs, which are green.
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25301/head:pull/25301$ git checkout pull/25301Update a local copy of the PR:
$ git checkout pull/25301$ git pull https://git.openjdk.org/jdk.git pull/25301/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 25301View PR using the GUI difftool:
$ git pr show -t 25301Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25301.diff
Using Webrev
Link to Webrev Comment