Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #include "sandbox/win/src/filesystem_dispatcher.h" |
michael@0 | 6 | |
michael@0 | 7 | #include "sandbox/win/src/crosscall_client.h" |
michael@0 | 8 | #include "sandbox/win/src/filesystem_interception.h" |
michael@0 | 9 | #include "sandbox/win/src/filesystem_policy.h" |
michael@0 | 10 | #include "sandbox/win/src/interception.h" |
michael@0 | 11 | #include "sandbox/win/src/interceptors.h" |
michael@0 | 12 | #include "sandbox/win/src/ipc_tags.h" |
michael@0 | 13 | #include "sandbox/win/src/policy_broker.h" |
michael@0 | 14 | #include "sandbox/win/src/policy_params.h" |
michael@0 | 15 | #include "sandbox/win/src/sandbox.h" |
michael@0 | 16 | #include "sandbox/win/src/sandbox_nt_util.h" |
michael@0 | 17 | |
michael@0 | 18 | namespace sandbox { |
michael@0 | 19 | |
michael@0 | 20 | FilesystemDispatcher::FilesystemDispatcher(PolicyBase* policy_base) |
michael@0 | 21 | : policy_base_(policy_base) { |
michael@0 | 22 | static const IPCCall create_params = { |
michael@0 | 23 | {IPC_NTCREATEFILE_TAG, WCHAR_TYPE, ULONG_TYPE, ULONG_TYPE, ULONG_TYPE, |
michael@0 | 24 | ULONG_TYPE, ULONG_TYPE, ULONG_TYPE}, |
michael@0 | 25 | reinterpret_cast<CallbackGeneric>(&FilesystemDispatcher::NtCreateFile) |
michael@0 | 26 | }; |
michael@0 | 27 | |
michael@0 | 28 | static const IPCCall open_file = { |
michael@0 | 29 | {IPC_NTOPENFILE_TAG, WCHAR_TYPE, ULONG_TYPE, ULONG_TYPE, ULONG_TYPE, |
michael@0 | 30 | ULONG_TYPE}, |
michael@0 | 31 | reinterpret_cast<CallbackGeneric>(&FilesystemDispatcher::NtOpenFile) |
michael@0 | 32 | }; |
michael@0 | 33 | |
michael@0 | 34 | static const IPCCall attribs = { |
michael@0 | 35 | {IPC_NTQUERYATTRIBUTESFILE_TAG, WCHAR_TYPE, ULONG_TYPE, INOUTPTR_TYPE}, |
michael@0 | 36 | reinterpret_cast<CallbackGeneric>( |
michael@0 | 37 | &FilesystemDispatcher::NtQueryAttributesFile) |
michael@0 | 38 | }; |
michael@0 | 39 | |
michael@0 | 40 | static const IPCCall full_attribs = { |
michael@0 | 41 | {IPC_NTQUERYFULLATTRIBUTESFILE_TAG, WCHAR_TYPE, ULONG_TYPE, INOUTPTR_TYPE}, |
michael@0 | 42 | reinterpret_cast<CallbackGeneric>( |
michael@0 | 43 | &FilesystemDispatcher::NtQueryFullAttributesFile) |
michael@0 | 44 | }; |
michael@0 | 45 | |
michael@0 | 46 | static const IPCCall set_info = { |
michael@0 | 47 | {IPC_NTSETINFO_RENAME_TAG, VOIDPTR_TYPE, INOUTPTR_TYPE, INOUTPTR_TYPE, |
michael@0 | 48 | ULONG_TYPE, ULONG_TYPE}, |
michael@0 | 49 | reinterpret_cast<CallbackGeneric>( |
michael@0 | 50 | &FilesystemDispatcher::NtSetInformationFile) |
michael@0 | 51 | }; |
michael@0 | 52 | |
michael@0 | 53 | ipc_calls_.push_back(create_params); |
michael@0 | 54 | ipc_calls_.push_back(open_file); |
michael@0 | 55 | ipc_calls_.push_back(attribs); |
michael@0 | 56 | ipc_calls_.push_back(full_attribs); |
michael@0 | 57 | ipc_calls_.push_back(set_info); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | bool FilesystemDispatcher::SetupService(InterceptionManager* manager, |
michael@0 | 61 | int service) { |
michael@0 | 62 | switch (service) { |
michael@0 | 63 | case IPC_NTCREATEFILE_TAG: |
michael@0 | 64 | return INTERCEPT_NT(manager, NtCreateFile, CREATE_FILE_ID, 48); |
michael@0 | 65 | |
michael@0 | 66 | case IPC_NTOPENFILE_TAG: |
michael@0 | 67 | return INTERCEPT_NT(manager, NtOpenFile, OPEN_FILE_ID, 28); |
michael@0 | 68 | |
michael@0 | 69 | case IPC_NTQUERYATTRIBUTESFILE_TAG: |
michael@0 | 70 | return INTERCEPT_NT(manager, NtQueryAttributesFile, QUERY_ATTRIB_FILE_ID, |
michael@0 | 71 | 12); |
michael@0 | 72 | |
michael@0 | 73 | case IPC_NTQUERYFULLATTRIBUTESFILE_TAG: |
michael@0 | 74 | return INTERCEPT_NT(manager, NtQueryFullAttributesFile, |
michael@0 | 75 | QUERY_FULL_ATTRIB_FILE_ID, 12); |
michael@0 | 76 | |
michael@0 | 77 | case IPC_NTSETINFO_RENAME_TAG: |
michael@0 | 78 | return INTERCEPT_NT(manager, NtSetInformationFile, SET_INFO_FILE_ID, 24); |
michael@0 | 79 | |
michael@0 | 80 | default: |
michael@0 | 81 | return false; |
michael@0 | 82 | } |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | bool FilesystemDispatcher::NtCreateFile( |
michael@0 | 86 | IPCInfo* ipc, std::wstring* name, DWORD attributes, DWORD desired_access, |
michael@0 | 87 | DWORD file_attributes, DWORD share_access, DWORD create_disposition, |
michael@0 | 88 | DWORD create_options) { |
michael@0 | 89 | if (!PreProcessName(*name, name)) { |
michael@0 | 90 | // The path requested might contain a reparse point. |
michael@0 | 91 | ipc->return_info.nt_status = STATUS_ACCESS_DENIED; |
michael@0 | 92 | return true; |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | const wchar_t* filename = name->c_str(); |
michael@0 | 96 | |
michael@0 | 97 | ULONG broker = TRUE; |
michael@0 | 98 | CountedParameterSet<OpenFile> params; |
michael@0 | 99 | params[OpenFile::NAME] = ParamPickerMake(filename); |
michael@0 | 100 | params[OpenFile::ACCESS] = ParamPickerMake(desired_access); |
michael@0 | 101 | params[OpenFile::OPTIONS] = ParamPickerMake(create_options); |
michael@0 | 102 | params[OpenFile::BROKER] = ParamPickerMake(broker); |
michael@0 | 103 | |
michael@0 | 104 | // To evaluate the policy we need to call back to the policy object. We |
michael@0 | 105 | // are just middlemen in the operation since is the FileSystemPolicy which |
michael@0 | 106 | // knows what to do. |
michael@0 | 107 | EvalResult result = policy_base_->EvalPolicy(IPC_NTCREATEFILE_TAG, |
michael@0 | 108 | params.GetBase()); |
michael@0 | 109 | HANDLE handle; |
michael@0 | 110 | ULONG_PTR io_information = 0; |
michael@0 | 111 | NTSTATUS nt_status; |
michael@0 | 112 | if (!FileSystemPolicy::CreateFileAction(result, *ipc->client_info, *name, |
michael@0 | 113 | attributes, desired_access, |
michael@0 | 114 | file_attributes, share_access, |
michael@0 | 115 | create_disposition, create_options, |
michael@0 | 116 | &handle, &nt_status, |
michael@0 | 117 | &io_information)) { |
michael@0 | 118 | ipc->return_info.nt_status = STATUS_ACCESS_DENIED; |
michael@0 | 119 | return true; |
michael@0 | 120 | } |
michael@0 | 121 | // Return operation status on the IPC. |
michael@0 | 122 | ipc->return_info.extended[0].ulong_ptr = io_information; |
michael@0 | 123 | ipc->return_info.nt_status = nt_status; |
michael@0 | 124 | ipc->return_info.handle = handle; |
michael@0 | 125 | return true; |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | bool FilesystemDispatcher::NtOpenFile( |
michael@0 | 129 | IPCInfo* ipc, std::wstring* name, DWORD attributes, DWORD desired_access, |
michael@0 | 130 | DWORD share_access, DWORD open_options) { |
michael@0 | 131 | if (!PreProcessName(*name, name)) { |
michael@0 | 132 | // The path requested might contain a reparse point. |
michael@0 | 133 | ipc->return_info.nt_status = STATUS_ACCESS_DENIED; |
michael@0 | 134 | return true; |
michael@0 | 135 | } |
michael@0 | 136 | |
michael@0 | 137 | const wchar_t* filename = name->c_str(); |
michael@0 | 138 | |
michael@0 | 139 | ULONG broker = TRUE; |
michael@0 | 140 | CountedParameterSet<OpenFile> params; |
michael@0 | 141 | params[OpenFile::NAME] = ParamPickerMake(filename); |
michael@0 | 142 | params[OpenFile::ACCESS] = ParamPickerMake(desired_access); |
michael@0 | 143 | params[OpenFile::OPTIONS] = ParamPickerMake(open_options); |
michael@0 | 144 | params[OpenFile::BROKER] = ParamPickerMake(broker); |
michael@0 | 145 | |
michael@0 | 146 | // To evaluate the policy we need to call back to the policy object. We |
michael@0 | 147 | // are just middlemen in the operation since is the FileSystemPolicy which |
michael@0 | 148 | // knows what to do. |
michael@0 | 149 | EvalResult result = policy_base_->EvalPolicy(IPC_NTOPENFILE_TAG, |
michael@0 | 150 | params.GetBase()); |
michael@0 | 151 | HANDLE handle; |
michael@0 | 152 | ULONG_PTR io_information = 0; |
michael@0 | 153 | NTSTATUS nt_status; |
michael@0 | 154 | if (!FileSystemPolicy::OpenFileAction(result, *ipc->client_info, *name, |
michael@0 | 155 | attributes, desired_access, |
michael@0 | 156 | share_access, open_options, &handle, |
michael@0 | 157 | &nt_status, &io_information)) { |
michael@0 | 158 | ipc->return_info.nt_status = STATUS_ACCESS_DENIED; |
michael@0 | 159 | return true; |
michael@0 | 160 | } |
michael@0 | 161 | // Return operation status on the IPC. |
michael@0 | 162 | ipc->return_info.extended[0].ulong_ptr = io_information; |
michael@0 | 163 | ipc->return_info.nt_status = nt_status; |
michael@0 | 164 | ipc->return_info.handle = handle; |
michael@0 | 165 | return true; |
michael@0 | 166 | } |
michael@0 | 167 | |
michael@0 | 168 | bool FilesystemDispatcher::NtQueryAttributesFile( |
michael@0 | 169 | IPCInfo* ipc, std::wstring* name, DWORD attributes, CountedBuffer* info) { |
michael@0 | 170 | if (sizeof(FILE_BASIC_INFORMATION) != info->Size()) |
michael@0 | 171 | return false; |
michael@0 | 172 | |
michael@0 | 173 | if (!PreProcessName(*name, name)) { |
michael@0 | 174 | // The path requested might contain a reparse point. |
michael@0 | 175 | ipc->return_info.nt_status = STATUS_ACCESS_DENIED; |
michael@0 | 176 | return true; |
michael@0 | 177 | } |
michael@0 | 178 | |
michael@0 | 179 | ULONG broker = TRUE; |
michael@0 | 180 | const wchar_t* filename = name->c_str(); |
michael@0 | 181 | CountedParameterSet<FileName> params; |
michael@0 | 182 | params[FileName::NAME] = ParamPickerMake(filename); |
michael@0 | 183 | params[FileName::BROKER] = ParamPickerMake(broker); |
michael@0 | 184 | |
michael@0 | 185 | // To evaluate the policy we need to call back to the policy object. We |
michael@0 | 186 | // are just middlemen in the operation since is the FileSystemPolicy which |
michael@0 | 187 | // knows what to do. |
michael@0 | 188 | EvalResult result = policy_base_->EvalPolicy(IPC_NTQUERYATTRIBUTESFILE_TAG, |
michael@0 | 189 | params.GetBase()); |
michael@0 | 190 | |
michael@0 | 191 | FILE_BASIC_INFORMATION* information = |
michael@0 | 192 | reinterpret_cast<FILE_BASIC_INFORMATION*>(info->Buffer()); |
michael@0 | 193 | NTSTATUS nt_status; |
michael@0 | 194 | if (!FileSystemPolicy::QueryAttributesFileAction(result, *ipc->client_info, |
michael@0 | 195 | *name, attributes, |
michael@0 | 196 | information, &nt_status)) { |
michael@0 | 197 | ipc->return_info.nt_status = STATUS_ACCESS_DENIED; |
michael@0 | 198 | return true; |
michael@0 | 199 | } |
michael@0 | 200 | |
michael@0 | 201 | // Return operation status on the IPC. |
michael@0 | 202 | ipc->return_info.nt_status = nt_status; |
michael@0 | 203 | return true; |
michael@0 | 204 | } |
michael@0 | 205 | |
michael@0 | 206 | bool FilesystemDispatcher::NtQueryFullAttributesFile( |
michael@0 | 207 | IPCInfo* ipc, std::wstring* name, DWORD attributes, CountedBuffer* info) { |
michael@0 | 208 | if (sizeof(FILE_NETWORK_OPEN_INFORMATION) != info->Size()) |
michael@0 | 209 | return false; |
michael@0 | 210 | |
michael@0 | 211 | if (!PreProcessName(*name, name)) { |
michael@0 | 212 | // The path requested might contain a reparse point. |
michael@0 | 213 | ipc->return_info.nt_status = STATUS_ACCESS_DENIED; |
michael@0 | 214 | return true; |
michael@0 | 215 | } |
michael@0 | 216 | |
michael@0 | 217 | ULONG broker = TRUE; |
michael@0 | 218 | const wchar_t* filename = name->c_str(); |
michael@0 | 219 | CountedParameterSet<FileName> params; |
michael@0 | 220 | params[FileName::NAME] = ParamPickerMake(filename); |
michael@0 | 221 | params[FileName::BROKER] = ParamPickerMake(broker); |
michael@0 | 222 | |
michael@0 | 223 | // To evaluate the policy we need to call back to the policy object. We |
michael@0 | 224 | // are just middlemen in the operation since is the FileSystemPolicy which |
michael@0 | 225 | // knows what to do. |
michael@0 | 226 | EvalResult result = policy_base_->EvalPolicy( |
michael@0 | 227 | IPC_NTQUERYFULLATTRIBUTESFILE_TAG, params.GetBase()); |
michael@0 | 228 | |
michael@0 | 229 | FILE_NETWORK_OPEN_INFORMATION* information = |
michael@0 | 230 | reinterpret_cast<FILE_NETWORK_OPEN_INFORMATION*>(info->Buffer()); |
michael@0 | 231 | NTSTATUS nt_status; |
michael@0 | 232 | if (!FileSystemPolicy::QueryFullAttributesFileAction(result, |
michael@0 | 233 | *ipc->client_info, |
michael@0 | 234 | *name, attributes, |
michael@0 | 235 | information, |
michael@0 | 236 | &nt_status)) { |
michael@0 | 237 | ipc->return_info.nt_status = STATUS_ACCESS_DENIED; |
michael@0 | 238 | return true; |
michael@0 | 239 | } |
michael@0 | 240 | |
michael@0 | 241 | // Return operation status on the IPC. |
michael@0 | 242 | ipc->return_info.nt_status = nt_status; |
michael@0 | 243 | return true; |
michael@0 | 244 | } |
michael@0 | 245 | |
michael@0 | 246 | bool FilesystemDispatcher::NtSetInformationFile( |
michael@0 | 247 | IPCInfo* ipc, HANDLE handle, CountedBuffer* status, CountedBuffer* info, |
michael@0 | 248 | DWORD length, DWORD info_class) { |
michael@0 | 249 | if (sizeof(IO_STATUS_BLOCK) != status->Size()) |
michael@0 | 250 | return false; |
michael@0 | 251 | if (length != info->Size()) |
michael@0 | 252 | return false; |
michael@0 | 253 | |
michael@0 | 254 | FILE_RENAME_INFORMATION* rename_info = |
michael@0 | 255 | reinterpret_cast<FILE_RENAME_INFORMATION*>(info->Buffer()); |
michael@0 | 256 | |
michael@0 | 257 | if (!IsSupportedRenameCall(rename_info, length, info_class)) |
michael@0 | 258 | return false; |
michael@0 | 259 | |
michael@0 | 260 | std::wstring name; |
michael@0 | 261 | name.assign(rename_info->FileName, rename_info->FileNameLength / |
michael@0 | 262 | sizeof(rename_info->FileName[0])); |
michael@0 | 263 | if (!PreProcessName(name, &name)) { |
michael@0 | 264 | // The path requested might contain a reparse point. |
michael@0 | 265 | ipc->return_info.nt_status = STATUS_ACCESS_DENIED; |
michael@0 | 266 | return true; |
michael@0 | 267 | } |
michael@0 | 268 | |
michael@0 | 269 | ULONG broker = TRUE; |
michael@0 | 270 | const wchar_t* filename = name.c_str(); |
michael@0 | 271 | CountedParameterSet<FileName> params; |
michael@0 | 272 | params[FileName::NAME] = ParamPickerMake(filename); |
michael@0 | 273 | params[FileName::BROKER] = ParamPickerMake(broker); |
michael@0 | 274 | |
michael@0 | 275 | // To evaluate the policy we need to call back to the policy object. We |
michael@0 | 276 | // are just middlemen in the operation since is the FileSystemPolicy which |
michael@0 | 277 | // knows what to do. |
michael@0 | 278 | EvalResult result = policy_base_->EvalPolicy(IPC_NTSETINFO_RENAME_TAG, |
michael@0 | 279 | params.GetBase()); |
michael@0 | 280 | |
michael@0 | 281 | IO_STATUS_BLOCK* io_status = |
michael@0 | 282 | reinterpret_cast<IO_STATUS_BLOCK*>(status->Buffer()); |
michael@0 | 283 | NTSTATUS nt_status; |
michael@0 | 284 | if (!FileSystemPolicy::SetInformationFileAction(result, *ipc->client_info, |
michael@0 | 285 | handle, rename_info, length, |
michael@0 | 286 | info_class, io_status, |
michael@0 | 287 | &nt_status)) { |
michael@0 | 288 | ipc->return_info.nt_status = STATUS_ACCESS_DENIED; |
michael@0 | 289 | return true; |
michael@0 | 290 | } |
michael@0 | 291 | |
michael@0 | 292 | // Return operation status on the IPC. |
michael@0 | 293 | ipc->return_info.nt_status = nt_status; |
michael@0 | 294 | return true; |
michael@0 | 295 | } |
michael@0 | 296 | |
michael@0 | 297 | } // namespace sandbox |