-
Notifications
You must be signed in to change notification settings - Fork 4.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
allow FileStream to open any types of files from path #54676
Conversation
Tagging subscribers to this area: @dotnet/area-system-io Issue DetailsSo far runtime/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/FileStreamHelpers.Windows.cs Lines 153 to 154 in 9d771a2
This limitation was applied only to non-extended paths: runtime/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/FileStreamHelpers.Windows.cs Lines 147 to 151 in 9d771a2
Which would still allow for opening Since we don't have such limitation for Unix where we just disallow for opening directories using runtime/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs Line 76 in 9d771a2
And it's an additional sys-call for file opening, I think that we can just remove this limitation. I am going to post benchmark numbers as soon as I rebuild the repo in
|
Can this have some security implications where application accepting file path would now be able to inadvertently write to a pipe? I think it's okay but it may need to be listed as a breaking change. |
Opening files would be 2-3% faster:
|
I would not consider it a security issue but would prefer experts like @GrabYourPitchforks or @bartonjs to state their opinion. As of today someone can create a
To be honest I don't know why we do have this limitation. Perhaps @JeremyKuhne knows? |
I didn't mean that it would break any security guarantees at the OS or sandbox level. Purely talking about application level validation of input here and a scenario where this additional validation disappears with simple recompilation of app against new framework. |
I don't think this is a huge concern. The only way I can see this happening is if the server allows the untrusted client to provide the entire path to open (not even using concatenation, as buggy as people's implementations of this are) with no validation whatsoever. And at that point, if I wanted to do bad things to your server, I'd overwrite your server's executables on disk directly rather than try to write to a pipe. Basically, I think your app already has to be in a very bad way if this were to open a new attack vector. One thing that could be interesting is whether this API now allows people to read & write NTFS alternate data streams, which IIRC were blocked previously. (Somebody check me on that.) This would still indicate a bug (lack of validation) on the application's part, but we know for a fact that the majority of developers don't know how to write proper validation code when accepting arbitrary untrusted filenames as inputs. So I don't think it would introduce any new holes, but it could expand existing holes in apps. |
No security implications here. There were much more aggressive checks on Framework which, afaik, were a combination of:
As a side note, I'd push people to |
I'm not necessarily saying it's a huge concern, more like questioning whether it needs an extra note in release notes or something akin to that. Here's a scenario I was running in my head: |
Agree that a change like this would absolutely merit a mention in the release notes. |
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.
LGTM, thanks (though there are now conflicts to address).
…ions # Conflicts: # src/libraries/System.Private.CoreLib/src/System/IO/Strategies/FileStreamHelpers.Windows.cs # src/libraries/System.Private.CoreLib/src/System/IO/Strategies/OSFileStreamStrategy.cs
So far
FileStream
on Windows could be created from a path that was pointing only to a regular file. Sockets and pipes (which can be reffered to using device path like:\\.\pipe\$pipeName
) were not supported:runtime/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/FileStreamHelpers.Windows.cs
Lines 153 to 154 in 9d771a2
This limitation was applied only to non-extended paths:
runtime/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/FileStreamHelpers.Windows.cs
Lines 147 to 151 in 9d771a2
Which would still allow for opening
UNKNOWN
(GetFileType
returning0
) files like device interfaces from #54143Since we don't have such limitation for Unix where we just disallow for opening directories using
FileStream
(it's ok to open a pipe or socket from the path):runtime/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs
Line 76 in 9d771a2
And it's an additional sys-call for file opening, I think that we can just remove this limitation.
I am going to post benchmark numbers as soon as I rebuild the repo in
Release