Uh oh!
There was an error while loading. Please reload this page.
allow FileStream to open any types of files from path - #54676
Conversation
ghost
commented
Jun 24, 2021
Tagging subscribers to this area: @dotnet/area-system-io Issue DetailsSo far This limitation was applied only to non-extended paths: Which would still allow for opening Since we don't have such limitation for Unix where we just disallow for opening directories using 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
|
filipnavara
commented
Jun 24, 2021
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. |
adamsitnik
commented
Jun 24, 2021
Opening files would be 2-3% faster: Details
|
adamsitnik
commented
Jun 24, 2021
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? |
filipnavara
commented
Jun 24, 2021
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. |
GrabYourPitchforks
commented
Jun 24, 2021
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. |
JeremyKuhne
commented
Jun 24, 2021
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 |
filipnavara
commented
Jun 24, 2021
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: |
GrabYourPitchforks
commented
Jun 24, 2021
Agree that a change like this would absolutely merit a mention in the release notes. |
stephentoub
left a comment
There was a problem hiding this comment.
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
FileStreamon 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(GetFileTypereturning0) 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