Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(825)

Side by Side Diff: content/browser/browser_main_loop.cc

Issue 20197003: Linux: use sandbox binary alongside chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « build/common.gypi ('k') | content/content_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/process/process_metrics.h" 18 #include "base/process/process_metrics.h"
17 #include "base/run_loop.h" 19 #include "base/run_loop.h"
18 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
19 #include "base/system_monitor/system_monitor.h" 21 #include "base/system_monitor/system_monitor.h"
20 #include "base/threading/thread_restrictions.h" 22 #include "base/threading/thread_restrictions.h"
21 #include "base/timer/hi_res_timer_manager.h" 23 #include "base/timer/hi_res_timer_manager.h"
22 #include "content/browser/browser_thread_impl.h" 24 #include "content/browser/browser_thread_impl.h"
23 #include "content/browser/device_orientation/device_motion_service.h" 25 #include "content/browser/device_orientation/device_motion_service.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 #endif 112 #endif
111 113
112 namespace content { 114 namespace content {
113 namespace { 115 namespace {
114 116
115 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) 117 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
116 void SetupSandbox(const CommandLine& parsed_command_line) { 118 void SetupSandbox(const CommandLine& parsed_command_line) {
117 TRACE_EVENT0("startup", "SetupSandbox"); 119 TRACE_EVENT0("startup", "SetupSandbox");
118 // TODO(evanm): move this into SandboxWrapper; I'm just trying to move this 120 // TODO(evanm): move this into SandboxWrapper; I'm just trying to move this
119 // code en masse out of chrome_main for now. 121 // code en masse out of chrome_main for now.
120 const char* sandbox_binary = NULL; 122 base::FilePath sandbox_binary;
123 bool env_chrome_devel_sandbox_set = false;
121 struct stat st; 124 struct stat st;
122 125
123 // In Chromium branded builds, developers can set an environment variable to 126 base::FilePath exe_dir;
124 // use the development sandbox. See 127 if (PathService::Get(base::DIR_EXE, &exe_dir)) {
128 base::FilePath sandbox_candidate = exe_dir.AppendASCII("chrome-sandbox");
129 if (base::PathExists(sandbox_candidate))
130 sandbox_binary = sandbox_candidate;
131 }
132
133 // In user-managed builds, including development builds, an environment
134 // variable is required to enable the sandbox. See
125 // http://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment 135 // http://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment
126 if (stat(base::kProcSelfExe, &st) == 0 && st.st_uid == getuid()) 136 if (sandbox_binary.empty() &&
127 sandbox_binary = getenv("CHROME_DEVEL_SANDBOX"); 137 stat(base::kProcSelfExe, &st) == 0 && st.st_uid == getuid()) {
128 138 const char* devel_sandbox_path = getenv("CHROME_DEVEL_SANDBOX");
129 #if defined(LINUX_SANDBOX_PATH) 139 if (devel_sandbox_path) {
130 if (!sandbox_binary) 140 env_chrome_devel_sandbox_set = true;
131 sandbox_binary = LINUX_SANDBOX_PATH; 141 sandbox_binary = base::FilePath(devel_sandbox_path);
132 #endif 142 }
143 }
133 144
134 const bool want_setuid_sandbox = 145 const bool want_setuid_sandbox =
135 !parsed_command_line.HasSwitch(switches::kNoSandbox) && 146 !parsed_command_line.HasSwitch(switches::kNoSandbox) &&
136 !parsed_command_line.HasSwitch(switches::kDisableSetuidSandbox); 147 !parsed_command_line.HasSwitch(switches::kDisableSetuidSandbox);
137 148
138 if (want_setuid_sandbox) { 149 if (want_setuid_sandbox) {
139 static const char no_suid_error[] = "Running without the SUID sandbox! See " 150 static const char no_suid_error[] = "Running without the SUID sandbox! See "
140 "https://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment " 151 "https://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment "
141 "for more information on developing with the sandbox on."; 152 "for more information on developing with the sandbox on.";
142 if (!sandbox_binary) { 153 if (sandbox_binary.empty()) {
143 // This needs to be fatal. Talk to security@chromium.org if you feel 154 if (!env_chrome_devel_sandbox_set) {
144 // otherwise. 155 // This needs to be fatal. Talk to security@chromium.org if you feel
145 LOG(FATAL) << no_suid_error; 156 // otherwise.
157 LOG(FATAL) << no_suid_error;
158 }
159
160 // TODO(jln): an empty CHROME_DEVEL_SANDBOX environment variable (as
161 // opposed to a non existing one) is not fatal yet. This is needed
162 // because of existing bots and scripts. Fix it (crbug.com/245376).
163 LOG(ERROR) << no_suid_error;
146 } 164 }
147 // TODO(jln): an empty CHROME_DEVEL_SANDBOX environment variable (as
148 // opposed to a non existing one) is not fatal yet. This is needed because
149 // of existing bots and scripts. Fix it (crbug.com/245376).
150 if (sandbox_binary && *sandbox_binary == '\0')
151 LOG(ERROR) << no_suid_error;
152 }
153
154 std::string sandbox_cmd;
155 if (want_setuid_sandbox && sandbox_binary) {
156 sandbox_cmd = sandbox_binary;
157 } 165 }
158 166
159 // Tickle the sandbox host and zygote host so they fork now. 167 // Tickle the sandbox host and zygote host so they fork now.
160 RenderSandboxHostLinux::GetInstance()->Init(sandbox_cmd); 168 RenderSandboxHostLinux::GetInstance()->Init(sandbox_binary.value());
161 ZygoteHostImpl::GetInstance()->Init(sandbox_cmd); 169 ZygoteHostImpl::GetInstance()->Init(sandbox_binary.value());
162 } 170 }
163 #endif 171 #endif
164 172
165 #if defined(OS_LINUX) || defined(OS_OPENBSD) 173 #if defined(OS_LINUX) || defined(OS_OPENBSD)
166 static void GLibLogHandler(const gchar* log_domain, 174 static void GLibLogHandler(const gchar* log_domain,
167 GLogLevelFlags log_level, 175 GLogLevelFlags log_level,
168 const gchar* message, 176 const gchar* message,
169 gpointer userdata) { 177 gpointer userdata) {
170 if (!log_domain) 178 if (!log_domain)
171 log_domain = "<unknown>"; 179 log_domain = "<unknown>";
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 if (parameters_.ui_task) 909 if (parameters_.ui_task)
902 base::MessageLoopForUI::current()->PostTask(FROM_HERE, 910 base::MessageLoopForUI::current()->PostTask(FROM_HERE,
903 *parameters_.ui_task); 911 *parameters_.ui_task);
904 912
905 base::RunLoop run_loop; 913 base::RunLoop run_loop;
906 run_loop.Run(); 914 run_loop.Run();
907 #endif 915 #endif
908 } 916 }
909 917
910 } // namespace content 918 } // namespace content
OLDNEW
« no previous file with comments | « build/common.gypi ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698