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

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

Issue 1640123005: Revert of Have each SandboxedProcessLauncherDelegate maintain a zygote. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 <utility> 7 #include <utility>
8 8
9 #include "base/base_switches.h" 9 #include "base/base_switches.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 19 matching lines...) Expand all
30 #include "content/public/browser/browser_thread.h" 30 #include "content/public/browser/browser_thread.h"
31 #include "content/public/browser/content_browser_client.h" 31 #include "content/public/browser/content_browser_client.h"
32 #include "content/public/browser/utility_process_host_client.h" 32 #include "content/public/browser/utility_process_host_client.h"
33 #include "content/public/common/content_switches.h" 33 #include "content/public/common/content_switches.h"
34 #include "content/public/common/process_type.h" 34 #include "content/public/common/process_type.h"
35 #include "content/public/common/sandbox_type.h" 35 #include "content/public/common/sandbox_type.h"
36 #include "content/public/common/sandboxed_process_launcher_delegate.h" 36 #include "content/public/common/sandboxed_process_launcher_delegate.h"
37 #include "ipc/ipc_switches.h" 37 #include "ipc/ipc_switches.h"
38 #include "ui/base/ui_base_switches.h" 38 #include "ui/base/ui_base_switches.h"
39 39
40 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
41 #include "content/public/browser/zygote_handle_linux.h"
42 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
43
44 #if defined(OS_WIN) 40 #if defined(OS_WIN)
45 #include "sandbox/win/src/sandbox_policy.h" 41 #include "sandbox/win/src/sandbox_policy.h"
46 #include "sandbox/win/src/sandbox_types.h" 42 #include "sandbox/win/src/sandbox_types.h"
47 #endif 43 #endif
48 44
49 namespace content { 45 namespace content {
50 46
51 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
52 namespace {
53 ZygoteHandle g_utility_zygote;
54 } // namespace
55 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
56
57 // NOTE: changes to this class need to be reviewed by the security team. 47 // NOTE: changes to this class need to be reviewed by the security team.
58 class UtilitySandboxedProcessLauncherDelegate 48 class UtilitySandboxedProcessLauncherDelegate
59 : public SandboxedProcessLauncherDelegate { 49 : public SandboxedProcessLauncherDelegate {
60 public: 50 public:
61 UtilitySandboxedProcessLauncherDelegate(const base::FilePath& exposed_dir, 51 UtilitySandboxedProcessLauncherDelegate(const base::FilePath& exposed_dir,
62 bool launch_elevated, 52 bool launch_elevated,
63 bool no_sandbox, 53 bool no_sandbox,
64 const base::EnvironmentMap& env, 54 const base::EnvironmentMap& env,
65 ChildProcessHost* host) 55 ChildProcessHost* host)
66 : exposed_dir_(exposed_dir), 56 : exposed_dir_(exposed_dir),
67 #if defined(OS_WIN) 57 #if defined(OS_WIN)
68 launch_elevated_(launch_elevated) 58 launch_elevated_(launch_elevated)
69 #elif defined(OS_POSIX) 59 #elif defined(OS_POSIX)
70 env_(env), 60 env_(env),
71 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
72 no_sandbox_(no_sandbox), 61 no_sandbox_(no_sandbox),
73 #endif // !defined(OS_MACOSX) && !defined(OS_ANDROID)
74 ipc_fd_(host->TakeClientFileDescriptor()) 62 ipc_fd_(host->TakeClientFileDescriptor())
75 #endif // OS_WIN 63 #endif // OS_WIN
76 {} 64 {}
77 65
78 ~UtilitySandboxedProcessLauncherDelegate() override {} 66 ~UtilitySandboxedProcessLauncherDelegate() override {}
79 67
80 #if defined(OS_WIN) 68 #if defined(OS_WIN)
81 bool ShouldLaunchElevated() override { return launch_elevated_; } 69 bool ShouldLaunchElevated() override { return launch_elevated_; }
82 70
83 bool PreSpawnTarget(sandbox::TargetPolicy* policy) override { 71 bool PreSpawnTarget(sandbox::TargetPolicy* policy) override {
84 if (exposed_dir_.empty()) 72 if (exposed_dir_.empty())
85 return true; 73 return true;
86 74
87 sandbox::ResultCode result; 75 sandbox::ResultCode result;
88 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES, 76 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES,
89 sandbox::TargetPolicy::FILES_ALLOW_ANY, 77 sandbox::TargetPolicy::FILES_ALLOW_ANY,
90 exposed_dir_.value().c_str()); 78 exposed_dir_.value().c_str());
91 if (result != sandbox::SBOX_ALL_OK) 79 if (result != sandbox::SBOX_ALL_OK)
92 return false; 80 return false;
93 81
94 base::FilePath exposed_files = exposed_dir_.AppendASCII("*"); 82 base::FilePath exposed_files = exposed_dir_.AppendASCII("*");
95 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES, 83 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES,
96 sandbox::TargetPolicy::FILES_ALLOW_ANY, 84 sandbox::TargetPolicy::FILES_ALLOW_ANY,
97 exposed_files.value().c_str()); 85 exposed_files.value().c_str());
98 return result == sandbox::SBOX_ALL_OK; 86 return result == sandbox::SBOX_ALL_OK;
99 } 87 }
100 88
101 #elif defined(OS_POSIX) 89 #elif defined(OS_POSIX)
102 90
103 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) 91 bool ShouldUseZygote() override {
104 ZygoteHandle* GetZygote() override { 92 return !no_sandbox_ && exposed_dir_.empty();
105 if (no_sandbox_ || !exposed_dir_.empty())
106 return nullptr;
107 return &g_utility_zygote;
108 } 93 }
109 #endif // !defined(OS_MACOSX) && !defined(OS_ANDROID)
110 base::EnvironmentMap GetEnvironment() override { return env_; } 94 base::EnvironmentMap GetEnvironment() override { return env_; }
111 base::ScopedFD TakeIpcFd() override { return std::move(ipc_fd_); } 95 base::ScopedFD TakeIpcFd() override { return std::move(ipc_fd_); }
112 #endif // OS_WIN 96 #endif // OS_WIN
113 97
114 SandboxType GetSandboxType() override { 98 SandboxType GetSandboxType() override {
115 return SANDBOX_TYPE_UTILITY; 99 return SANDBOX_TYPE_UTILITY;
116 } 100 }
117 101
118 private: 102 private:
119 base::FilePath exposed_dir_; 103 base::FilePath exposed_dir_;
120 104
121 #if defined(OS_WIN) 105 #if defined(OS_WIN)
122 bool launch_elevated_; 106 bool launch_elevated_;
123 #elif defined(OS_POSIX) 107 #elif defined(OS_POSIX)
124 base::EnvironmentMap env_; 108 base::EnvironmentMap env_;
125 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
126 bool no_sandbox_; 109 bool no_sandbox_;
127 #endif // !defined(OS_MACOSX) && !defined(OS_ANDROID)
128 base::ScopedFD ipc_fd_; 110 base::ScopedFD ipc_fd_;
129 #endif // OS_WIN 111 #endif // OS_WIN
130 }; 112 };
131 113
132 UtilityMainThreadFactoryFunction g_utility_main_thread_factory = NULL; 114 UtilityMainThreadFactoryFunction g_utility_main_thread_factory = NULL;
133 115
134 UtilityProcessHost* UtilityProcessHost::Create( 116 UtilityProcessHost* UtilityProcessHost::Create(
135 const scoped_refptr<UtilityProcessHostClient>& client, 117 const scoped_refptr<UtilityProcessHostClient>& client,
136 const scoped_refptr<base::SequencedTaskRunner>& client_task_runner) { 118 const scoped_refptr<base::SequencedTaskRunner>& client_task_runner) {
137 return new UtilityProcessHostImpl(client, client_task_runner); 119 return new UtilityProcessHostImpl(client, client_task_runner);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 ServiceRegistry* UtilityProcessHostImpl::GetServiceRegistry() { 213 ServiceRegistry* UtilityProcessHostImpl::GetServiceRegistry() {
232 if (mojo_application_host_) 214 if (mojo_application_host_)
233 return mojo_application_host_->service_registry(); 215 return mojo_application_host_->service_registry();
234 return nullptr; 216 return nullptr;
235 } 217 }
236 218
237 void UtilityProcessHostImpl::SetName(const base::string16& name) { 219 void UtilityProcessHostImpl::SetName(const base::string16& name) {
238 name_ = name; 220 name_ = name;
239 } 221 }
240 222
241 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
242 // static
243 void UtilityProcessHostImpl::EarlyZygoteLaunch() {
244 DCHECK(!g_utility_zygote);
245 g_utility_zygote = CreateZygote();
246 }
247 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
248
249 bool UtilityProcessHostImpl::StartProcess() { 223 bool UtilityProcessHostImpl::StartProcess() {
250 if (started_) 224 if (started_)
251 return true; 225 return true;
252 started_ = true; 226 started_ = true;
253 227
254 if (is_batch_mode_) 228 if (is_batch_mode_)
255 return true; 229 return true;
256 230
257 // Name must be set or metrics_service will crash in any test which 231 // Name must be set or metrics_service will crash in any test which
258 // launches a UtilityProcessHost. 232 // launches a UtilityProcessHost.
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 if (RenderProcessHost::run_renderer_in_process()) 371 if (RenderProcessHost::run_renderer_in_process())
398 handle = base::GetCurrentProcessHandle(); 372 handle = base::GetCurrentProcessHandle();
399 else 373 else
400 handle = process_->GetData().handle; 374 handle = process_->GetData().handle;
401 375
402 mojo_application_host_->Activate(this, handle); 376 mojo_application_host_->Activate(this, handle);
403 } 377 }
404 } 378 }
405 379
406 } // namespace content 380 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/utility_process_host_impl.h ('k') | content/browser/zygote_host/zygote_communication_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698