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-2008 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/sync_interception.h" |
michael@0 | 6 | |
michael@0 | 7 | #include "sandbox/win/src/crosscall_client.h" |
michael@0 | 8 | #include "sandbox/win/src/ipc_tags.h" |
michael@0 | 9 | #include "sandbox/win/src/policy_params.h" |
michael@0 | 10 | #include "sandbox/win/src/policy_target.h" |
michael@0 | 11 | #include "sandbox/win/src/sandbox_factory.h" |
michael@0 | 12 | #include "sandbox/win/src/sandbox_nt_util.h" |
michael@0 | 13 | #include "sandbox/win/src/sharedmem_ipc_client.h" |
michael@0 | 14 | #include "sandbox/win/src/target_services.h" |
michael@0 | 15 | |
michael@0 | 16 | namespace sandbox { |
michael@0 | 17 | |
michael@0 | 18 | HANDLE WINAPI TargetCreateEventW(CreateEventWFunction orig_CreateEvent, |
michael@0 | 19 | LPSECURITY_ATTRIBUTES security_attributes, |
michael@0 | 20 | BOOL manual_reset, BOOL initial_state, |
michael@0 | 21 | LPCWSTR name) { |
michael@0 | 22 | // Check if the process can create it first. |
michael@0 | 23 | HANDLE handle = orig_CreateEvent(security_attributes, manual_reset, |
michael@0 | 24 | initial_state, name); |
michael@0 | 25 | DWORD original_error = ::GetLastError(); |
michael@0 | 26 | if (NULL != handle) |
michael@0 | 27 | return handle; |
michael@0 | 28 | |
michael@0 | 29 | // We don't trust that the IPC can work this early. |
michael@0 | 30 | if (!SandboxFactory::GetTargetServices()->GetState()->InitCalled()) |
michael@0 | 31 | return NULL; |
michael@0 | 32 | |
michael@0 | 33 | do { |
michael@0 | 34 | if (security_attributes) |
michael@0 | 35 | break; |
michael@0 | 36 | |
michael@0 | 37 | void* memory = GetGlobalIPCMemory(); |
michael@0 | 38 | if (NULL == memory) |
michael@0 | 39 | break; |
michael@0 | 40 | |
michael@0 | 41 | CountedParameterSet<NameBased> params; |
michael@0 | 42 | params[NameBased::NAME] = ParamPickerMake(name); |
michael@0 | 43 | |
michael@0 | 44 | if (!QueryBroker(IPC_CREATEEVENT_TAG, params.GetBase())) |
michael@0 | 45 | break; |
michael@0 | 46 | |
michael@0 | 47 | SharedMemIPCClient ipc(memory); |
michael@0 | 48 | CrossCallReturn answer = {0}; |
michael@0 | 49 | ResultCode code = CrossCall(ipc, IPC_CREATEEVENT_TAG, name, manual_reset, |
michael@0 | 50 | initial_state, &answer); |
michael@0 | 51 | |
michael@0 | 52 | if (SBOX_ALL_OK != code) |
michael@0 | 53 | break; |
michael@0 | 54 | |
michael@0 | 55 | ::SetLastError(answer.win32_result); |
michael@0 | 56 | return answer.handle; |
michael@0 | 57 | } while (false); |
michael@0 | 58 | |
michael@0 | 59 | ::SetLastError(original_error); |
michael@0 | 60 | return NULL; |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | // Interception of OpenEventW on the child process. |
michael@0 | 64 | // It should never be called directly |
michael@0 | 65 | HANDLE WINAPI TargetOpenEventW(OpenEventWFunction orig_OpenEvent, |
michael@0 | 66 | ACCESS_MASK desired_access, BOOL inherit_handle, |
michael@0 | 67 | LPCWSTR name) { |
michael@0 | 68 | // Check if the process can open it first. |
michael@0 | 69 | HANDLE handle = orig_OpenEvent(desired_access, inherit_handle, name); |
michael@0 | 70 | DWORD original_error = ::GetLastError(); |
michael@0 | 71 | if (NULL != handle) |
michael@0 | 72 | return handle; |
michael@0 | 73 | |
michael@0 | 74 | // We don't trust that the IPC can work this early. |
michael@0 | 75 | if (!SandboxFactory::GetTargetServices()->GetState()->InitCalled()) |
michael@0 | 76 | return NULL; |
michael@0 | 77 | |
michael@0 | 78 | do { |
michael@0 | 79 | void* memory = GetGlobalIPCMemory(); |
michael@0 | 80 | if (NULL == memory) |
michael@0 | 81 | break; |
michael@0 | 82 | |
michael@0 | 83 | uint32 inherit_handle_ipc = inherit_handle; |
michael@0 | 84 | CountedParameterSet<OpenEventParams> params; |
michael@0 | 85 | params[OpenEventParams::NAME] = ParamPickerMake(name); |
michael@0 | 86 | params[OpenEventParams::ACCESS] = ParamPickerMake(desired_access); |
michael@0 | 87 | |
michael@0 | 88 | if (!QueryBroker(IPC_OPENEVENT_TAG, params.GetBase())) |
michael@0 | 89 | break; |
michael@0 | 90 | |
michael@0 | 91 | SharedMemIPCClient ipc(memory); |
michael@0 | 92 | CrossCallReturn answer = {0}; |
michael@0 | 93 | ResultCode code = CrossCall(ipc, IPC_OPENEVENT_TAG, name, desired_access, |
michael@0 | 94 | inherit_handle_ipc, &answer); |
michael@0 | 95 | |
michael@0 | 96 | if (SBOX_ALL_OK != code) |
michael@0 | 97 | break; |
michael@0 | 98 | |
michael@0 | 99 | ::SetLastError(answer.win32_result); |
michael@0 | 100 | return answer.handle; |
michael@0 | 101 | } while (false); |
michael@0 | 102 | |
michael@0 | 103 | ::SetLastError(original_error); |
michael@0 | 104 | return NULL; |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | } // namespace sandbox |