Source code

Revision control

Copy as Markdown

Other Tools

Block directory creation and only allow read access.
diff --git a/sandbox/win/src/filesystem_dispatcher.cc b/sandbox/win/src/filesystem_dispatcher.cc
index 2b6a31f9bf88..4d8bb91c3d7b 100644
--- a/sandbox/win/src/filesystem_dispatcher.cc
+++ b/sandbox/win/src/filesystem_dispatcher.cc
@@ -92,6 +92,19 @@ bool ValidateFileOptions(uint32_t options) {
return (options & kFileValidOptionFlags) == options;
}
+void RestrictDirectoryAccess(uint32_t options, uint32_t* access) {
+ if (options & FILE_NON_DIRECTORY_FILE) {
+ return;
+ }
+
+ static constexpr uint32_t kAllowedDirReadFlags =
+ FILE_LIST_DIRECTORY | FILE_TRAVERSE | FILE_READ_ATTRIBUTES |
+ FILE_READ_EA | READ_CONTROL | SYNCHRONIZE | GENERIC_READ |
+ GENERIC_EXECUTE;
+
+ *access &= kAllowedDirReadFlags;
+}
+
bool FilesystemDispatcher::NtCreateFile(IPCInfo* ipc,
std::wstring* name,
uint32_t attributes,
@@ -105,6 +118,20 @@ bool FilesystemDispatcher::NtCreateFile(IPCInfo* ipc,
return true;
}
+ // Only allow read only open for directories.
+ if (create_options & FILE_DIRECTORY_FILE) {
+ // Reject any flags that can only create or overwrite.
+ if (create_disposition != FILE_OPEN && create_disposition != FILE_OPEN_IF) {
+ ipc->return_info.nt_status = STATUS_ACCESS_DENIED;
+ return true;
+ }
+
+ // Force to open only.
+ create_disposition = FILE_OPEN;
+ }
+
+ RestrictDirectoryAccess(create_options, &desired_access);
+
EvalResult result = EvalPolicy(IpcTag::NTCREATEFILE, *name, desired_access,
create_disposition == FILE_OPEN);
HANDLE handle;
@@ -135,6 +162,8 @@ bool FilesystemDispatcher::NtOpenFile(IPCInfo* ipc,
return true;
}
+ RestrictDirectoryAccess(open_options, &desired_access);
+
EvalResult result =
EvalPolicy(IpcTag::NTOPENFILE, *name, desired_access, true);
HANDLE handle;