OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/utility_process_host_impl.h" | 5 #include "content/browser/utility_process_host_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/sequenced_task_runner.h" | 13 #include "base/sequenced_task_runner.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
16 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
17 #include "content/browser/browser_child_process_host_impl.h" | 17 #include "content/browser/browser_child_process_host_impl.h" |
18 #include "content/browser/renderer_host/render_process_host_impl.h" | 18 #include "content/browser/renderer_host/render_process_host_impl.h" |
19 #include "content/common/child_process_host_impl.h" | 19 #include "content/common/child_process_host_impl.h" |
20 #include "content/common/utility_messages.h" | 20 #include "content/common/utility_messages.h" |
21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
22 #include "content/public/browser/content_browser_client.h" | 22 #include "content/public/browser/content_browser_client.h" |
23 #include "content/public/browser/utility_process_host_client.h" | 23 #include "content/public/browser/utility_process_host_client.h" |
24 #include "content/public/common/content_switches.h" | 24 #include "content/public/common/content_switches.h" |
25 #include "content/public/common/process_type.h" | 25 #include "content/public/common/process_type.h" |
| 26 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
26 #include "ipc/ipc_switches.h" | 27 #include "ipc/ipc_switches.h" |
27 #include "ui/base/ui_base_switches.h" | 28 #include "ui/base/ui_base_switches.h" |
28 | 29 |
29 #if defined(OS_WIN) | |
30 #include "content/public/common/sandboxed_process_launcher_delegate.h" | |
31 #endif | |
32 | |
33 namespace content { | 30 namespace content { |
34 | 31 |
35 #if defined(OS_WIN) | |
36 // NOTE: changes to this class need to be reviewed by the security team. | 32 // NOTE: changes to this class need to be reviewed by the security team. |
37 class UtilitySandboxedProcessLauncherDelegate | 33 class UtilitySandboxedProcessLauncherDelegate |
38 : public SandboxedProcessLauncherDelegate { | 34 : public SandboxedProcessLauncherDelegate { |
39 public: | 35 public: |
40 explicit UtilitySandboxedProcessLauncherDelegate( | 36 UtilitySandboxedProcessLauncherDelegate(const base::FilePath& exposed_dir, |
41 const base::FilePath& exposed_dir) : exposed_dir_(exposed_dir) {} | 37 bool launch_elevated, bool no_sandbox, |
| 38 base::EnvironmentMap& env, |
| 39 ChildProcessHost* host) |
| 40 : exposed_dir_(exposed_dir), |
| 41 #if defined(OS_WIN) |
| 42 launch_elevated_(launch_elevated) |
| 43 #elif defined(OS_POSIX) |
| 44 env_(env), |
| 45 no_sandbox_(no_sandbox), |
| 46 ipc_fd_(host->TakeClientFileDescriptor()) |
| 47 #endif // OS_WIN |
| 48 {} |
| 49 |
42 virtual ~UtilitySandboxedProcessLauncherDelegate() {} | 50 virtual ~UtilitySandboxedProcessLauncherDelegate() {} |
43 | 51 |
| 52 #if defined(OS_WIN) |
| 53 virtual bool ShouldLaunchElevated() OVERRIDE { |
| 54 return launch_elevated_; |
| 55 } |
44 virtual void PreSandbox(bool* disable_default_policy, | 56 virtual void PreSandbox(bool* disable_default_policy, |
45 base::FilePath* exposed_dir) OVERRIDE { | 57 base::FilePath* exposed_dir) OVERRIDE { |
46 *exposed_dir = exposed_dir_; | 58 *exposed_dir = exposed_dir_; |
47 } | 59 } |
| 60 #elif defined(OS_POSIX) |
48 | 61 |
49 private: | 62 virtual bool ShouldUseZygote() OVERRIDE { |
50 base::FilePath exposed_dir_; | 63 return !no_sandbox_ && exposed_dir_.empty(); |
| 64 } |
| 65 virtual base::EnvironmentMap GetEnvironment() OVERRIDE { |
| 66 return env_; |
| 67 } |
| 68 virtual int GetIpcFd() OVERRIDE { |
| 69 return ipc_fd_; |
| 70 } |
| 71 #endif // OS_WIN |
| 72 |
| 73 private: |
| 74 |
| 75 base::FilePath exposed_dir_; |
| 76 |
| 77 #if defined(OS_WIN) |
| 78 bool launch_elevated_; |
| 79 #elif defined(OS_POSIX) |
| 80 base::EnvironmentMap env_; |
| 81 bool no_sandbox_; |
| 82 int ipc_fd_; |
| 83 #endif // OS_WIN |
51 }; | 84 }; |
52 #endif | |
53 | |
54 | 85 |
55 UtilityMainThreadFactoryFunction g_utility_main_thread_factory = NULL; | 86 UtilityMainThreadFactoryFunction g_utility_main_thread_factory = NULL; |
56 | 87 |
57 UtilityProcessHost* UtilityProcessHost::Create( | 88 UtilityProcessHost* UtilityProcessHost::Create( |
58 UtilityProcessHostClient* client, | 89 UtilityProcessHostClient* client, |
59 base::SequencedTaskRunner* client_task_runner) { | 90 base::SequencedTaskRunner* client_task_runner) { |
60 return new UtilityProcessHostImpl(client, client_task_runner); | 91 return new UtilityProcessHostImpl(client, client_task_runner); |
61 } | 92 } |
62 | 93 |
63 void UtilityProcessHost::RegisterUtilityMainThreadFactory( | 94 void UtilityProcessHost::RegisterUtilityMainThreadFactory( |
64 UtilityMainThreadFactoryFunction create) { | 95 UtilityMainThreadFactoryFunction create) { |
65 g_utility_main_thread_factory = create; | 96 g_utility_main_thread_factory = create; |
66 } | 97 } |
67 | 98 |
68 UtilityProcessHostImpl::UtilityProcessHostImpl( | 99 UtilityProcessHostImpl::UtilityProcessHostImpl( |
69 UtilityProcessHostClient* client, | 100 UtilityProcessHostClient* client, |
70 base::SequencedTaskRunner* client_task_runner) | 101 base::SequencedTaskRunner* client_task_runner) |
71 : client_(client), | 102 : client_(client), |
72 client_task_runner_(client_task_runner), | 103 client_task_runner_(client_task_runner), |
73 is_batch_mode_(false), | 104 is_batch_mode_(false), |
74 is_mdns_enabled_(false), | 105 is_mdns_enabled_(false), |
75 no_sandbox_(false), | 106 no_sandbox_(false), |
76 #if defined(OS_WIN) | |
77 run_elevated_(false), | 107 run_elevated_(false), |
78 #endif | |
79 #if defined(OS_LINUX) | 108 #if defined(OS_LINUX) |
80 child_flags_(ChildProcessHost::CHILD_ALLOW_SELF), | 109 child_flags_(ChildProcessHost::CHILD_ALLOW_SELF), |
81 #else | 110 #else |
82 child_flags_(ChildProcessHost::CHILD_NORMAL), | 111 child_flags_(ChildProcessHost::CHILD_NORMAL), |
83 #endif | 112 #endif |
84 started_(false) { | 113 started_(false) { |
85 } | 114 } |
86 | 115 |
87 UtilityProcessHostImpl::~UtilityProcessHostImpl() { | 116 UtilityProcessHostImpl::~UtilityProcessHostImpl() { |
88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 | 248 |
220 if (is_mdns_enabled_) | 249 if (is_mdns_enabled_) |
221 cmd_line->AppendSwitch(switches::kUtilityProcessEnableMDns); | 250 cmd_line->AppendSwitch(switches::kUtilityProcessEnableMDns); |
222 | 251 |
223 #if defined(OS_WIN) | 252 #if defined(OS_WIN) |
224 // Let the utility process know if it is intended to be elevated. | 253 // Let the utility process know if it is intended to be elevated. |
225 if (run_elevated_) | 254 if (run_elevated_) |
226 cmd_line->AppendSwitch(switches::kUtilityProcessRunningElevated); | 255 cmd_line->AppendSwitch(switches::kUtilityProcessRunningElevated); |
227 #endif | 256 #endif |
228 | 257 |
229 bool use_zygote = false; | |
230 | |
231 #if defined(OS_LINUX) | |
232 // The Linux sandbox does not support granting access to a single directory, | |
233 // so we need to bypass the zygote in that case. | |
234 use_zygote = !no_sandbox_ && exposed_dir_.empty(); | |
235 #endif | |
236 | |
237 process_->Launch( | 258 process_->Launch( |
238 #if defined(OS_WIN) | 259 new UtilitySandboxedProcessLauncherDelegate(exposed_dir_, |
239 new UtilitySandboxedProcessLauncherDelegate(exposed_dir_), | 260 run_elevated_, |
240 run_elevated_, | 261 no_sandbox_, env_, |
241 #elif defined(OS_POSIX) | 262 process_->GetHost()), |
242 use_zygote, | |
243 env_, | |
244 #endif | |
245 cmd_line); | 263 cmd_line); |
246 } | 264 } |
247 | 265 |
248 return true; | 266 return true; |
249 } | 267 } |
250 | 268 |
251 bool UtilityProcessHostImpl::OnMessageReceived(const IPC::Message& message) { | 269 bool UtilityProcessHostImpl::OnMessageReceived(const IPC::Message& message) { |
252 client_task_runner_->PostTask( | 270 client_task_runner_->PostTask( |
253 FROM_HERE, | 271 FROM_HERE, |
254 base::Bind(base::IgnoreResult( | 272 base::Bind(base::IgnoreResult( |
(...skipping 10 matching lines...) Expand all Loading... |
265 } | 283 } |
266 | 284 |
267 void UtilityProcessHostImpl::OnProcessCrashed(int exit_code) { | 285 void UtilityProcessHostImpl::OnProcessCrashed(int exit_code) { |
268 client_task_runner_->PostTask( | 286 client_task_runner_->PostTask( |
269 FROM_HERE, | 287 FROM_HERE, |
270 base::Bind(&UtilityProcessHostClient::OnProcessCrashed, client_.get(), | 288 base::Bind(&UtilityProcessHostClient::OnProcessCrashed, client_.get(), |
271 exit_code)); | 289 exit_code)); |
272 } | 290 } |
273 | 291 |
274 } // namespace content | 292 } // namespace content |
OLD | NEW |