-
Notifications
You must be signed in to change notification settings - Fork 17.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
os: File.Stat on Windows doesn't use file handle for directories #52747
Comments
Change https://go.dev/cl/405275 mentions this issue: |
I've been investigating this issue lately, and I've found that This change breaks directory traversal, as readdir is expecting a handle created via I've done a working prototype of this idea in CL 405275. I'm also pretty sure that there is no need to use the path-based |
Another side effect of CL 405275: The directory handle created by This means it wouldn't be possible to move or remove an opened directory, just as it is already happening with normal opened files. @alexbrainman @mattn thoughts? |
How does |
This is the current behavior:
So one could say that the current behavior of CL 405275 changes how directory handles are constructed, instead of using |
Summary of behavior changes in CL 405275:
I don't see how we can avoid these behavior changes if we want to fix the TOCTOU issue, using |
I am not against these changes. Mainly because it is @bcmills and others will be dealing with new bugs introduced by this change. I don't see TOCTOU as a problem. But I am not security expert. It is hard for me to judge if these changes actually help any users or not. On the hand @qmuntal mentioned that CL 405275 also fixes #36019 and #43322 . Up to others if we should submit CL 405275 or not. Alex |
At the risk of reopening a can of worms, we've had a lot of discussion in the past about |
The documentation for that flag says that it means “[t]he file is being opened or created for a backup or restore operation.” In general I wonder, though: when we call So, what I'm wondering is: does that search handle itself not prevent the directory from being renamed, akin to opening it without the |
It would make things more homogeneous. The current |
It is unfortunate that
IMO this argument no longer holds, this discussion has some examples of operations that can only be applied to directory handlers opened via Having said this, I agree with @alexbrainman that CL 405275 will cause troubles to some, mainly to the lack of
A |
I agree with @qmuntal . Back in #23312 there was nothing to fix - the proposal was to make code less "inconsistent". But CL 405275 will actually fix some real issues. Alex |
On Windows
File.Stat
doesn't use the file handle to retrieve attributes when the file is a directory, due to the lack of a...ByHandle
Windows API which works on directories (GetFileInformationByHandle
only works on files), using the path instead.This means there may be a TOCTOU issue, as the results returned by
Stat
represent the attributes for the file at the path passed toOpen
, which may no longer be the file represented by the file handle if the file has been moved/replaced.The text was updated successfully, but these errors were encountered: