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) 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_policy.h" |
michael@0 | 6 | |
michael@0 | 7 | #include <string> |
michael@0 | 8 | |
michael@0 | 9 | #include "base/win/scoped_handle.h" |
michael@0 | 10 | #include "sandbox/win/src/broker_services.h" |
michael@0 | 11 | #include "sandbox/win/src/ipc_tags.h" |
michael@0 | 12 | #include "sandbox/win/src/policy_engine_opcodes.h" |
michael@0 | 13 | #include "sandbox/win/src/policy_params.h" |
michael@0 | 14 | #include "sandbox/win/src/sandbox_types.h" |
michael@0 | 15 | #include "sandbox/win/src/sandbox_utils.h" |
michael@0 | 16 | |
michael@0 | 17 | namespace sandbox { |
michael@0 | 18 | |
michael@0 | 19 | bool HandlePolicy::GenerateRules(const wchar_t* type_name, |
michael@0 | 20 | TargetPolicy::Semantics semantics, |
michael@0 | 21 | LowLevelPolicy* policy) { |
michael@0 | 22 | PolicyRule duplicate_rule(ASK_BROKER); |
michael@0 | 23 | |
michael@0 | 24 | switch (semantics) { |
michael@0 | 25 | case TargetPolicy::HANDLES_DUP_ANY: { |
michael@0 | 26 | if (!duplicate_rule.AddNumberMatch(IF_NOT, HandleTarget::TARGET, |
michael@0 | 27 | ::GetCurrentProcessId(), EQUAL)) { |
michael@0 | 28 | return false; |
michael@0 | 29 | } |
michael@0 | 30 | break; |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | case TargetPolicy::HANDLES_DUP_BROKER: { |
michael@0 | 34 | if (!duplicate_rule.AddNumberMatch(IF, HandleTarget::TARGET, |
michael@0 | 35 | ::GetCurrentProcessId(), EQUAL)) { |
michael@0 | 36 | return false; |
michael@0 | 37 | } |
michael@0 | 38 | break; |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | default: |
michael@0 | 42 | return false; |
michael@0 | 43 | } |
michael@0 | 44 | if (!duplicate_rule.AddStringMatch(IF, HandleTarget::NAME, type_name, |
michael@0 | 45 | CASE_INSENSITIVE)) { |
michael@0 | 46 | return false; |
michael@0 | 47 | } |
michael@0 | 48 | if (!policy->AddRule(IPC_DUPLICATEHANDLEPROXY_TAG, &duplicate_rule)) { |
michael@0 | 49 | return false; |
michael@0 | 50 | } |
michael@0 | 51 | return true; |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | DWORD HandlePolicy::DuplicateHandleProxyAction(EvalResult eval_result, |
michael@0 | 55 | const ClientInfo& client_info, |
michael@0 | 56 | HANDLE source_handle, |
michael@0 | 57 | DWORD target_process_id, |
michael@0 | 58 | HANDLE* target_handle, |
michael@0 | 59 | DWORD desired_access, |
michael@0 | 60 | DWORD options) { |
michael@0 | 61 | // The only action supported is ASK_BROKER which means duplicate the handle. |
michael@0 | 62 | if (ASK_BROKER != eval_result) { |
michael@0 | 63 | return ERROR_ACCESS_DENIED; |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | base::win::ScopedHandle remote_target_process; |
michael@0 | 67 | if (target_process_id != ::GetCurrentProcessId()) { |
michael@0 | 68 | // Sandboxed children are dynamic, so we check that manually. |
michael@0 | 69 | if (!BrokerServicesBase::GetInstance()->IsActiveTarget(target_process_id)) { |
michael@0 | 70 | return ERROR_ACCESS_DENIED; |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | remote_target_process.Set(::OpenProcess(PROCESS_DUP_HANDLE, FALSE, |
michael@0 | 74 | target_process_id)); |
michael@0 | 75 | if (!remote_target_process.IsValid()) |
michael@0 | 76 | return ::GetLastError(); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | // If the policy didn't block us and we have no valid target, then the broker |
michael@0 | 80 | // (this process) is the valid target. |
michael@0 | 81 | HANDLE target_process = remote_target_process.IsValid() ? |
michael@0 | 82 | remote_target_process.Get() : ::GetCurrentProcess(); |
michael@0 | 83 | DWORD result = ERROR_SUCCESS; |
michael@0 | 84 | if (!::DuplicateHandle(client_info.process, source_handle, target_process, |
michael@0 | 85 | target_handle, desired_access, FALSE, |
michael@0 | 86 | options)) { |
michael@0 | 87 | return ::GetLastError(); |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | return ERROR_SUCCESS; |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | } // namespace sandbox |
michael@0 | 94 |