Chromium Code Reviews| 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 <unistd.h> | 7 #include <unistd.h> |
| 8 #include <sys/types.h> | 8 #include <sys/types.h> |
| 9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
| 10 #include <sys/stat.h> | 10 #include <sys/stat.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/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 16 #include "base/pickle.h" | 16 #include "base/pickle.h" |
| 17 #include "base/process_util.h" | 17 #include "base/process_util.h" |
| 18 #include "base/string_util.h" | 18 #include "base/string_util.h" |
| 19 #include "base/unix_domain_socket_posix.h" | 19 #include "base/unix_domain_socket_posix.h" |
| 20 | 20 |
| 21 #include "chrome/browser/renderer_host/render_sandbox_host_linux.h" | 21 #include "chrome/browser/renderer_host/render_sandbox_host_linux.h" |
| 22 #include "chrome/common/chrome_constants.h" | 22 #include "chrome/common/chrome_constants.h" |
| 23 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 24 | 24 |
| 25 #include "sandbox/linux/suid/suid_unsafe_environment_variables.h" | |
| 26 | |
| 27 static void SaveSUIDUnsafeEnvironmentVariables() { | |
| 28 // The ELF loader will clear many environment variables so we save them to | |
| 29 // different names here so that the SUID sandbox can resolve them for the | |
| 30 // renderer. | |
| 31 | |
| 32 for (unsigned i = 0; kSUIDUnsafeEnvironmentVariables[i]; ++i) { | |
| 33 const char* const envvar = kSUIDUnsafeEnvironmentVariables[i]; | |
| 34 char* const saved_envvar = SandboxSavedEnvironmentVariable(envvar); | |
| 35 if (!saved_envvar) | |
| 36 continue; | |
| 37 | |
| 38 const char* const value = getenv(envvar); | |
| 39 if (value) | |
| 40 setenv(saved_envvar, value, 1 /* overwrite */); | |
| 41 else | |
| 42 unsetenv(saved_envvar); | |
|
Evan Martin
2009/07/17 21:10:57
I wonder if we should unsetenv() all existing SAND
agl
2009/07/17 21:35:09
We already control all the SANDBOX_ values: either
| |
| 43 | |
| 44 free(saved_envvar); | |
| 45 } | |
| 46 } | |
| 47 | |
| 25 ZygoteHost::ZygoteHost() { | 48 ZygoteHost::ZygoteHost() { |
| 26 std::wstring chrome_path; | 49 std::wstring chrome_path; |
| 27 CHECK(PathService::Get(base::FILE_EXE, &chrome_path)); | 50 CHECK(PathService::Get(base::FILE_EXE, &chrome_path)); |
| 28 CommandLine cmd_line(chrome_path); | 51 CommandLine cmd_line(chrome_path); |
| 29 | 52 |
| 30 cmd_line.AppendSwitchWithValue(switches::kProcessType, | 53 cmd_line.AppendSwitchWithValue(switches::kProcessType, |
| 31 switches::kZygoteProcess); | 54 switches::kZygoteProcess); |
| 32 | 55 |
| 33 int fds[2]; | 56 int fds[2]; |
| 34 CHECK(socketpair(PF_UNIX, SOCK_SEQPACKET, 0, fds) == 0); | 57 CHECK(socketpair(PF_UNIX, SOCK_SEQPACKET, 0, fds) == 0); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 57 if (!sandbox_binary) | 80 if (!sandbox_binary) |
| 58 sandbox_binary = LINUX_SANDBOX_PATH; | 81 sandbox_binary = LINUX_SANDBOX_PATH; |
| 59 #endif | 82 #endif |
| 60 | 83 |
| 61 if (sandbox_binary && stat(sandbox_binary, &st) == 0) { | 84 if (sandbox_binary && stat(sandbox_binary, &st) == 0) { |
| 62 if (access(sandbox_binary, X_OK) == 0 && | 85 if (access(sandbox_binary, X_OK) == 0 && |
| 63 (st.st_mode & S_ISUID) && | 86 (st.st_mode & S_ISUID) && |
| 64 (st.st_mode & S_IXOTH)) { | 87 (st.st_mode & S_IXOTH)) { |
| 65 cmd_line.PrependWrapper(ASCIIToWide(sandbox_binary)); | 88 cmd_line.PrependWrapper(ASCIIToWide(sandbox_binary)); |
| 66 | 89 |
| 67 // SUID binaries clear LD_LIBRARY_PATH. However, the sandbox binary needs | 90 SaveSUIDUnsafeEnvironmentVariables(); |
| 68 // to run its child processes with the correct LD_LIBRARY_PATH so we save | |
| 69 // a copy here: | |
| 70 const char* ld_library_path = getenv("LD_LIBRARY_PATH"); | |
| 71 if (ld_library_path) | |
| 72 setenv("SANDBOX_LD_LIBRARY_PATH", ld_library_path, 1 /* overwrite */); | |
| 73 } else { | 91 } else { |
| 74 LOG(FATAL) << "The SUID sandbox helper binary was found, but is not " | 92 LOG(FATAL) << "The SUID sandbox helper binary was found, but is not " |
| 75 "configured correctly. Rather than run without sandboxing " | 93 "configured correctly. Rather than run without sandboxing " |
| 76 "I'm aborting now. You need to make sure that " | 94 "I'm aborting now. You need to make sure that " |
| 77 << sandbox_binary << " is mode 4755."; | 95 << sandbox_binary << " is mode 4755."; |
| 78 } | 96 } |
| 79 } | 97 } |
| 80 | 98 |
| 81 // Start up the sandbox host process and get the file descriptor for the | 99 // Start up the sandbox host process and get the file descriptor for the |
| 82 // renderers to talk to it. | 100 // renderers to talk to it. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 !read_pickle.ReadBool(&iter, &tmp_child_exited)) { | 179 !read_pickle.ReadBool(&iter, &tmp_child_exited)) { |
| 162 LOG(WARNING) << "Error parsing DidProcessCrash response from zygote."; | 180 LOG(WARNING) << "Error parsing DidProcessCrash response from zygote."; |
| 163 return false; | 181 return false; |
| 164 } | 182 } |
| 165 | 183 |
| 166 if (child_exited) | 184 if (child_exited) |
| 167 *child_exited = tmp_child_exited; | 185 *child_exited = tmp_child_exited; |
| 168 | 186 |
| 169 return did_crash; | 187 return did_crash; |
| 170 } | 188 } |
| OLD | NEW |