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

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

Issue 177863002: Refactor configuration of sandboxes - first steps (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to review comments from jam@ Created 6 years, 9 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
OLDNEW
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,
38 bool no_sandbox,
39 base::EnvironmentMap& env,
40 ChildProcessHost* host)
41 #if defined(OS_WIN)
42 : launch_elevated_(launch_elevated),
43 exposed_dir_(exposed_dir) {}
44 #elif defined(OS_POSIX)
45 : exposed_dir_(exposed_dir),
jam 2014/02/28 18:07:43 nit: bring out the shared part out of the ifdefs
aberent 2014/02/28 21:17:28 Done.
46 env_(env),
47 no_sandbox_(no_sandbox),
48 ipc_fd_(host->TakeClientFileDescriptor()) {}
49 #endif // OS_WIN
50
42 virtual ~UtilitySandboxedProcessLauncherDelegate() {} 51 virtual ~UtilitySandboxedProcessLauncherDelegate() {}
43 52
53 #if defined(OS_WIN)
54 virtual bool ShouldLaunchElevated() OVERRIDE {
55 return launch_elevated_;
56 }
44 virtual void PreSandbox(bool* disable_default_policy, 57 virtual void PreSandbox(bool* disable_default_policy,
45 base::FilePath* exposed_dir) OVERRIDE { 58 base::FilePath* exposed_dir) OVERRIDE {
46 *exposed_dir = exposed_dir_; 59 *exposed_dir = exposed_dir_;
47 } 60 }
61 #elif defined(OS_POSIX)
48 62
49 private: 63 virtual bool ShouldUseZygote() OVERRIDE {
50 base::FilePath exposed_dir_; 64 return !no_sandbox_ && exposed_dir_.empty();
51 }; 65 }
66 virtual base::EnvironmentMap GetEnvironment() OVERRIDE {
67 return env_;
68 }
69 virtual int GetIpcFd() OVERRIDE {
70 return ipc_fd_;
71 }
72 #endif // OS_WIN
73
74 private:
75
76 #if defined(OS_WIN)
77 bool launch_elevated_;
52 #endif 78 #endif
53 79
80 base::FilePath exposed_dir_;
81
82 #if defined(OS_POSIX)
83 base::EnvironmentMap env_;
84 bool no_sandbox_;
85 int ipc_fd_;
86 #endif // OS_WIN
87 };
54 88
55 UtilityMainThreadFactoryFunction g_utility_main_thread_factory = NULL; 89 UtilityMainThreadFactoryFunction g_utility_main_thread_factory = NULL;
56 90
57 UtilityProcessHost* UtilityProcessHost::Create( 91 UtilityProcessHost* UtilityProcessHost::Create(
58 UtilityProcessHostClient* client, 92 UtilityProcessHostClient* client,
59 base::SequencedTaskRunner* client_task_runner) { 93 base::SequencedTaskRunner* client_task_runner) {
60 return new UtilityProcessHostImpl(client, client_task_runner); 94 return new UtilityProcessHostImpl(client, client_task_runner);
61 } 95 }
62 96
63 void UtilityProcessHost::RegisterUtilityMainThreadFactory( 97 void UtilityProcessHost::RegisterUtilityMainThreadFactory(
64 UtilityMainThreadFactoryFunction create) { 98 UtilityMainThreadFactoryFunction create) {
65 g_utility_main_thread_factory = create; 99 g_utility_main_thread_factory = create;
66 } 100 }
67 101
68 UtilityProcessHostImpl::UtilityProcessHostImpl( 102 UtilityProcessHostImpl::UtilityProcessHostImpl(
69 UtilityProcessHostClient* client, 103 UtilityProcessHostClient* client,
70 base::SequencedTaskRunner* client_task_runner) 104 base::SequencedTaskRunner* client_task_runner)
71 : client_(client), 105 : client_(client),
72 client_task_runner_(client_task_runner), 106 client_task_runner_(client_task_runner),
73 is_batch_mode_(false), 107 is_batch_mode_(false),
74 is_mdns_enabled_(false), 108 is_mdns_enabled_(false),
75 no_sandbox_(false), 109 no_sandbox_(false),
76 #if defined(OS_WIN)
77 run_elevated_(false), 110 run_elevated_(false),
78 #endif
79 #if defined(OS_LINUX) 111 #if defined(OS_LINUX)
80 child_flags_(ChildProcessHost::CHILD_ALLOW_SELF), 112 child_flags_(ChildProcessHost::CHILD_ALLOW_SELF),
81 #else 113 #else
82 child_flags_(ChildProcessHost::CHILD_NORMAL), 114 child_flags_(ChildProcessHost::CHILD_NORMAL),
83 #endif 115 #endif
84 started_(false) { 116 started_(false) {
85 } 117 }
86 118
87 UtilityProcessHostImpl::~UtilityProcessHostImpl() { 119 UtilityProcessHostImpl::~UtilityProcessHostImpl() {
88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 251
220 if (is_mdns_enabled_) 252 if (is_mdns_enabled_)
221 cmd_line->AppendSwitch(switches::kUtilityProcessEnableMDns); 253 cmd_line->AppendSwitch(switches::kUtilityProcessEnableMDns);
222 254
223 #if defined(OS_WIN) 255 #if defined(OS_WIN)
224 // Let the utility process know if it is intended to be elevated. 256 // Let the utility process know if it is intended to be elevated.
225 if (run_elevated_) 257 if (run_elevated_)
226 cmd_line->AppendSwitch(switches::kUtilityProcessRunningElevated); 258 cmd_line->AppendSwitch(switches::kUtilityProcessRunningElevated);
227 #endif 259 #endif
228 260
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( 261 process_->Launch(
238 #if defined(OS_WIN) 262 new UtilitySandboxedProcessLauncherDelegate(exposed_dir_,
239 new UtilitySandboxedProcessLauncherDelegate(exposed_dir_), 263 run_elevated_,
240 run_elevated_, 264 no_sandbox_, env_,
241 #elif defined(OS_POSIX) 265 process_->GetHost()),
242 use_zygote,
243 env_,
244 #endif
245 cmd_line); 266 cmd_line);
246 } 267 }
247 268
248 return true; 269 return true;
249 } 270 }
250 271
251 bool UtilityProcessHostImpl::OnMessageReceived(const IPC::Message& message) { 272 bool UtilityProcessHostImpl::OnMessageReceived(const IPC::Message& message) {
252 client_task_runner_->PostTask( 273 client_task_runner_->PostTask(
253 FROM_HERE, 274 FROM_HERE,
254 base::Bind(base::IgnoreResult( 275 base::Bind(base::IgnoreResult(
(...skipping 10 matching lines...) Expand all
265 } 286 }
266 287
267 void UtilityProcessHostImpl::OnProcessCrashed(int exit_code) { 288 void UtilityProcessHostImpl::OnProcessCrashed(int exit_code) {
268 client_task_runner_->PostTask( 289 client_task_runner_->PostTask(
269 FROM_HERE, 290 FROM_HERE,
270 base::Bind(&UtilityProcessHostClient::OnProcessCrashed, client_.get(), 291 base::Bind(&UtilityProcessHostClient::OnProcessCrashed, client_.get(),
271 exit_code)); 292 exit_code));
272 } 293 }
273 294
274 } // namespace content 295 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698