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