Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: content/browser/bootstrap_sandbox_mac.cc

Issue 341073005: Define a bootstrap sandbox policy for renderer processes and enable it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | content/browser/mach_broker_mac.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/bootstrap_sandbox_mac.h" 5 #include "content/browser/bootstrap_sandbox_mac.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/mac/mac_util.h" 8 #include "base/mac/mac_util.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/singleton.h" 10 #include "base/memory/singleton.h"
11 #include "content/browser/mach_broker_mac.h"
11 #include "content/common/sandbox_init_mac.h" 12 #include "content/common/sandbox_init_mac.h"
12 #include "content/public/browser/browser_child_process_observer.h" 13 #include "content/public/browser/browser_child_process_observer.h"
13 #include "content/public/browser/child_process_data.h" 14 #include "content/public/browser/child_process_data.h"
15 #include "content/public/browser/notification_details.h"
16 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.h"
18 #include "content/public/browser/notification_service.h"
19 #include "content/public/browser/notification_types.h"
20 #include "content/public/browser/render_process_host.h"
14 #include "content/public/common/sandbox_type_mac.h" 21 #include "content/public/common/sandbox_type_mac.h"
15 #include "sandbox/mac/bootstrap_sandbox.h" 22 #include "sandbox/mac/bootstrap_sandbox.h"
16 23
17 namespace content { 24 namespace content {
18 25
19 namespace { 26 namespace {
20 27
21 // This class is responsible for creating the BootstrapSandbox global 28 // This class is responsible for creating the BootstrapSandbox global
22 // singleton, as well as registering all associated policies with it. 29 // singleton, as well as registering all associated policies with it.
23 class BootstrapSandboxPolicy : public BrowserChildProcessObserver { 30 class BootstrapSandboxPolicy : public BrowserChildProcessObserver,
31 public NotificationObserver {
24 public: 32 public:
25 static BootstrapSandboxPolicy* GetInstance(); 33 static BootstrapSandboxPolicy* GetInstance();
26 34
27 sandbox::BootstrapSandbox* sandbox() const { 35 sandbox::BootstrapSandbox* sandbox() const {
28 return sandbox_.get(); 36 return sandbox_.get();
29 } 37 }
30 38
31 // BrowserChildProcessObserver: 39 // BrowserChildProcessObserver:
32 virtual void BrowserChildProcessHostDisconnected( 40 virtual void BrowserChildProcessHostDisconnected(
33 const ChildProcessData& data) OVERRIDE; 41 const ChildProcessData& data) OVERRIDE;
34 virtual void BrowserChildProcessCrashed( 42 virtual void BrowserChildProcessCrashed(
35 const ChildProcessData& data) OVERRIDE; 43 const ChildProcessData& data) OVERRIDE;
36 44
45 // NotificationObserver:
46 virtual void Observe(int type,
47 const NotificationSource& source,
48 const NotificationDetails& details) OVERRIDE;
49
37 private: 50 private:
38 friend struct DefaultSingletonTraits<BootstrapSandboxPolicy>; 51 friend struct DefaultSingletonTraits<BootstrapSandboxPolicy>;
39 BootstrapSandboxPolicy(); 52 BootstrapSandboxPolicy();
40 virtual ~BootstrapSandboxPolicy(); 53 virtual ~BootstrapSandboxPolicy();
41 54
42 void RegisterSandboxPolicies(); 55 void RegisterSandboxPolicies();
56 void RegisterRendererPolicy();
57
58 void AddBaselinePolicy(sandbox::BootstrapSandboxPolicy* policy);
59
60 NotificationRegistrar notification_registrar_;
43 61
44 scoped_ptr<sandbox::BootstrapSandbox> sandbox_; 62 scoped_ptr<sandbox::BootstrapSandbox> sandbox_;
45 }; 63 };
46 64
47 BootstrapSandboxPolicy* BootstrapSandboxPolicy::GetInstance() { 65 BootstrapSandboxPolicy* BootstrapSandboxPolicy::GetInstance() {
48 return Singleton<BootstrapSandboxPolicy>::get(); 66 return Singleton<BootstrapSandboxPolicy>::get();
49 } 67 }
50 68
51 void BootstrapSandboxPolicy::BrowserChildProcessHostDisconnected( 69 void BootstrapSandboxPolicy::BrowserChildProcessHostDisconnected(
52 const ChildProcessData& data) { 70 const ChildProcessData& data) {
53 sandbox()->ChildDied(data.handle); 71 sandbox()->ChildDied(data.handle);
54 } 72 }
55 73
56 void BootstrapSandboxPolicy::BrowserChildProcessCrashed( 74 void BootstrapSandboxPolicy::BrowserChildProcessCrashed(
57 const ChildProcessData& data) { 75 const ChildProcessData& data) {
58 sandbox()->ChildDied(data.handle); 76 sandbox()->ChildDied(data.handle);
59 } 77 }
60 78
79 void BootstrapSandboxPolicy::Observe(int type,
80 const NotificationSource& source,
81 const NotificationDetails& details) {
82 switch (type) {
83 case NOTIFICATION_RENDERER_PROCESS_CLOSED:
84 sandbox()->ChildDied(
85 Details<RenderProcessHost::RendererClosedDetails>(details)->handle);
86 break;
87 default:
88 NOTREACHED() << "Unexpected notification " << type;
89 break;
90 }
91 }
92
61 BootstrapSandboxPolicy::BootstrapSandboxPolicy() 93 BootstrapSandboxPolicy::BootstrapSandboxPolicy()
62 : sandbox_(sandbox::BootstrapSandbox::Create()) { 94 : sandbox_(sandbox::BootstrapSandbox::Create()) {
63 CHECK(sandbox_.get()); 95 CHECK(sandbox_.get());
64 BrowserChildProcessObserver::Add(this); 96 BrowserChildProcessObserver::Add(this);
97 notification_registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSED,
98 NotificationService::AllBrowserContextsAndSources());
65 RegisterSandboxPolicies(); 99 RegisterSandboxPolicies();
66 } 100 }
67 101
68 BootstrapSandboxPolicy::~BootstrapSandboxPolicy() { 102 BootstrapSandboxPolicy::~BootstrapSandboxPolicy() {
69 BrowserChildProcessObserver::Remove(this); 103 BrowserChildProcessObserver::Remove(this);
70 } 104 }
71 105
72 void BootstrapSandboxPolicy::RegisterSandboxPolicies() { 106 void BootstrapSandboxPolicy::RegisterSandboxPolicies() {
107 RegisterRendererPolicy();
108 }
109
110 void BootstrapSandboxPolicy::RegisterRendererPolicy() {
111 sandbox::BootstrapSandboxPolicy policy;
112 AddBaselinePolicy(&policy);
113
114 // Permit font queries.
115 policy.rules["com.apple.FontServer"] = sandbox::Rule(sandbox::POLICY_ALLOW);
116 policy.rules["com.apple.FontObjectsServer"] =
117 sandbox::Rule(sandbox::POLICY_ALLOW);
118
119 // Return a fake port to the windowserver, otherwise CoreGraphics will log
120 // an error. On 10.6, returning an error (the default) is required instead
121 // of a dummy port.
122 if (!base::mac::IsOSSnowLeopard()) {
123 policy.rules["com.apple.windowserver.active"] =
124 sandbox::Rule(sandbox::POLICY_DENY_DUMMY_PORT);
125 }
126
127 sandbox_->RegisterSandboxPolicy(SANDBOX_TYPE_RENDERER, policy);
128 }
129
130 void BootstrapSandboxPolicy::AddBaselinePolicy(
131 sandbox::BootstrapSandboxPolicy* policy) {
132 auto& rules = policy->rules;
133
134 // Allow connecting to the MachBroker to get the new child's task port.
Mark Mentovai 2014/06/20 16:05:57 Because this function is concerned with setting up
Robert Sesek 2014/06/20 17:32:19 Done.
135 rules[MachBroker::GetMachPortName()] = sandbox::Rule(sandbox::POLICY_ALLOW);
Mark Mentovai 2014/06/20 16:05:57 For the future, it might be nice to have something
Robert Sesek 2014/06/20 17:32:19 That's an interesting idea. Would require a separa
136
137 // Allow logging to the syslog.
138 rules["com.apple.system.logger"] = sandbox::Rule(sandbox::POLICY_ALLOW);
73 } 139 }
74 140
75 } // namespace 141 } // namespace
76 142
77 bool ShouldEnableBootstrapSandbox() { 143 bool ShouldEnableBootstrapSandbox() {
78 return base::mac::IsOSMountainLionOrEarlier() || 144 return base::mac::IsOSMavericksOrEarlier();
79 base::mac::IsOSMavericks();
80 } 145 }
81 146
82 sandbox::BootstrapSandbox* GetBootstrapSandbox() { 147 sandbox::BootstrapSandbox* GetBootstrapSandbox() {
83 return BootstrapSandboxPolicy::GetInstance()->sandbox(); 148 return BootstrapSandboxPolicy::GetInstance()->sandbox();
84 } 149 }
85 150
86 } // namespace content 151 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/mach_broker_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698