-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
8352728: InternalError loading java.security due to Windows parent folder permissions #24465
base: master
Are you sure you want to change the base?
Conversation
👋 Welcome back fferrari! A progress list of the required criteria for merging this PR into |
❗ This change is not yet ready to be integrated. |
@franferrax The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
I don't think this change should be integrated before more investigation. I think start by finding out why this code is using toRealPath. For the two cases listed, it looks like toRealPath is correctly failing for the first, but for /dev/stdin then please bring it to nio-dev to discuss how special devices should be handled by that method. |
Hi @AlanBateman.
Ok, makes sense.
The usage of
Yes, that was our impression, and that's why we are not proposing any fix to
I will investigate the Linux case, I had skipped it because |
Hi, this is a proposal to fix 8352728.
The main idea is to replace
java.nio.file.Path::toRealPath
byjava.io.File::getCanonicalPath
for path canonicalization purposes. The rationale behind this decision is the following:File::getCanonicalPath
handles restricted permissions in parent directories. Contrarily,Path::toRealPath
fails withAccessDeniedException
.File::getCanonicalPath
handles non-regular files (e.g./dev/stdin
). Contrarily,Path::toRealPath
fails withNoSuchFileException
.Windows Case
@martinuy and I tracked down the
File::getCanonicalPath
vsPath::toRealPath
behaviour differences in Windows. Both methods end up calling theFindFirstFileW
API inside a loop for each parent directory in the path, until they include the leaf:File::getCanonicalPath
goes through the following stack intoFindFirstFileW
:WinNTFileSystem::canonicalize
WinNTFileSystem::canonicalize0
wcanonicalize
(here is the loop)FindFirstFileW
fails withERROR_ACCESS_DENIED
,lastErrorReportable
is consulted, the error is considered non-reportable and the iteration is stopped here. This may leave a partially normalized path, but it doesn't stop the processing, allowing later symlinks resolution.Path::toRealPath
goes through the following stack intoFindFirstFileW
:WindowsPath::toRealPath
WindowsLinkSupport::getRealPath
(here is the loop)WindowsNativeDispatcher::FindFirstFile
WindowsNativeDispatcher::FindFirstFile0
FindFirstFileW
fails withERROR_ACCESS_DENIED
, aWindowsException
is immediately thrown, then caught and rethrown as anIOException
(in particularAccessDeniedException
). This not only stops the iteration but also makes thePath::toRealPath
call fail.NOTE: In cases in which
File::getCanonicalPath
gives a partially normalized path due to lack of permissions, the impact on cycle detection should be negligible: any include that leads to infinite recursion will revisit the exact same path at some point (even if not normalized).Testing
The proposed
ConfigFileTestDirPermissions
test is passing, and no regressions have been found intest/jdk/java/security/Security/ConfigFileTest.java
(Windows and Linux).Also, the GitHub Actions testing run (
tier1
on various platforms) has passed.Testing Appendix
I could not make a fully automated symlinks resolution test in Windows, so I'm posting here a PowerShell extended version of
ConfigFileTestDirPermissions
. This test requires user interaction, to accept UAC elevation when creating the symlink. To run it, just paste the whole snippet in a non-elevated PowerShell terminal at the root of a builtjdk
repository.ConfigFileTestDirPermissionsEx PowerShell test
Progress
Issue
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/24465/head:pull/24465
$ git checkout pull/24465
Update a local copy of the PR:
$ git checkout pull/24465
$ git pull https://git.openjdk.org/jdk.git pull/24465/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 24465
View PR using the GUI difftool:
$ git pr show -t 24465
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/24465.diff
Using Webrev
Link to Webrev Comment