rsesek | dba8411 | 2015-09-18 19:22:07 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "content/browser/bootstrap_sandbox_manager_mac.h" |
| 6 | |
| 7 | #include "base/logging.h" |
| 8 | #include "base/mac/mac_util.h" |
rsesek | dba8411 | 2015-09-18 19:22:07 | [diff] [blame] | 9 | #include "content/browser/mach_broker_mac.h" |
| 10 | #include "content/common/sandbox_init_mac.h" |
| 11 | #include "content/public/browser/browser_thread.h" |
| 12 | #include "content/public/browser/child_process_data.h" |
| 13 | #include "content/public/browser/render_process_host.h" |
| 14 | #include "sandbox/mac/bootstrap_sandbox.h" |
| 15 | |
| 16 | namespace content { |
| 17 | |
| 18 | // static |
| 19 | bool BootstrapSandboxManager::ShouldEnable() { |
rsesek | ce0bd33 | 2015-10-01 15:20:55 | [diff] [blame] | 20 | return false; |
rsesek | dba8411 | 2015-09-18 19:22:07 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | // static |
| 24 | BootstrapSandboxManager* BootstrapSandboxManager::GetInstance() { |
| 25 | return base::Singleton<BootstrapSandboxManager>::get(); |
| 26 | } |
| 27 | |
| 28 | bool BootstrapSandboxManager::EnabledForSandbox(SandboxType sandbox_type) { |
| 29 | return sandbox_type == SANDBOX_TYPE_RENDERER; |
| 30 | } |
| 31 | |
| 32 | void BootstrapSandboxManager::BrowserChildProcessHostDisconnected( |
| 33 | const ChildProcessData& data) { |
| 34 | sandbox()->InvalidateClient(data.handle); |
| 35 | } |
| 36 | |
| 37 | void BootstrapSandboxManager::BrowserChildProcessCrashed( |
| 38 | const ChildProcessData& data, |
| 39 | int exit_code) { |
| 40 | sandbox()->InvalidateClient(data.handle); |
| 41 | } |
| 42 | |
| 43 | void BootstrapSandboxManager::RenderProcessExited( |
| 44 | RenderProcessHost* host, |
| 45 | base::TerminationStatus status, |
| 46 | int exit_code) { |
| 47 | sandbox()->InvalidateClient(host->GetHandle()); |
| 48 | } |
| 49 | |
| 50 | BootstrapSandboxManager::BootstrapSandboxManager() |
| 51 | : sandbox_(sandbox::BootstrapSandbox::Create()) { |
| 52 | CHECK(sandbox_.get()); |
| 53 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 54 | BrowserChildProcessObserver::Add(this); |
| 55 | RegisterSandboxPolicies(); |
| 56 | } |
| 57 | |
| 58 | BootstrapSandboxManager::~BootstrapSandboxManager() { |
| 59 | BrowserChildProcessObserver::Remove(this); |
| 60 | } |
| 61 | |
| 62 | void BootstrapSandboxManager::RegisterSandboxPolicies() { |
| 63 | RegisterRendererPolicy(); |
| 64 | } |
| 65 | |
| 66 | void BootstrapSandboxManager::RegisterRendererPolicy() { |
| 67 | sandbox::BootstrapSandboxPolicy policy; |
| 68 | AddBaselinePolicy(&policy); |
| 69 | |
| 70 | // Permit font queries. |
| 71 | policy.rules["com.apple.FontServer"] = sandbox::Rule(sandbox::POLICY_ALLOW); |
| 72 | policy.rules["com.apple.FontObjectsServer"] = |
| 73 | sandbox::Rule(sandbox::POLICY_ALLOW); |
| 74 | |
| 75 | // Allow access to the windowserver. This is needed to get the colorspace |
| 76 | // during sandbox warmup. Since NSColorSpace conforms to NSCoding, this |
| 77 | // should be plumbed over IPC instead <http://crbug.com/265709>. |
| 78 | policy.rules["com.apple.windowserver.active"] = |
| 79 | sandbox::Rule(sandbox::POLICY_ALLOW); |
| 80 | |
rsesek | dba8411 | 2015-09-18 19:22:07 | [diff] [blame] | 81 | // Allow access to launchservicesd on 10.10+ otherwise the renderer will crash |
| 82 | // attempting to get its ASN. http://crbug.com/533537 |
| 83 | if (base::mac::IsOSYosemiteOrLater()) { |
| 84 | policy.rules["com.apple.coreservices.launchservicesd"] = |
| 85 | sandbox::Rule(sandbox::POLICY_ALLOW); |
| 86 | } |
| 87 | |
| 88 | sandbox_->RegisterSandboxPolicy(SANDBOX_TYPE_RENDERER, policy); |
| 89 | } |
| 90 | |
| 91 | void BootstrapSandboxManager::AddBaselinePolicy( |
| 92 | sandbox::BootstrapSandboxPolicy* policy) { |
| 93 | auto& rules = policy->rules; |
| 94 | |
| 95 | // Allow the child to send its task port to the MachBroker. |
| 96 | rules[MachBroker::GetMachPortName()] = sandbox::Rule(sandbox::POLICY_ALLOW); |
| 97 | |
| 98 | // Allow logging to the syslog. |
| 99 | rules["com.apple.system.logger"] = sandbox::Rule(sandbox::POLICY_ALLOW); |
| 100 | } |
| 101 | |
| 102 | } // namespace content |