OLD | NEW |
---|---|
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( | |
Avi (use Gerrit)
2014/06/19 23:59:47
This is eventually going to be called by other pol
Robert Sesek
2014/06/20 14:47:20
Yes. Utility and PPAPI types will both have polici
| |
131 sandbox::BootstrapSandboxPolicy* policy) { | |
132 auto& rules = policy->rules; | |
133 | |
134 // Allow connecting to the MachBroker to get the new child's task port. | |
135 rules[MachBroker::GetMachPortName()] = sandbox::Rule(sandbox::POLICY_ALLOW); | |
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::IsOSMountainLionOrEarlier() || |
79 base::mac::IsOSMavericks(); | 145 base::mac::IsOSMavericks(); |
Avi (use Gerrit)
2014/06/19 23:59:47
IsOSMavericksOrEarlier?
Robert Sesek
2014/06/20 14:47:20
Done. Wasn't available when I needed it :).
| |
80 } | 146 } |
81 | 147 |
82 sandbox::BootstrapSandbox* GetBootstrapSandbox() { | 148 sandbox::BootstrapSandbox* GetBootstrapSandbox() { |
83 return BootstrapSandboxPolicy::GetInstance()->sandbox(); | 149 return BootstrapSandboxPolicy::GetInstance()->sandbox(); |
84 } | 150 } |
85 | 151 |
86 } // namespace content | 152 } // namespace content |
OLD | NEW |