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

Side by Side Diff: components/nacl/zygote/nacl_fork_delegate_linux.cc

Issue 2950153002: Improve process launch handle sharing API. (Closed)
Patch Set: Fix Created 3 years, 5 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 "components/nacl/zygote/nacl_fork_delegate_linux.h" 5 #include "components/nacl/zygote/nacl_fork_delegate_linux.h"
6 6
7 #include <signal.h> 7 #include <signal.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <sys/resource.h> 10 #include <sys/resource.h>
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 167
168 // For communications between the NaCl loader process and 168 // For communications between the NaCl loader process and
169 // the browser process. 169 // the browser process.
170 int nacl_sandbox_descriptor = 170 int nacl_sandbox_descriptor =
171 base::GlobalDescriptors::kBaseDescriptor + kSandboxIPCChannel; 171 base::GlobalDescriptors::kBaseDescriptor + kSandboxIPCChannel;
172 // Confirm a hard-wired assumption. 172 // Confirm a hard-wired assumption.
173 DCHECK_EQ(sandboxdesc, nacl_sandbox_descriptor); 173 DCHECK_EQ(sandboxdesc, nacl_sandbox_descriptor);
174 174
175 int fds[2]; 175 int fds[2];
176 PCHECK(0 == socketpair(PF_UNIX, SOCK_SEQPACKET, 0, fds)); 176 PCHECK(0 == socketpair(PF_UNIX, SOCK_SEQPACKET, 0, fds));
177 base::FileHandleMappingVector fds_to_map;
178 fds_to_map.push_back(std::make_pair(fds[1], kNaClZygoteDescriptor));
179 fds_to_map.push_back(std::make_pair(sandboxdesc, nacl_sandbox_descriptor));
180 177
181 bool use_nacl_bootstrap = false; 178 bool use_nacl_bootstrap = false;
182 // For non-SFI mode, we do not use fixed address space. 179 // For non-SFI mode, we do not use fixed address space.
183 if (!nonsfi_mode_) { 180 if (!nonsfi_mode_) {
184 // Using nacl_helper_bootstrap is not necessary on x86-64 because 181 // Using nacl_helper_bootstrap is not necessary on x86-64 because
185 // NaCl's x86-64 sandbox is not zero-address-based. Starting 182 // NaCl's x86-64 sandbox is not zero-address-based. Starting
186 // nacl_helper through nacl_helper_bootstrap works on x86-64, but it 183 // nacl_helper through nacl_helper_bootstrap works on x86-64, but it
187 // leaves nacl_helper_bootstrap mapped at a fixed address at the 184 // leaves nacl_helper_bootstrap mapped at a fixed address at the
188 // bottom of the address space, which is undesirable because it 185 // bottom of the address space, which is undesirable because it
189 // effectively defeats ASLR. 186 // effectively defeats ASLR.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 base::CommandLine::StringVector bootstrap_prepend; 244 base::CommandLine::StringVector bootstrap_prepend;
248 bootstrap_prepend.push_back(helper_exe.value()); 245 bootstrap_prepend.push_back(helper_exe.value());
249 bootstrap_prepend.push_back(kNaClHelperReservedAtZero); 246 bootstrap_prepend.push_back(kNaClHelperReservedAtZero);
250 bootstrap_prepend.push_back(kNaClHelperRDebug); 247 bootstrap_prepend.push_back(kNaClHelperRDebug);
251 argv_to_launch.insert(argv_to_launch.begin() + 1, 248 argv_to_launch.insert(argv_to_launch.begin() + 1,
252 bootstrap_prepend.begin(), 249 bootstrap_prepend.begin(),
253 bootstrap_prepend.end()); 250 bootstrap_prepend.end());
254 } 251 }
255 252
256 base::LaunchOptions options; 253 base::LaunchOptions options;
254 options.fds_to_remap.push_back(
255 std::make_pair(fds[1], kNaClZygoteDescriptor));
256 options.fds_to_remap.push_back(
257 std::make_pair(sandboxdesc, nacl_sandbox_descriptor));
257 258
258 base::ScopedFD dummy_fd; 259 base::ScopedFD dummy_fd;
259 if (using_setuid_sandbox) { 260 if (using_setuid_sandbox) {
260 // NaCl needs to keep tight control of the cmd_line, so prepend the 261 // NaCl needs to keep tight control of the cmd_line, so prepend the
261 // setuid sandbox wrapper manually. 262 // setuid sandbox wrapper manually.
262 base::FilePath sandbox_path = setuid_sandbox_host->GetSandboxBinaryPath(); 263 base::FilePath sandbox_path = setuid_sandbox_host->GetSandboxBinaryPath();
263 argv_to_launch.insert(argv_to_launch.begin(), sandbox_path.value()); 264 argv_to_launch.insert(argv_to_launch.begin(), sandbox_path.value());
264 setuid_sandbox_host->SetupLaunchOptions(&options, &fds_to_map, &dummy_fd); 265 setuid_sandbox_host->SetupLaunchOptions(&options, &dummy_fd);
265 setuid_sandbox_host->SetupLaunchEnvironment(); 266 setuid_sandbox_host->SetupLaunchEnvironment();
266 } 267 }
267 268
268 options.fds_to_remap = &fds_to_map;
269
270 // The NaCl processes spawned may need to exceed the ambient soft limit 269 // The NaCl processes spawned may need to exceed the ambient soft limit
271 // on RLIMIT_AS to allocate the untrusted address space and its guard 270 // on RLIMIT_AS to allocate the untrusted address space and its guard
272 // regions. The nacl_helper itself cannot just raise its own limit, 271 // regions. The nacl_helper itself cannot just raise its own limit,
273 // because the existing limit may prevent the initial exec of 272 // because the existing limit may prevent the initial exec of
274 // nacl_helper_bootstrap from succeeding, with its large address space 273 // nacl_helper_bootstrap from succeeding, with its large address space
275 // reservation. 274 // reservation.
276 std::vector<int> max_these_limits; 275 std::vector<int> max_these_limits;
277 max_these_limits.push_back(RLIMIT_AS); 276 max_these_limits.push_back(RLIMIT_AS);
278 options.maximize_rlimits = &max_these_limits; 277 options.maximize_rlimits = &max_these_limits;
279 278
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 pass_through_vars.push_back(kNaClVerbosity); 457 pass_through_vars.push_back(kNaClVerbosity);
459 pass_through_vars.push_back(sandbox::kSandboxEnvironmentApiRequest); 458 pass_through_vars.push_back(sandbox::kSandboxEnvironmentApiRequest);
460 for (size_t i = 0; i < pass_through_vars.size(); ++i) { 459 for (size_t i = 0; i < pass_through_vars.size(); ++i) {
461 std::string temp; 460 std::string temp;
462 if (env->GetVar(pass_through_vars[i], &temp)) 461 if (env->GetVar(pass_through_vars[i], &temp))
463 options->environ[pass_through_vars[i]] = temp; 462 options->environ[pass_through_vars[i]] = temp;
464 } 463 }
465 } 464 }
466 465
467 } // namespace nacl 466 } // namespace nacl
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698