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 // Previously we just looked for the binary next to the Chromium binary. But | |
| 26 // this breaks people who do a build-all. | |
| 27 // NOTE packagers: change this. | |
| 28 | |
| 29 // static const char kSandboxBinary[] = "/opt/google/chrome/chrome-sandbox"; | |
| 30 static const char kSandboxBinary[] = "/false"; | |
| 31 | |
| 32 ZygoteHost::ZygoteHost() { | 25 ZygoteHost::ZygoteHost() { |
| 33 std::wstring chrome_path; | 26 std::wstring chrome_path; |
| 34 CHECK(PathService::Get(base::FILE_EXE, &chrome_path)); | 27 CHECK(PathService::Get(base::FILE_EXE, &chrome_path)); |
| 35 CommandLine cmd_line(chrome_path); | 28 CommandLine cmd_line(chrome_path); |
| 36 | 29 |
| 37 cmd_line.AppendSwitchWithValue(switches::kProcessType, | 30 cmd_line.AppendSwitchWithValue(switches::kProcessType, |
| 38 switches::kZygoteProcess); | 31 switches::kZygoteProcess); |
| 39 | 32 |
| 40 int fds[2]; | 33 int fds[2]; |
| 41 CHECK(socketpair(PF_UNIX, SOCK_SEQPACKET, 0, fds) == 0); | 34 CHECK(socketpair(PF_UNIX, SOCK_SEQPACKET, 0, fds) == 0); |
| 42 base::file_handle_mapping_vector fds_to_map; | 35 base::file_handle_mapping_vector fds_to_map; |
| 43 fds_to_map.push_back(std::make_pair(fds[1], 3)); | 36 fds_to_map.push_back(std::make_pair(fds[1], 3)); |
| 44 | 37 |
| 45 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); | 38 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
| 46 if (browser_command_line.HasSwitch(switches::kZygoteCmdPrefix)) { | 39 if (browser_command_line.HasSwitch(switches::kZygoteCmdPrefix)) { |
| 47 const std::wstring prefix = | 40 const std::wstring prefix = |
| 48 browser_command_line.GetSwitchValue(switches::kZygoteCmdPrefix); | 41 browser_command_line.GetSwitchValue(switches::kZygoteCmdPrefix); |
| 49 cmd_line.PrependWrapper(prefix); | 42 cmd_line.PrependWrapper(prefix); |
| 50 } | 43 } |
| 51 | 44 |
| 52 const char* sandbox_binary = NULL; | 45 const char* sandbox_binary = NULL; |
| 53 struct stat st; | 46 struct stat st; |
| 47 | |
| 48 #if !defined(GOOGLE_CHROME_BUILD) | |
|
Michael Moss
2009/07/15 21:19:49
Not sure why this needs to be only !GOOGLE_CHROME_
| |
| 49 // In Chromium branded builds, developers can set an environment variable to | |
| 50 // use the development sandbox. See | |
| 51 // http://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment | |
| 54 if (stat("/proc/self/exe", &st) == 0 && | 52 if (stat("/proc/self/exe", &st) == 0 && |
| 55 st.st_uid == getuid()) { | 53 st.st_uid == getuid()) { |
| 56 sandbox_binary = getenv("CHROME_DEVEL_SANDBOX"); | 54 sandbox_binary = getenv("CHROME_DEVEL_SANDBOX"); |
| 57 } | 55 } |
| 56 #endif | |
| 58 | 57 |
| 58 #if defined(LINUX_SANDBOX_PATH) | |
| 59 if (!sandbox_binary) | 59 if (!sandbox_binary) |
| 60 sandbox_binary = kSandboxBinary; | 60 sandbox_binary = LINUX_SANDBOX_PATH; |
| 61 #endif | |
| 61 | 62 |
| 62 if (stat(sandbox_binary, &st) == 0) { | 63 if (sandbox_binary && stat(sandbox_binary, &st) == 0) { |
| 63 if (access(sandbox_binary, X_OK) == 0 && | 64 if (access(sandbox_binary, X_OK) == 0 && |
| 64 (st.st_mode & S_ISUID) && | 65 (st.st_mode & S_ISUID) && |
| 65 (st.st_mode & S_IXOTH)) { | 66 (st.st_mode & S_IXOTH)) { |
| 66 cmd_line.PrependWrapper(ASCIIToWide(sandbox_binary)); | 67 cmd_line.PrependWrapper(ASCIIToWide(sandbox_binary)); |
| 67 | 68 |
| 68 // SUID binaries clear LD_LIBRARY_PATH. However, the sandbox binary needs | 69 // SUID binaries clear LD_LIBRARY_PATH. However, the sandbox binary needs |
| 69 // to run its child processes with the correct LD_LIBRARY_PATH so we save | 70 // to run its child processes with the correct LD_LIBRARY_PATH so we save |
| 70 // a copy here: | 71 // a copy here: |
| 71 const char* ld_library_path = getenv("LD_LIBRARY_PATH"); | 72 const char* ld_library_path = getenv("LD_LIBRARY_PATH"); |
| 72 if (ld_library_path) | 73 if (ld_library_path) |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 !read_pickle.ReadBool(&iter, &tmp_child_exited)) { | 163 !read_pickle.ReadBool(&iter, &tmp_child_exited)) { |
| 163 LOG(WARNING) << "Error parsing DidProcessCrash response from zygote."; | 164 LOG(WARNING) << "Error parsing DidProcessCrash response from zygote."; |
| 164 return false; | 165 return false; |
| 165 } | 166 } |
| 166 | 167 |
| 167 if (child_exited) | 168 if (child_exited) |
| 168 *child_exited = tmp_child_exited; | 169 *child_exited = tmp_child_exited; |
| 169 | 170 |
| 170 return did_crash; | 171 return did_crash; |
| 171 } | 172 } |
| OLD | NEW |