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 "content/browser/browser_main_loop.h" | 5 #include "content/browser/browser_main_loop.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/file_util.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
12 #include "base/metrics/field_trial.h" | 13 #include "base/metrics/field_trial.h" |
13 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/path_service.h" |
14 #include "base/pending_task.h" | 16 #include "base/pending_task.h" |
15 #include "base/power_monitor/power_monitor.h" | 17 #include "base/power_monitor/power_monitor.h" |
16 #include "base/power_monitor/power_monitor_device_source.h" | 18 #include "base/power_monitor/power_monitor_device_source.h" |
17 #include "base/process/process_metrics.h" | 19 #include "base/process/process_metrics.h" |
18 #include "base/run_loop.h" | 20 #include "base/run_loop.h" |
19 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
20 #include "base/system_monitor/system_monitor.h" | 22 #include "base/system_monitor/system_monitor.h" |
21 #include "base/threading/thread_restrictions.h" | 23 #include "base/threading/thread_restrictions.h" |
22 #include "base/timer/hi_res_timer_manager.h" | 24 #include "base/timer/hi_res_timer_manager.h" |
23 #include "content/browser/browser_thread_impl.h" | 25 #include "content/browser/browser_thread_impl.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 #endif | 115 #endif |
114 | 116 |
115 namespace content { | 117 namespace content { |
116 namespace { | 118 namespace { |
117 | 119 |
118 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 120 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
119 void SetupSandbox(const CommandLine& parsed_command_line) { | 121 void SetupSandbox(const CommandLine& parsed_command_line) { |
120 TRACE_EVENT0("startup", "SetupSandbox"); | 122 TRACE_EVENT0("startup", "SetupSandbox"); |
121 // TODO(evanm): move this into SandboxWrapper; I'm just trying to move this | 123 // TODO(evanm): move this into SandboxWrapper; I'm just trying to move this |
122 // code en masse out of chrome_main for now. | 124 // code en masse out of chrome_main for now. |
123 const char* sandbox_binary = NULL; | 125 base::FilePath sandbox_binary; |
| 126 bool env_chrome_devel_sandbox_set = false; |
124 struct stat st; | 127 struct stat st; |
125 | 128 |
126 // In Chromium branded builds, developers can set an environment variable to | |
127 // use the development sandbox. See | |
128 // http://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment | |
129 if (stat(base::kProcSelfExe, &st) == 0 && st.st_uid == getuid()) | |
130 sandbox_binary = getenv("CHROME_DEVEL_SANDBOX"); | |
131 | |
132 #if defined(LINUX_SANDBOX_PATH) | |
133 if (!sandbox_binary) | |
134 sandbox_binary = LINUX_SANDBOX_PATH; | |
135 #endif | |
136 | |
137 const bool want_setuid_sandbox = | 129 const bool want_setuid_sandbox = |
138 !parsed_command_line.HasSwitch(switches::kNoSandbox) && | 130 !parsed_command_line.HasSwitch(switches::kNoSandbox) && |
139 !parsed_command_line.HasSwitch(switches::kDisableSetuidSandbox); | 131 !parsed_command_line.HasSwitch(switches::kDisableSetuidSandbox); |
140 | 132 |
141 if (want_setuid_sandbox) { | 133 if (want_setuid_sandbox) { |
| 134 base::FilePath exe_dir; |
| 135 if (PathService::Get(base::DIR_EXE, &exe_dir)) { |
| 136 base::FilePath sandbox_candidate = exe_dir.AppendASCII("chrome-sandbox"); |
| 137 if (base::PathExists(sandbox_candidate)) |
| 138 sandbox_binary = sandbox_candidate; |
| 139 } |
| 140 |
| 141 // In user-managed builds, including development builds, an environment |
| 142 // variable is required to enable the sandbox. See |
| 143 // http://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment |
| 144 if (sandbox_binary.empty() && |
| 145 stat(base::kProcSelfExe, &st) == 0 && st.st_uid == getuid()) { |
| 146 const char* devel_sandbox_path = getenv("CHROME_DEVEL_SANDBOX"); |
| 147 if (devel_sandbox_path) { |
| 148 env_chrome_devel_sandbox_set = true; |
| 149 sandbox_binary = base::FilePath(devel_sandbox_path); |
| 150 } |
| 151 } |
| 152 |
142 static const char no_suid_error[] = "Running without the SUID sandbox! See " | 153 static const char no_suid_error[] = "Running without the SUID sandbox! See " |
143 "https://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment " | 154 "https://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment " |
144 "for more information on developing with the sandbox on."; | 155 "for more information on developing with the sandbox on."; |
145 if (!sandbox_binary) { | 156 if (sandbox_binary.empty()) { |
146 // This needs to be fatal. Talk to security@chromium.org if you feel | 157 if (!env_chrome_devel_sandbox_set) { |
147 // otherwise. | 158 // This needs to be fatal. Talk to security@chromium.org if you feel |
148 LOG(FATAL) << no_suid_error; | 159 // otherwise. |
| 160 LOG(FATAL) << no_suid_error; |
| 161 } |
| 162 |
| 163 // TODO(jln): an empty CHROME_DEVEL_SANDBOX environment variable (as |
| 164 // opposed to a non existing one) is not fatal yet. This is needed |
| 165 // because of existing bots and scripts. Fix it (crbug.com/245376). |
| 166 LOG(ERROR) << no_suid_error; |
149 } | 167 } |
150 // TODO(jln): an empty CHROME_DEVEL_SANDBOX environment variable (as | |
151 // opposed to a non existing one) is not fatal yet. This is needed because | |
152 // of existing bots and scripts. Fix it (crbug.com/245376). | |
153 if (sandbox_binary && *sandbox_binary == '\0') | |
154 LOG(ERROR) << no_suid_error; | |
155 } | |
156 | |
157 std::string sandbox_cmd; | |
158 if (want_setuid_sandbox && sandbox_binary) { | |
159 sandbox_cmd = sandbox_binary; | |
160 } | 168 } |
161 | 169 |
162 // Tickle the sandbox host and zygote host so they fork now. | 170 // Tickle the sandbox host and zygote host so they fork now. |
163 RenderSandboxHostLinux::GetInstance()->Init(sandbox_cmd); | 171 RenderSandboxHostLinux::GetInstance()->Init(sandbox_binary.value()); |
164 ZygoteHostImpl::GetInstance()->Init(sandbox_cmd); | 172 ZygoteHostImpl::GetInstance()->Init(sandbox_binary.value()); |
165 } | 173 } |
166 #endif | 174 #endif |
167 | 175 |
168 #if defined(OS_LINUX) || defined(OS_OPENBSD) | 176 #if defined(OS_LINUX) || defined(OS_OPENBSD) |
169 static void GLibLogHandler(const gchar* log_domain, | 177 static void GLibLogHandler(const gchar* log_domain, |
170 GLogLevelFlags log_level, | 178 GLogLevelFlags log_level, |
171 const gchar* message, | 179 const gchar* message, |
172 gpointer userdata) { | 180 gpointer userdata) { |
173 if (!log_domain) | 181 if (!log_domain) |
174 log_domain = "<unknown>"; | 182 log_domain = "<unknown>"; |
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
951 if (parameters_.ui_task) | 959 if (parameters_.ui_task) |
952 base::MessageLoopForUI::current()->PostTask(FROM_HERE, | 960 base::MessageLoopForUI::current()->PostTask(FROM_HERE, |
953 *parameters_.ui_task); | 961 *parameters_.ui_task); |
954 | 962 |
955 base::RunLoop run_loop; | 963 base::RunLoop run_loop; |
956 run_loop.Run(); | 964 run_loop.Run(); |
957 #endif | 965 #endif |
958 } | 966 } |
959 | 967 |
960 } // namespace content | 968 } // namespace content |
OLD | NEW |