| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/zygote_host_linux.h" | 5 #include "chrome/browser/zygote_host_linux.h" |
| 6 | 6 |
| 7 #include <sys/socket.h> | 7 #include <sys/socket.h> |
| 8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
| 9 #include <sys/types.h> | 9 #include <sys/types.h> |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| 11 | 11 |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/eintr_wrapper.h" | 13 #include "base/eintr_wrapper.h" |
| 14 #include "base/linux_util.h" | 14 #include "base/linux_util.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 17 #include "base/pickle.h" | 17 #include "base/pickle.h" |
| 18 #include "base/process_util.h" | 18 #include "base/process_util.h" |
| 19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
| 20 #include "base/unix_domain_socket_posix.h" | 20 #include "base/unix_domain_socket_posix.h" |
| 21 | 21 |
| 22 #include "chrome/browser/renderer_host/render_sandbox_host_linux.h" | 22 #include "chrome/browser/renderer_host/render_sandbox_host_linux.h" |
| 23 #include "chrome/common/chrome_constants.h" | 23 #include "chrome/common/chrome_constants.h" |
| 24 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
| 25 #include "chrome/common/process_watcher.h" | 25 #include "chrome/common/process_watcher.h" |
| 26 | 26 |
| 27 #include "sandbox/linux/suid/suid_unsafe_environment_variables.h" | |
| 28 | |
| 29 static void SaveSUIDUnsafeEnvironmentVariables() { | |
| 30 // The ELF loader will clear many environment variables so we save them to | |
| 31 // different names here so that the SUID sandbox can resolve them for the | |
| 32 // renderer. | |
| 33 | |
| 34 for (unsigned i = 0; kSUIDUnsafeEnvironmentVariables[i]; ++i) { | |
| 35 const char* const envvar = kSUIDUnsafeEnvironmentVariables[i]; | |
| 36 char* const saved_envvar = SandboxSavedEnvironmentVariable(envvar); | |
| 37 if (!saved_envvar) | |
| 38 continue; | |
| 39 | |
| 40 const char* const value = getenv(envvar); | |
| 41 if (value) | |
| 42 setenv(saved_envvar, value, 1 /* overwrite */); | |
| 43 else | |
| 44 unsetenv(saved_envvar); | |
| 45 | |
| 46 free(saved_envvar); | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 ZygoteHost::ZygoteHost() | 27 ZygoteHost::ZygoteHost() |
| 51 : pid_(-1), | 28 : pid_(-1), |
| 52 init_(false), | 29 init_(false), |
| 53 using_suid_sandbox_(false) { | 30 using_suid_sandbox_(false) { |
| 54 } | 31 } |
| 55 | 32 |
| 56 ZygoteHost::~ZygoteHost() { | 33 ZygoteHost::~ZygoteHost() { |
| 57 if (init_) | 34 if (init_) |
| 58 close(control_fd_); | 35 close(control_fd_); |
| 59 } | 36 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 90 cmd_line.AppendSwitchWithValue(switches::kLoggingLevel, | 67 cmd_line.AppendSwitchWithValue(switches::kLoggingLevel, |
| 91 browser_command_line.GetSwitchValueASCII( | 68 browser_command_line.GetSwitchValueASCII( |
| 92 switches::kLoggingLevel)); | 69 switches::kLoggingLevel)); |
| 93 } | 70 } |
| 94 if (browser_command_line.HasSwitch(switches::kEnableLogging)) { | 71 if (browser_command_line.HasSwitch(switches::kEnableLogging)) { |
| 95 // Append with value to support --enable-logging=stderr. | 72 // Append with value to support --enable-logging=stderr. |
| 96 cmd_line.AppendSwitchWithValue(switches::kEnableLogging, | 73 cmd_line.AppendSwitchWithValue(switches::kEnableLogging, |
| 97 browser_command_line.GetSwitchValueASCII( | 74 browser_command_line.GetSwitchValueASCII( |
| 98 switches::kEnableLogging)); | 75 switches::kEnableLogging)); |
| 99 } | 76 } |
| 100 if (browser_command_line.HasSwitch(switches::kEnableSeccompSandbox)) { | 77 if (browser_command_line.HasSwitch(switches::kDisableSeccompSandbox)) { |
| 101 cmd_line.AppendSwitch(switches::kEnableSeccompSandbox); | 78 cmd_line.AppendSwitch(switches::kDisableSeccompSandbox); |
| 102 } | 79 } |
| 103 | 80 |
| 104 sandbox_binary_ = sandbox_cmd.c_str(); | 81 sandbox_binary_ = sandbox_cmd.c_str(); |
| 105 struct stat st; | |
| 106 | |
| 107 if (!sandbox_cmd.empty() && stat(sandbox_binary_.c_str(), &st) == 0) { | |
| 108 if (access(sandbox_binary_.c_str(), X_OK) == 0 && | |
| 109 (st.st_uid == 0) && | |
| 110 (st.st_mode & S_ISUID) && | |
| 111 (st.st_mode & S_IXOTH)) { | |
| 112 using_suid_sandbox_ = true; | |
| 113 cmd_line.PrependWrapper(ASCIIToWide(sandbox_binary_.c_str())); | |
| 114 | |
| 115 SaveSUIDUnsafeEnvironmentVariables(); | |
| 116 } else { | |
| 117 LOG(FATAL) << "The SUID sandbox helper binary was found, but is not " | |
| 118 "configured correctly. Rather than run without sandboxing " | |
| 119 "I'm aborting now. You need to make sure that " | |
| 120 << sandbox_binary_ << " is mode 4755 and owned by root."; | |
| 121 } | |
| 122 } | |
| 123 | 82 |
| 124 // Start up the sandbox host process and get the file descriptor for the | 83 // Start up the sandbox host process and get the file descriptor for the |
| 125 // renderers to talk to it. | 84 // renderers to talk to it. |
| 126 const int sfd = Singleton<RenderSandboxHostLinux>()->GetRendererSocket(); | 85 const int sfd = Singleton<RenderSandboxHostLinux>()->GetRendererSocket(); |
| 127 fds_to_map.push_back(std::make_pair(sfd, 5)); | 86 fds_to_map.push_back(std::make_pair(sfd, 5)); |
| 128 | 87 |
| 129 int dummy_fd = -1; | 88 int dummy_fd = -1; |
| 130 if (using_suid_sandbox_) { | 89 if (using_suid_sandbox_) { |
| 131 dummy_fd = socket(PF_UNIX, SOCK_DGRAM, 0); | 90 dummy_fd = socket(PF_UNIX, SOCK_DGRAM, 0); |
| 132 CHECK(dummy_fd >= 0); | 91 CHECK(dummy_fd >= 0); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 !read_pickle.ReadBool(&iter, &tmp_child_exited)) { | 227 !read_pickle.ReadBool(&iter, &tmp_child_exited)) { |
| 269 LOG(WARNING) << "Error parsing DidProcessCrash response from zygote."; | 228 LOG(WARNING) << "Error parsing DidProcessCrash response from zygote."; |
| 270 return false; | 229 return false; |
| 271 } | 230 } |
| 272 | 231 |
| 273 if (child_exited) | 232 if (child_exited) |
| 274 *child_exited = tmp_child_exited; | 233 *child_exited = tmp_child_exited; |
| 275 | 234 |
| 276 return did_crash; | 235 return did_crash; |
| 277 } | 236 } |
| OLD | NEW |