Eryk Sun <eryk...@gmail.com> added the comment:

> switch to the newer CreateFile2() function

Apparently we need to allow FILE_SHARE_READ if CreateFile2() is used to 
implement os.stat(). It's not a big deal, but this is a design flaw.

CreateFile2() always uses the kernel I/O flag FILE_DISALLOW_EXCLUSIVE [1] when 
it calls NtCreateFile(). The intent of this flag is to avoid exclusive read 
access on the first open of a file when a user lacks write permission. Thus 
unprivileged users aren't allowed to prevent read access to critical system 
files. 

However, the implementation is flawed because it denies access even if the open 
doesn't request data access. It's also flawed because it allows exclusive read 
access when there are previous opens even if the previous opens have no data 
access.

Classically, IoCheckShareAccess() only checks for a sharing violation when an 
open requests read, write, or delete data access (i.e. FILE_READ_DATA, 
FILE_EXECUTE, FILE_WRITE_DATA, FILE_APPEND_DATA, DELETE). This is clearly 
explained in [MS-FSA] [2]. An open that only requests metadata access can never 
cause a sharing violation and poses no problem with regard to blocking access 
to a file.

---
[1] 
https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntddk/nf-ntddk-iocreatefileex
[2] 
https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-fsa/8c0e3f4f-0729-49f4-a14d-7f7add593819

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue46506>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to