Skip to content

Fix absolute path check when loading hostfxr/hostpolicy/coreclr #116597

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

Merged
merged 4 commits into from
Jun 16, 2025

Conversation

elinor-fung
Copy link
Member

On Windows, we were incorrectly only checking for <letter>: and incorrectly determining that UNC and device paths were not absolute. This updates pal::is_path_rooted to match the managed Path.IsPathRooted and adds a pal::is_path_absolute with the logic of Path.IsPartiallyQualified

See #116521
cc @dotnet/appmodel @AaronRobinsonMSFT @jkotas

We should backport as well.

Copy link
Contributor

Tagging subscribers to this area: @vitek-karas, @agocke, @VSadov
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR corrects the determination of absolute paths on Windows by introducing a new pal::is_path_absolute that aligns with .NET’s logic and updating existing checks to use it. It also enhances the rooted-path test on Windows, adds Unix support for is_path_absolute, and includes tests for device path scenarios.

  • Implement is_path_absolute and expand is_path_rooted on Windows
  • Switch all corehost/fxr/hostpolicy resolvers to use is_path_absolute
  • Add Windows device-path tests in installer activation suites

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/native/corehost/hostpolicy/standalone/coreclr_resolver.cpp Use is_path_absolute instead of is_path_rooted
src/native/corehost/hostmisc/pal.windows.cpp Add is_path_absolute, refine is_path_rooted
src/native/corehost/hostmisc/pal.unix.cpp Add is_path_absolute delegating to is_path_rooted
src/native/corehost/hostmisc/pal.h Declare new is_path_absolute API
src/native/corehost/fxr_resolver.h Update hostfxr load check to use is_path_absolute
src/native/corehost/fxr/standalone/hostpolicy_resolver.cpp Switch hostpolicy path check to is_path_absolute
src/native/corehost/corehost.cpp Add detailed error log when fxr resolution fails
src/native/corehost/apphost/standalone/hostfxr_resolver.cpp Use is_path_absolute for apphost fxr path validation
src/installer/tests/HostActivation.Tests/SelfContainedAppLaunch.cs Add Windows device-path launch tests
src/installer/tests/HostActivation.Tests/FrameworkDependentAppLaunch.cs Add Windows device-path DotNetRoot tests
Comments suppressed due to low confidence (2)

src/native/corehost/hostmisc/pal.h:345

  • Consider adding a doc comment above is_path_absolute describing its behavior (UNC, device paths, drive-letter paths) to aid future maintainers.
bool is_path_absolute(const string_t& path);

src/installer/tests/HostActivation.Tests/SelfContainedAppLaunch.cs:162

  • Add a test case for a standard UNC network share path (e.g., \\server\\share\\app.exe) to ensure UNC paths are recognized as absolute.
public void DevicePath()

@@ -342,6 +342,7 @@ namespace pal

bool get_default_breadcrumb_store(string_t* recv);
bool is_path_rooted(const string_t& path);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all remaining uses of is_path_rooted correct?

is_path_rooted is kind of broken concept. It rarely does what you expect.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switch ones where the intent is checking for absolute path to is_path_fully_qualified. Remaining are around appending paths, where I think we do want is_path_rooted (matches Path.Combine logic).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Path.Combine has similar set of issues - it was one of the reasons for introducing Path.Join.

Are there situations in append_path where we can end up with path2 that is rooted but not fully qualified?

If there are situations like that, the behavior will depend on current directory again that's generally a security problem. If there are no situations like that, it does not matter whether we use is_path_fully_qualified or is_path_rooted.

Ideally, I think we would switch to Path.Join like API - but that is nice to have clean up that's not appropriate for servicing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only case is if the user explicitly did some configuration to specify a path that is rooted but not fully qualified - for the environment variable for bundle extraction directory or a custom sdk path in global.json, we'd use that rooted, not fully qualified path.

I'll look at making append_path more Path.Join-like in the future.

@elinor-fung elinor-fung merged commit 22ccb05 into dotnet:main Jun 16, 2025
148 of 150 checks passed
@elinor-fung
Copy link
Member Author

/backport to release/9.0-staging

Copy link
Contributor

Started backporting to release/9.0-staging: https://github.com/dotnet/runtime/actions/runs/15687286225

@elinor-fung
Copy link
Member Author

/backport to release/8.0-staging

Copy link
Contributor

Started backporting to release/8.0-staging: https://github.com/dotnet/runtime/actions/runs/15687292495

Copy link
Contributor

@elinor-fung backporting to "release/9.0-staging" failed, the patch most likely resulted in conflicts:

$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Fix absolute path check when loading hostfxr/hostpolicy/coreclr
Using index info to reconstruct a base tree...
M	src/native/corehost/apphost/standalone/hostfxr_resolver.cpp
M	src/native/corehost/corehost.cpp
M	src/native/corehost/fxr/standalone/hostpolicy_resolver.cpp
M	src/native/corehost/fxr_resolver.h
M	src/native/corehost/hostmisc/pal.h
M	src/native/corehost/hostmisc/pal.unix.cpp
M	src/native/corehost/hostmisc/pal.windows.cpp
M	src/native/corehost/hostpolicy/standalone/coreclr_resolver.cpp
Falling back to patching base and 3-way merge...
Auto-merging src/native/corehost/hostpolicy/standalone/coreclr_resolver.cpp
CONFLICT (content): Merge conflict in src/native/corehost/hostpolicy/standalone/coreclr_resolver.cpp
Auto-merging src/native/corehost/hostmisc/pal.windows.cpp
Auto-merging src/native/corehost/hostmisc/pal.unix.cpp
Auto-merging src/native/corehost/hostmisc/pal.h
Auto-merging src/native/corehost/fxr_resolver.h
CONFLICT (content): Merge conflict in src/native/corehost/fxr_resolver.h
Auto-merging src/native/corehost/fxr/standalone/hostpolicy_resolver.cpp
CONFLICT (content): Merge conflict in src/native/corehost/fxr/standalone/hostpolicy_resolver.cpp
Auto-merging src/native/corehost/corehost.cpp
Auto-merging src/native/corehost/apphost/standalone/hostfxr_resolver.cpp
CONFLICT (content): Merge conflict in src/native/corehost/apphost/standalone/hostfxr_resolver.cpp
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Fix absolute path check when loading hostfxr/hostpolicy/coreclr
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

Copy link
Contributor

@elinor-fung backporting to "release/8.0-staging" failed, the patch most likely resulted in conflicts:

$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Fix absolute path check when loading hostfxr/hostpolicy/coreclr
Using index info to reconstruct a base tree...
M	src/native/corehost/apphost/standalone/hostfxr_resolver.cpp
M	src/native/corehost/corehost.cpp
M	src/native/corehost/fxr/standalone/hostpolicy_resolver.cpp
M	src/native/corehost/fxr_resolver.h
M	src/native/corehost/hostmisc/pal.h
M	src/native/corehost/hostmisc/pal.unix.cpp
M	src/native/corehost/hostmisc/pal.windows.cpp
M	src/native/corehost/hostpolicy/standalone/coreclr_resolver.cpp
Falling back to patching base and 3-way merge...
Auto-merging src/native/corehost/hostpolicy/standalone/coreclr_resolver.cpp
CONFLICT (content): Merge conflict in src/native/corehost/hostpolicy/standalone/coreclr_resolver.cpp
Auto-merging src/native/corehost/hostmisc/pal.windows.cpp
Auto-merging src/native/corehost/hostmisc/pal.unix.cpp
Auto-merging src/native/corehost/hostmisc/pal.h
Auto-merging src/native/corehost/fxr_resolver.h
CONFLICT (content): Merge conflict in src/native/corehost/fxr_resolver.h
Auto-merging src/native/corehost/fxr/standalone/hostpolicy_resolver.cpp
CONFLICT (content): Merge conflict in src/native/corehost/fxr/standalone/hostpolicy_resolver.cpp
Auto-merging src/native/corehost/corehost.cpp
Auto-merging src/native/corehost/apphost/standalone/hostfxr_resolver.cpp
CONFLICT (content): Merge conflict in src/native/corehost/apphost/standalone/hostfxr_resolver.cpp
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Fix absolute path check when loading hostfxr/hostpolicy/coreclr
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

@elinor-fung elinor-fung deleted the host-fixAbsolutePathCheck branch June 16, 2025 18:19
@elinor-fung
Copy link
Member Author

/backport to release/9.0-staging

Copy link
Contributor

Started backporting to release/9.0-staging: https://github.com/dotnet/runtime/actions/runs/15718023739

Copy link
Contributor

@elinor-fung backporting to "release/9.0-staging" failed, the patch most likely resulted in conflicts:

$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Fix absolute path check when loading hostfxr/hostpolicy/coreclr
Applying: Add tests
Applying: PR feedback
error: sha1 information is lacking or useless (src/native/corehost/apphost/standalone/hostfxr_resolver.cpp).
error: could not build fake ancestor
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0003 PR feedback
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

@elinor-fung
Copy link
Member Author

/backport to release/8.0-staging

Copy link
Contributor

Started backporting to release/8.0-staging: https://github.com/dotnet/runtime/actions/runs/15720742824

Copy link
Contributor

@elinor-fung backporting to "release/8.0-staging" failed, the patch most likely resulted in conflicts:

$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Fix absolute path check when loading hostfxr/hostpolicy/coreclr
Applying: Add tests
Using index info to reconstruct a base tree...
A	src/installer/tests/HostActivation.Tests/FrameworkDependentAppLaunch.cs
A	src/installer/tests/HostActivation.Tests/SelfContainedAppLaunch.cs
Falling back to patching base and 3-way merge...
CONFLICT (modify/delete): src/installer/tests/HostActivation.Tests/SelfContainedAppLaunch.cs deleted in HEAD and modified in Add tests. Version Add tests of src/installer/tests/HostActivation.Tests/SelfContainedAppLaunch.cs left in tree.
Auto-merging src/installer/tests/HostActivation.Tests/PortableAppActivation.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0002 Add tests
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants