summaryrefslogtreecommitdiff
path: root/chromium/content/browser/bootstrap_sandbox_manager_mac.cc
blob: 48d25491429665a76e9edc43e6af364f6fff4965 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/bootstrap_sandbox_manager_mac.h"

#include "base/logging.h"
#include "base/mac/mac_util.h"
#include "content/browser/browser_io_surface_manager_mac.h"
#include "content/browser/mach_broker_mac.h"
#include "content/common/sandbox_init_mac.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_data.h"
#include "content/public/browser/render_process_host.h"
#include "sandbox/mac/bootstrap_sandbox.h"

namespace content {

// static
bool BootstrapSandboxManager::ShouldEnable() {
  return false;
}

// static
BootstrapSandboxManager* BootstrapSandboxManager::GetInstance() {
  return base::Singleton<BootstrapSandboxManager>::get();
}

bool BootstrapSandboxManager::EnabledForSandbox(SandboxType sandbox_type) {
  return sandbox_type == SANDBOX_TYPE_RENDERER;
}

void BootstrapSandboxManager::BrowserChildProcessHostDisconnected(
      const ChildProcessData& data) {
  sandbox()->InvalidateClient(data.handle);
}

void BootstrapSandboxManager::BrowserChildProcessCrashed(
      const ChildProcessData& data,
      int exit_code) {
  sandbox()->InvalidateClient(data.handle);
}

void BootstrapSandboxManager::RenderProcessExited(
    RenderProcessHost* host,
    base::TerminationStatus status,
    int exit_code) {
  sandbox()->InvalidateClient(host->GetHandle());
}

BootstrapSandboxManager::BootstrapSandboxManager()
    : sandbox_(sandbox::BootstrapSandbox::Create()) {
  CHECK(sandbox_.get());
  DCHECK_CURRENTLY_ON(BrowserThread::UI);
  BrowserChildProcessObserver::Add(this);
  RegisterSandboxPolicies();
}

BootstrapSandboxManager::~BootstrapSandboxManager() {
  BrowserChildProcessObserver::Remove(this);
}

void BootstrapSandboxManager::RegisterSandboxPolicies() {
  RegisterRendererPolicy();
}

void BootstrapSandboxManager::RegisterRendererPolicy() {
  sandbox::BootstrapSandboxPolicy policy;
  AddBaselinePolicy(&policy);

  // Permit font queries.
  policy.rules["com.apple.FontServer"] = sandbox::Rule(sandbox::POLICY_ALLOW);
  policy.rules["com.apple.FontObjectsServer"] =
      sandbox::Rule(sandbox::POLICY_ALLOW);

  // Allow access to the windowserver. This is needed to get the colorspace
  // during sandbox warmup. Since NSColorSpace conforms to NSCoding, this
  // should be plumbed over IPC instead <http://crbug.com/265709>.
  policy.rules["com.apple.windowserver.active"] =
      sandbox::Rule(sandbox::POLICY_ALLOW);

  // Allow renderers to contact the IOSurfaceManager in the browser to share
  // accelerated surfaces.
  policy.rules[BrowserIOSurfaceManager::GetMachPortName()] =
      sandbox::Rule(sandbox::POLICY_ALLOW);

  // Allow access to launchservicesd on 10.10+ otherwise the renderer will crash
  // attempting to get its ASN. http://crbug.com/533537
  if (base::mac::IsOSYosemiteOrLater()) {
    policy.rules["com.apple.coreservices.launchservicesd"] =
        sandbox::Rule(sandbox::POLICY_ALLOW);
  }

  sandbox_->RegisterSandboxPolicy(SANDBOX_TYPE_RENDERER, policy);
}

void BootstrapSandboxManager::AddBaselinePolicy(
    sandbox::BootstrapSandboxPolicy* policy) {
  auto& rules = policy->rules;

  // Allow the child to send its task port to the MachBroker.
  rules[MachBroker::GetMachPortName()] = sandbox::Rule(sandbox::POLICY_ALLOW);

  // Allow logging to the syslog.
  rules["com.apple.system.logger"] = sandbox::Rule(sandbox::POLICY_ALLOW);
}

}  // namespace content