security/sandbox/win/src/handle_dispatcher.cc

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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) 2012 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/handle_dispatcher.h"
michael@0 6
michael@0 7 #include "base/win/scoped_handle.h"
michael@0 8 #include "sandbox/win/src/handle_interception.h"
michael@0 9 #include "sandbox/win/src/handle_policy.h"
michael@0 10 #include "sandbox/win/src/ipc_tags.h"
michael@0 11 #include "sandbox/win/src/policy_broker.h"
michael@0 12 #include "sandbox/win/src/policy_params.h"
michael@0 13 #include "sandbox/win/src/sandbox.h"
michael@0 14 #include "sandbox/win/src/sandbox_nt_util.h"
michael@0 15 #include "sandbox/win/src/sandbox_types.h"
michael@0 16 #include "sandbox/win/src/sandbox_utils.h"
michael@0 17
michael@0 18 namespace sandbox {
michael@0 19
michael@0 20 HandleDispatcher::HandleDispatcher(PolicyBase* policy_base)
michael@0 21 : policy_base_(policy_base) {
michael@0 22 static const IPCCall duplicate_handle_proxy = {
michael@0 23 {IPC_DUPLICATEHANDLEPROXY_TAG, VOIDPTR_TYPE, ULONG_TYPE, ULONG_TYPE,
michael@0 24 ULONG_TYPE},
michael@0 25 reinterpret_cast<CallbackGeneric>(&HandleDispatcher::DuplicateHandleProxy)
michael@0 26 };
michael@0 27
michael@0 28 ipc_calls_.push_back(duplicate_handle_proxy);
michael@0 29 }
michael@0 30
michael@0 31 bool HandleDispatcher::SetupService(InterceptionManager* manager,
michael@0 32 int service) {
michael@0 33 // We perform no interceptions for handles right now.
michael@0 34 switch (service) {
michael@0 35 case IPC_DUPLICATEHANDLEPROXY_TAG:
michael@0 36 return true;
michael@0 37 }
michael@0 38
michael@0 39 return false;
michael@0 40 }
michael@0 41
michael@0 42 bool HandleDispatcher::DuplicateHandleProxy(IPCInfo* ipc,
michael@0 43 HANDLE source_handle,
michael@0 44 DWORD target_process_id,
michael@0 45 DWORD desired_access,
michael@0 46 DWORD options) {
michael@0 47 NTSTATUS error;
michael@0 48 static NtQueryObject QueryObject = NULL;
michael@0 49 if (!QueryObject)
michael@0 50 ResolveNTFunctionPtr("NtQueryObject", &QueryObject);
michael@0 51
michael@0 52 // Get a copy of the handle for use in the broker process.
michael@0 53 HANDLE handle_temp;
michael@0 54 if (!::DuplicateHandle(ipc->client_info->process, source_handle,
michael@0 55 ::GetCurrentProcess(), &handle_temp,
michael@0 56 0, FALSE, DUPLICATE_SAME_ACCESS)) {
michael@0 57 ipc->return_info.win32_result = ::GetLastError();
michael@0 58 return false;
michael@0 59 }
michael@0 60 base::win::ScopedHandle handle(handle_temp);
michael@0 61
michael@0 62 // Get the object type (32 characters is safe; current max is 14).
michael@0 63 BYTE buffer[sizeof(OBJECT_TYPE_INFORMATION) + 32 * sizeof(wchar_t)];
michael@0 64 OBJECT_TYPE_INFORMATION* type_info =
michael@0 65 reinterpret_cast<OBJECT_TYPE_INFORMATION*>(buffer);
michael@0 66 ULONG size = sizeof(buffer) - sizeof(wchar_t);
michael@0 67 error = QueryObject(handle, ObjectTypeInformation, type_info, size, &size);
michael@0 68 if (!NT_SUCCESS(error)) {
michael@0 69 ipc->return_info.win32_result = error;
michael@0 70 return false;
michael@0 71 }
michael@0 72 type_info->Name.Buffer[type_info->Name.Length / sizeof(wchar_t)] = L'\0';
michael@0 73
michael@0 74 CountedParameterSet<HandleTarget> params;
michael@0 75 params[HandleTarget::NAME] = ParamPickerMake(type_info->Name.Buffer);
michael@0 76 params[HandleTarget::TARGET] = ParamPickerMake(target_process_id);
michael@0 77
michael@0 78 EvalResult eval = policy_base_->EvalPolicy(IPC_DUPLICATEHANDLEPROXY_TAG,
michael@0 79 params.GetBase());
michael@0 80 ipc->return_info.win32_result =
michael@0 81 HandlePolicy::DuplicateHandleProxyAction(eval, *ipc->client_info,
michael@0 82 source_handle,
michael@0 83 target_process_id,
michael@0 84 &ipc->return_info.handle,
michael@0 85 desired_access, options);
michael@0 86 return true;
michael@0 87 }
michael@0 88
michael@0 89 } // namespace sandbox
michael@0 90

mercurial