blob: 61d1b1e3b04bb09c40f72df3386c96fa62574cb5 [file] [log] [blame]
rsesekdba84112015-09-18 19:22:071// 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"
rsesekdba84112015-09-18 19:22:079#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
16namespace content {
17
18// static
19bool BootstrapSandboxManager::ShouldEnable() {
rsesekce0bd332015-10-01 15:20:5520 return false;
rsesekdba84112015-09-18 19:22:0721}
22
23// static
24BootstrapSandboxManager* BootstrapSandboxManager::GetInstance() {
25 return base::Singleton<BootstrapSandboxManager>::get();
26}
27
28bool BootstrapSandboxManager::EnabledForSandbox(SandboxType sandbox_type) {
29 return sandbox_type == SANDBOX_TYPE_RENDERER;
30}
31
32void BootstrapSandboxManager::BrowserChildProcessHostDisconnected(
33 const ChildProcessData& data) {
34 sandbox()->InvalidateClient(data.handle);
35}
36
37void BootstrapSandboxManager::BrowserChildProcessCrashed(
38 const ChildProcessData& data,
39 int exit_code) {
40 sandbox()->InvalidateClient(data.handle);
41}
42
43void BootstrapSandboxManager::RenderProcessExited(
44 RenderProcessHost* host,
45 base::TerminationStatus status,
46 int exit_code) {
47 sandbox()->InvalidateClient(host->GetHandle());
48}
49
50BootstrapSandboxManager::BootstrapSandboxManager()
51 : sandbox_(sandbox::BootstrapSandbox::Create()) {
52 CHECK(sandbox_.get());
53 DCHECK_CURRENTLY_ON(BrowserThread::UI);
54 BrowserChildProcessObserver::Add(this);
55 RegisterSandboxPolicies();
56}
57
58BootstrapSandboxManager::~BootstrapSandboxManager() {
59 BrowserChildProcessObserver::Remove(this);
60}
61
62void BootstrapSandboxManager::RegisterSandboxPolicies() {
63 RegisterRendererPolicy();
64}
65
66void 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
rsesekdba84112015-09-18 19:22:0781 // 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
91void 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