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

Simplified muxer fix #99576

Merged
merged 21 commits into from
Aug 2, 2024
Merged

Simplified muxer fix #99576

merged 21 commits into from
Aug 2, 2024

Conversation

agocke
Copy link
Member

@agocke agocke commented Mar 12, 2024

This is a simplified version of #87717 that tries to narrowly enable running a host behind a symlink.

Fixes #83314

agocke and others added 6 commits March 10, 2024 13:47
realpath is guaranteed to resolve symlinks. fullpath may resolve symlinks.
Moves all existing code to call fullpath, which is the existing contract. On
Unix, fullpath calls realpath, meaning it resolves symlinks. On Windows it
doesn't. Code which requires symlinks to be resolved should be moved to call
realpath. realpath is temporarily renamed realpath2 in this commit to find
dangling references.
@agocke agocke marked this pull request as ready for review March 18, 2024 01:10
@agocke agocke requested a review from elinor-fung March 18, 2024 01:13
src/native/corehost/host_startup_info.cpp Show resolved Hide resolved
src/native/corehost/fxr/fx_muxer.cpp Show resolved Hide resolved
src/native/corehost/hostmisc/pal.h Show resolved Hide resolved
src/native/corehost/corehost.cpp Outdated Show resolved Hide resolved
src/native/corehost/hostmisc/pal.windows.cpp Outdated Show resolved Hide resolved

if (file.get() == INVALID_HANDLE_VALUE)
{
// If we get "access denied" that may mean the path represents a directory.
Copy link
Member

Choose a reason for hiding this comment

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

Is this an intentional limitation? CreateFile should be able to get a directory handle with FILE_FLAG_BACKUP_SEMANTICS.

Copy link
Member Author

Choose a reason for hiding this comment

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

To be honest I can't remember. There seem to be a lot of caveats in FILE_FLAG_BACKUP_SEMANTICS docs. Since we're going to fullpath in this case anyway, is there any point in proceeding?

Also, does Windows have directory symlinks?

Copy link
Member

Choose a reason for hiding this comment

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

Windows does have directory symlinks - for example, via mklink /d.

The current uses of pal::realpath only operate on a file, so it is probably fine that this wouldn't resolve directory symlinks if we want to avoid any complexity that FILE_FLAG_BACKUP_SEMANTICS might bring. But in that case, maybe update the // Like fullpath, but resolves symlinks. comment to indicate that only resolving for files is known/intentional limitation of this function (on Windows). I could see hitting cases in the future where it'd be confusing that this doesn't handle directories (maybe dotnet root being a symlink or something like that).

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a comment. The file security implications of FILE_FLAG_BACKUP_SEMANTICS worry me a bit just because I don't understand all the consequences.

src/native/corehost/hostmisc/pal.windows.cpp Show resolved Hide resolved
src/native/corehost/hostmisc/pal.windows.cpp Outdated Show resolved Hide resolved
@agocke
Copy link
Member Author

agocke commented Apr 18, 2024

@elinor-fung I think this is ready for re-review whenever you're free. No rush.

{
trace::error(_X("Error resolving full path [%s]"), path->c_str());
trace::error(_X("GetLastError(): [%s]"), ::GetLastError());
return false;
Copy link
Member

Choose a reason for hiding this comment

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

Should this be outside of the if block so that we still return false when not printing out errors? Otherwise, skip_error_logging changes the actual error behaviour, not just logging.

Copy link
Member

Choose a reason for hiding this comment

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

Same below.

src/native/corehost/hostmisc/pal.windows.cpp Show resolved Hide resolved

if (file.get() == INVALID_HANDLE_VALUE)
{
// If we get "access denied" that may mean the path represents a directory.
Copy link
Member

Choose a reason for hiding this comment

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

Windows does have directory symlinks - for example, via mklink /d.

The current uses of pal::realpath only operate on a file, so it is probably fine that this wouldn't resolve directory symlinks if we want to avoid any complexity that FILE_FLAG_BACKUP_SEMANTICS might bring. But in that case, maybe update the // Like fullpath, but resolves symlinks. comment to indicate that only resolving for files is known/intentional limitation of this function (on Windows). I could see hitting cases in the future where it'd be confusing that this doesn't handle directories (maybe dotnet root being a symlink or something like that).

src/native/corehost/hostmisc/pal.windows.cpp Outdated Show resolved Hide resolved
src/native/corehost/hostmisc/pal.windows.cpp Outdated Show resolved Hide resolved
@agocke agocke merged commit 3e572e9 into dotnet:main Aug 2, 2024
149 checks passed
@agocke agocke deleted the simplified-muxer-fix branch August 2, 2024 16:10
@github-actions github-actions bot locked and limited conversation to collaborators Sep 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Dotnet muxer doesn't respect Windows symlinks
2 participants