Chromium Code Reviews| 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 "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 <stdlib.h> | 8 #include <stdlib.h> |
| 9 #include <sys/resource.h> | 9 #include <sys/resource.h> |
| 10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
| 11 | 11 |
| 12 #include <set> | 12 #include <set> |
| 13 | 13 |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "base/cpu.h" | 16 #include "base/cpu.h" |
| 17 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
| 18 #include "base/files/scoped_file.h" | 18 #include "base/files/scoped_file.h" |
| 19 #include "base/logging.h" | 19 #include "base/logging.h" |
| 20 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
| 21 #include "base/memory/scoped_vector.h" | 21 #include "base/memory/scoped_vector.h" |
| 22 #include "base/path_service.h" | 22 #include "base/path_service.h" |
| 23 #include "base/pickle.h" | 23 #include "base/pickle.h" |
| 24 #include "base/posix/eintr_wrapper.h" | 24 #include "base/posix/eintr_wrapper.h" |
| 25 #include "base/posix/global_descriptors.h" | 25 #include "base/posix/global_descriptors.h" |
| 26 #include "base/posix/unix_domain_socket_linux.h" | 26 #include "base/posix/unix_domain_socket_linux.h" |
| 27 #include "base/process/kill.h" | 27 #include "base/process/kill.h" |
| 28 #include "base/process/launch.h" | 28 #include "base/process/launch.h" |
| 29 #include "base/strings/string_split.h" | |
| 29 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 30 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| 30 #include "build/build_config.h" | 31 #include "build/build_config.h" |
| 31 #include "components/nacl/common/nacl_nonsfi_util.h" | 32 #include "components/nacl/common/nacl_nonsfi_util.h" |
| 32 #include "components/nacl/common/nacl_paths.h" | 33 #include "components/nacl/common/nacl_paths.h" |
| 33 #include "components/nacl/common/nacl_switches.h" | 34 #include "components/nacl/common/nacl_switches.h" |
| 34 #include "components/nacl/loader/nacl_helper_linux.h" | 35 #include "components/nacl/loader/nacl_helper_linux.h" |
| 35 #include "content/public/common/content_descriptors.h" | 36 #include "content/public/common/content_descriptors.h" |
| 36 #include "content/public/common/content_switches.h" | 37 #include "content/public/common/content_switches.h" |
| 37 #include "sandbox/linux/suid/client/setuid_sandbox_client.h" | 38 #include "sandbox/linux/suid/client/setuid_sandbox_client.h" |
| 38 | 39 |
| 39 namespace { | 40 namespace { |
| 40 | 41 |
| 41 // Note these need to match up with their counterparts in nacl_helper_linux.c | 42 // Note these need to match up with their counterparts in nacl_helper_linux.c |
| 42 // and nacl_helper_bootstrap_linux.c. | 43 // and nacl_helper_bootstrap_linux.c. |
| 43 const char kNaClHelperReservedAtZero[] = | 44 const char kNaClHelperReservedAtZero[] = |
| 44 "--reserved_at_zero=0xXXXXXXXXXXXXXXXX"; | 45 "--reserved_at_zero=0xXXXXXXXXXXXXXXXX"; |
| 45 const char kNaClHelperRDebug[] = "--r_debug=0xXXXXXXXXXXXXXXXX"; | 46 const char kNaClHelperRDebug[] = "--r_debug=0xXXXXXXXXXXXXXXXX"; |
| 46 | 47 |
| 48 const char kNaClDangerousNaClHelperEnvPassthrough[] = | |
|
Mark Seaborn
2014/06/02 23:10:29
Could you add a comment saying what this is for?
elijahtaylor1
2014/06/03 20:47:54
Done.
| |
| 49 "NACL_DANGEROUS_NACL_HELPER_ENV_PASSTHROUGH"; | |
|
Mark Seaborn
2014/06/02 23:10:29
Maybe just "NACL_ENV_PASSTHROUGH", otherwise it's
elijahtaylor1
2014/06/03 20:47:54
I added "DANGEROUS" because I was anticipating a r
| |
| 50 | |
| 47 #if defined(ARCH_CPU_X86) | 51 #if defined(ARCH_CPU_X86) |
| 48 bool NonZeroSegmentBaseIsSlow() { | 52 bool NonZeroSegmentBaseIsSlow() { |
| 49 base::CPU cpuid; | 53 base::CPU cpuid; |
| 50 // Using a non-zero segment base is known to be very slow on Intel | 54 // Using a non-zero segment base is known to be very slow on Intel |
| 51 // Atom CPUs. See "Segmentation-based Memory Protection Mechanism | 55 // Atom CPUs. See "Segmentation-based Memory Protection Mechanism |
| 52 // on Intel Atom Microarchitecture: Coding Optimizations" (Leonardo | 56 // on Intel Atom Microarchitecture: Coding Optimizations" (Leonardo |
| 53 // Potenza, Intel). | 57 // Potenza, Intel). |
| 54 // | 58 // |
| 55 // The following list of CPU model numbers is taken from: | 59 // The following list of CPU model numbers is taken from: |
| 56 // "Intel 64 and IA-32 Architectures Software Developer's Manual" | 60 // "Intel 64 and IA-32 Architectures Software Developer's Manual" |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 // The NaCl processes spawned may need to exceed the ambient soft limit | 240 // The NaCl processes spawned may need to exceed the ambient soft limit |
| 237 // on RLIMIT_AS to allocate the untrusted address space and its guard | 241 // on RLIMIT_AS to allocate the untrusted address space and its guard |
| 238 // regions. The nacl_helper itself cannot just raise its own limit, | 242 // regions. The nacl_helper itself cannot just raise its own limit, |
| 239 // because the existing limit may prevent the initial exec of | 243 // because the existing limit may prevent the initial exec of |
| 240 // nacl_helper_bootstrap from succeeding, with its large address space | 244 // nacl_helper_bootstrap from succeeding, with its large address space |
| 241 // reservation. | 245 // reservation. |
| 242 std::vector<int> max_these_limits; | 246 std::vector<int> max_these_limits; |
| 243 max_these_limits.push_back(RLIMIT_AS); | 247 max_these_limits.push_back(RLIMIT_AS); |
| 244 options.maximize_rlimits = &max_these_limits; | 248 options.maximize_rlimits = &max_these_limits; |
| 245 | 249 |
| 250 options.clear_environ = true; | |
|
Mark Seaborn
2014/06/02 23:10:29
Maybe add a comment like: To avoid information lea
elijahtaylor1
2014/06/03 20:47:54
Done, but modified this comment slightly. It's no
| |
| 251 AddPassthroughEnvToOptions(options); | |
| 252 | |
| 246 if (!base::LaunchProcess(argv_to_launch, options, NULL)) | 253 if (!base::LaunchProcess(argv_to_launch, options, NULL)) |
| 247 status_ = kNaClHelperLaunchFailed; | 254 status_ = kNaClHelperLaunchFailed; |
| 248 // parent and error cases are handled below | 255 // parent and error cases are handled below |
| 249 | 256 |
| 250 if (enable_layer1_sandbox) { | 257 if (enable_layer1_sandbox) { |
| 251 // Sanity check that dummy_fd was kept alive for LaunchProcess. | 258 // Sanity check that dummy_fd was kept alive for LaunchProcess. |
| 252 DCHECK(dummy_fd.is_valid()); | 259 DCHECK(dummy_fd.is_valid()); |
| 253 } | 260 } |
| 254 } | 261 } |
| 255 if (IGNORE_EINTR(close(fds[1])) != 0) | 262 if (IGNORE_EINTR(close(fds[1])) != 0) |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 if (!iter.ReadInt(&remote_exit_code)) { | 398 if (!iter.ReadInt(&remote_exit_code)) { |
| 392 LOG(ERROR) << "GetTerminationStatus: pickle failed"; | 399 LOG(ERROR) << "GetTerminationStatus: pickle failed"; |
| 393 return false; | 400 return false; |
| 394 } | 401 } |
| 395 | 402 |
| 396 *status = static_cast<base::TerminationStatus>(termination_status); | 403 *status = static_cast<base::TerminationStatus>(termination_status); |
| 397 *exit_code = remote_exit_code; | 404 *exit_code = remote_exit_code; |
| 398 return true; | 405 return true; |
| 399 } | 406 } |
| 400 | 407 |
| 408 // static | |
| 409 void NaClForkDelegate::AddPassthroughEnvToOptions( | |
| 410 base::LaunchOptions& options) { | |
| 411 scoped_ptr<base::Environment> env(base::Environment::Create()); | |
| 412 std::string pass_through_string; | |
| 413 if (env->GetVar(kNaClDangerousNaClHelperEnvPassthrough, | |
| 414 &pass_through_string)) { | |
| 415 std::vector<std::string> pass_through_vars; | |
| 416 base::SplitStringAlongWhitespace(pass_through_string, &pass_through_vars); | |
|
Mark Seaborn
2014/06/02 23:10:29
Nit: Could you split on commas instead? Spaces ar
elijahtaylor1
2014/06/03 20:47:54
Done.
| |
| 417 std::string temp; | |
|
Mark Seaborn
2014/06/02 23:10:29
Nit: could go inside the following loop
elijahtaylor1
2014/06/03 20:47:54
Done.
| |
| 418 for (size_t i = 0; i < pass_through_vars.size(); ++i) { | |
|
jln (very slow on Chromium)
2014/06/02 21:31:47
Why not use a vector::const_iterator instead?
elijahtaylor1
2014/06/03 20:47:54
verbosity/clarity. I'll leave as is unless you fe
| |
| 419 if (env->GetVar(pass_through_vars[i].c_str(), &temp)) | |
| 420 options.environ[pass_through_vars[i]] = temp; | |
| 421 } | |
| 422 } | |
| 423 } | |
| 424 | |
| 401 } // namespace nacl | 425 } // namespace nacl |
| OLD | NEW |