blob: 1e918b592dd8311599058a6ca5a7009b5ef9fff8 [file] [log] [blame]
[email protected]3b63f8f42011-03-28 01:54:151// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]cc8f1462009-06-12 17:36:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]e63c4d72011-05-31 22:38:295#include "content/browser/zygote_host_linux.h"
6
[email protected]a0f200ea2009-08-06 18:44:067#include <dlfcn.h>
[email protected]a9c54a172009-11-07 06:09:388#include <fcntl.h>
[email protected]724df992010-09-21 18:19:109#include <pthread.h>
[email protected]8ecd3aad2009-11-04 08:32:2210#include <sys/socket.h>
[email protected]a9c54a172009-11-07 06:09:3811#include <sys/stat.h>
[email protected]8ecd3aad2009-11-04 08:32:2212#include <sys/types.h>
[email protected]83a0cbe2009-11-04 04:22:4713#include <sys/wait.h>
[email protected]8ecd3aad2009-11-04 08:32:2214#include <unistd.h>
15
[email protected]789f70c72009-07-24 13:55:4316#include "base/basictypes.h"
[email protected]cc8f1462009-06-12 17:36:5517#include "base/command_line.h"
18#include "base/eintr_wrapper.h"
[email protected]5d91c9e2010-07-28 17:25:2819#include "base/file_path.h"
[email protected]e1d67a882011-08-31 21:11:0420#include "base/file_util.h"
[email protected]cc8f1462009-06-12 17:36:5521#include "base/global_descriptors_posix.h"
[email protected]8ecd3aad2009-11-04 08:32:2222#include "base/hash_tables.h"
23#include "base/linux_util.h"
[email protected]3b63f8f42011-03-28 01:54:1524#include "base/memory/scoped_ptr.h"
[email protected]cc8f1462009-06-12 17:36:5525#include "base/pickle.h"
[email protected]4d36536b2010-08-20 06:23:2726#include "base/process_util.h"
[email protected]4378a822009-07-08 01:15:1427#include "base/rand_util.h"
[email protected]80a086c52009-08-04 17:52:0428#include "base/sys_info.h"
[email protected]8015de32009-11-18 04:13:3329#include "build/build_config.h"
[email protected]4b559b4d2011-04-14 17:37:1430#include "crypto/nss_util.h"
[email protected]acb94722011-03-18 01:33:3431#include "content/common/chrome_descriptors.h"
[email protected]797c3552011-03-17 00:26:1832#include "content/common/font_config_ipc_linux.h"
[email protected]cebc3dc2011-04-18 17:15:0033#include "content/common/pepper_plugin_registry.h"
[email protected]4dd57932011-03-17 06:06:1234#include "content/common/sandbox_methods_linux.h"
[email protected]65f607f2011-08-03 21:08:1235#include "content/common/seccomp_sandbox.h"
[email protected]4dd57932011-03-17 06:06:1236#include "content/common/set_process_title.h"
[email protected]797c3552011-03-17 00:26:1837#include "content/common/unix_domain_socket_posix.h"
[email protected]c08950d22011-10-13 22:20:2938#include "content/public/common/content_switches.h"
[email protected]4573fbd2011-10-31 20:25:1839#include "content/public/common/main_function_params.h"
[email protected]b39ef1cb2011-10-25 04:46:5540#include "content/public/common/result_codes.h"
[email protected]f8ba13d2011-10-25 16:08:5241#include "content/public/common/zygote_fork_delegate_linux.h"
[email protected]cf3ac3972010-12-22 20:02:2942#include "skia/ext/SkFontHost_fontconfig_control.h"
[email protected]1831acf2009-10-05 16:38:4143#include "unicode/timezone.h"
[email protected]e1d67a882011-08-31 21:11:0444#include "ipc/ipc_channel.h"
[email protected]ce2ae442011-07-18 16:13:4145#include "ipc/ipc_switches.h"
[email protected]1831acf2009-10-05 16:38:4146
[email protected]e63c4d72011-05-31 22:38:2947#if defined(OS_LINUX)
48#include <sys/epoll.h>
49#include <sys/prctl.h>
50#include <sys/signal.h>
51#else
52#include <signal.h>
53#endif
54
55#if defined(CHROMIUM_SELINUX)
56#include <selinux/selinux.h>
57#include <selinux/context.h>
58#endif
59
[email protected]cc8f1462009-06-12 17:36:5560// http://code.google.com/p/chromium/wiki/LinuxZygote
61
[email protected]8ecd3aad2009-11-04 08:32:2262static const int kBrowserDescriptor = 3;
[email protected]73fa63992009-07-20 20:30:0763static const int kMagicSandboxIPCDescriptor = 5;
[email protected]8ecd3aad2009-11-04 08:32:2264static const int kZygoteIdDescriptor = 7;
65static bool g_suid_sandbox_active = false;
[email protected]2bc039a2011-07-29 23:05:4166
[email protected]2bc039a2011-07-29 23:05:4167#if defined(SECCOMP_SANDBOX)
[email protected]2bc039a2011-07-29 23:05:4168static int g_proc_fd = -1;
[email protected]65f607f2011-08-03 21:08:1269#endif
[email protected]2bc039a2011-07-29 23:05:4170
[email protected]a89a55dd2010-04-19 14:51:1371#if defined(CHROMIUM_SELINUX)
72static void SELinuxTransitionToTypeOrDie(const char* type) {
73 security_context_t security_context;
74 if (getcon(&security_context))
75 LOG(FATAL) << "Cannot get SELinux context";
76
77 context_t context = context_new(security_context);
78 context_type_set(context, type);
79 const int r = setcon(context_str(context));
80 context_free(context);
81 freecon(security_context);
82
83 if (r) {
84 LOG(FATAL) << "dynamic transition to type '" << type << "' failed. "
85 "(this binary has been built with SELinux support, but maybe "
86 "the policies haven't been loaded into the kernel?)";
87 }
88}
89#endif // CHROMIUM_SELINUX
90
[email protected]cc8f1462009-06-12 17:36:5591// This is the object which implements the zygote. The ZygoteMain function,
[email protected]61883442010-07-12 15:14:3492// which is called from ChromeMain, simply constructs one of these objects and
93// runs it.
[email protected]cc8f1462009-06-12 17:36:5594class Zygote {
95 public:
[email protected]f8ba13d2011-10-25 16:08:5296 Zygote(int sandbox_flags, content::ZygoteForkDelegate* helper)
[email protected]5abe6302011-12-20 23:44:3297 : sandbox_flags_(sandbox_flags),
98 helper_(helper),
99 initial_uma_sample_(0),
100 initial_uma_boundary_value_(0) {
[email protected]8d5d7612011-10-20 18:23:14101 if (helper_)
102 helper_->InitialUMA(&initial_uma_name_,
103 &initial_uma_sample_,
104 &initial_uma_boundary_value_);
[email protected]715b4f262010-07-13 14:17:28105 }
106
[email protected]cc8f1462009-06-12 17:36:55107 bool ProcessRequests() {
108 // A SOCK_SEQPACKET socket is installed in fd 3. We get commands from the
109 // browser on it.
[email protected]8ecd3aad2009-11-04 08:32:22110 // A SOCK_DGRAM is installed in fd 5. This is the sandbox IPC channel.
[email protected]abe3ad92009-06-15 18:15:08111 // See http://code.google.com/p/chromium/wiki/LinuxSandboxIPC
[email protected]cc8f1462009-06-12 17:36:55112
113 // We need to accept SIGCHLD, even though our handler is a no-op because
114 // otherwise we cannot wait on children. (According to POSIX 2001.)
115 struct sigaction action;
116 memset(&action, 0, sizeof(action));
117 action.sa_handler = SIGCHLDHandler;
118 CHECK(sigaction(SIGCHLD, &action, NULL) == 0);
119
[email protected]8ecd3aad2009-11-04 08:32:22120 if (g_suid_sandbox_active) {
121 // Let the ZygoteHost know we are ready to go.
[email protected]8a282712011-08-23 19:28:00122 // The receiving code is in content/browser/zygote_host_linux.cc.
[email protected]8ecd3aad2009-11-04 08:32:22123 std::vector<int> empty;
[email protected]cf3ac3972010-12-22 20:02:29124 bool r = UnixDomainSocket::SendMsg(kBrowserDescriptor, kZygoteMagic,
125 sizeof(kZygoteMagic), empty);
[email protected]bfc672a52011-07-20 07:51:27126#if defined(OS_CHROMEOS)
127 LOG_IF(WARNING, r) << "Sending zygote magic failed";
128 // Exit normally on chromeos because session manager may send SIGTERM
129 // right after the process starts and it may fail to send zygote magic
130 // number to browser process.
[email protected]a45f1832011-07-20 18:01:15131 if (!r)
132 _exit(content::RESULT_CODE_NORMAL_EXIT);
[email protected]bfc672a52011-07-20 07:51:27133#else
[email protected]8ecd3aad2009-11-04 08:32:22134 CHECK(r) << "Sending zygote magic failed";
[email protected]bfc672a52011-07-20 07:51:27135#endif
[email protected]8ecd3aad2009-11-04 08:32:22136 }
137
[email protected]cc8f1462009-06-12 17:36:55138 for (;;) {
[email protected]c548be22010-03-08 12:55:57139 // This function call can return multiple times, once per fork().
[email protected]8ecd3aad2009-11-04 08:32:22140 if (HandleRequestFromBrowser(kBrowserDescriptor))
[email protected]cc8f1462009-06-12 17:36:55141 return true;
142 }
143 }
144
145 private:
146 // See comment below, where sigaction is called.
147 static void SIGCHLDHandler(int signal) { }
148
149 // ---------------------------------------------------------------------------
150 // Requests from the browser...
151
152 // Read and process a request from the browser. Returns true if we are in a
153 // new process and thus need to unwind back into ChromeMain.
154 bool HandleRequestFromBrowser(int fd) {
155 std::vector<int> fds;
[email protected]2752bf62011-03-23 21:06:06156 static const unsigned kMaxMessageLength = 2048;
[email protected]cc8f1462009-06-12 17:36:55157 char buf[kMaxMessageLength];
[email protected]cf3ac3972010-12-22 20:02:29158 const ssize_t len = UnixDomainSocket::RecvMsg(fd, buf, sizeof(buf), &fds);
[email protected]7ae27b92010-09-24 17:33:36159
160 if (len == 0 || (len == -1 && errno == ECONNRESET)) {
161 // EOF from the browser. We should die.
162 _exit(0);
[email protected]cc8f1462009-06-12 17:36:55163 return false;
164 }
165
[email protected]7ae27b92010-09-24 17:33:36166 if (len == -1) {
167 PLOG(ERROR) << "Error reading message from browser";
[email protected]cc8f1462009-06-12 17:36:55168 return false;
169 }
170
171 Pickle pickle(buf, len);
172 void* iter = NULL;
173
174 int kind;
[email protected]57113ea2009-06-18 02:23:16175 if (pickle.ReadInt(&iter, &kind)) {
176 switch (kind) {
177 case ZygoteHost::kCmdFork:
[email protected]c548be22010-03-08 12:55:57178 // This function call can return multiple times, once per fork().
[email protected]57113ea2009-06-18 02:23:16179 return HandleForkRequest(fd, pickle, iter, fds);
[email protected]ce2ae442011-07-18 16:13:41180
[email protected]57113ea2009-06-18 02:23:16181 case ZygoteHost::kCmdReap:
182 if (!fds.empty())
183 break;
[email protected]c548be22010-03-08 12:55:57184 HandleReapRequest(fd, pickle, iter);
185 return false;
[email protected]443b80e2010-12-14 00:42:23186 case ZygoteHost::kCmdGetTerminationStatus:
[email protected]57113ea2009-06-18 02:23:16187 if (!fds.empty())
188 break;
[email protected]443b80e2010-12-14 00:42:23189 HandleGetTerminationStatus(fd, pickle, iter);
[email protected]c548be22010-03-08 12:55:57190 return false;
[email protected]715b4f262010-07-13 14:17:28191 case ZygoteHost::kCmdGetSandboxStatus:
192 HandleGetSandboxStatus(fd, pickle, iter);
193 return false;
[email protected]57113ea2009-06-18 02:23:16194 default:
195 NOTREACHED();
196 break;
197 }
[email protected]cc8f1462009-06-12 17:36:55198 }
199
[email protected]cc8f1462009-06-12 17:36:55200 LOG(WARNING) << "Error parsing message from browser";
201 for (std::vector<int>::const_iterator
202 i = fds.begin(); i != fds.end(); ++i)
203 close(*i);
204 return false;
205 }
206
[email protected]c548be22010-03-08 12:55:57207 void HandleReapRequest(int fd, const Pickle& pickle, void* iter) {
[email protected]8ecd3aad2009-11-04 08:32:22208 base::ProcessId child;
209 base::ProcessId actual_child;
[email protected]cc8f1462009-06-12 17:36:55210
211 if (!pickle.ReadInt(&iter, &child)) {
212 LOG(WARNING) << "Error parsing reap request from browser";
[email protected]c548be22010-03-08 12:55:57213 return;
[email protected]cc8f1462009-06-12 17:36:55214 }
215
[email protected]8ecd3aad2009-11-04 08:32:22216 if (g_suid_sandbox_active) {
217 actual_child = real_pids_to_sandbox_pids[child];
218 if (!actual_child)
[email protected]c548be22010-03-08 12:55:57219 return;
[email protected]8ecd3aad2009-11-04 08:32:22220 real_pids_to_sandbox_pids.erase(child);
221 } else {
222 actual_child = child;
223 }
224
[email protected]eaac71592011-11-23 18:32:00225 base::EnsureProcessTerminated(actual_child);
[email protected]cc8f1462009-06-12 17:36:55226 }
227
[email protected]443b80e2010-12-14 00:42:23228 void HandleGetTerminationStatus(int fd, const Pickle& pickle, void* iter) {
[email protected]57113ea2009-06-18 02:23:16229 base::ProcessHandle child;
230
231 if (!pickle.ReadInt(&iter, &child)) {
[email protected]443b80e2010-12-14 00:42:23232 LOG(WARNING) << "Error parsing GetTerminationStatus request "
233 << "from browser";
[email protected]c548be22010-03-08 12:55:57234 return;
[email protected]57113ea2009-06-18 02:23:16235 }
236
[email protected]443b80e2010-12-14 00:42:23237 base::TerminationStatus status;
238 int exit_code;
[email protected]8ecd3aad2009-11-04 08:32:22239 if (g_suid_sandbox_active)
240 child = real_pids_to_sandbox_pids[child];
[email protected]443b80e2010-12-14 00:42:23241 if (child) {
242 status = base::GetTerminationStatus(child, &exit_code);
243 } else {
244 // Assume that if we can't find the child in the sandbox, then
245 // it terminated normally.
246 status = base::TERMINATION_STATUS_NORMAL_TERMINATION;
[email protected]1fcfb202011-07-19 19:53:14247 exit_code = content::RESULT_CODE_NORMAL_EXIT;
[email protected]443b80e2010-12-14 00:42:23248 }
[email protected]57113ea2009-06-18 02:23:16249
250 Pickle write_pickle;
[email protected]443b80e2010-12-14 00:42:23251 write_pickle.WriteInt(static_cast<int>(status));
252 write_pickle.WriteInt(exit_code);
[email protected]8a861402011-01-28 19:59:11253 ssize_t written =
254 HANDLE_EINTR(write(fd, write_pickle.data(), write_pickle.size()));
255 if (written != static_cast<ssize_t>(write_pickle.size()))
[email protected]19cb9292010-04-16 23:00:15256 PLOG(ERROR) << "write";
[email protected]57113ea2009-06-18 02:23:16257 }
258
[email protected]28ecba32010-09-16 10:03:09259 // This is equivalent to fork(), except that, when using the SUID
260 // sandbox, it returns the real PID of the child process as it
261 // appears outside the sandbox, rather than returning the PID inside
[email protected]8d5d7612011-10-20 18:23:14262 // the sandbox. Optionally, it fills in uma_name et al with a report
263 // the helper wants to make via UMA_HISTOGRAM_ENUMERATION.
[email protected]ce2ae442011-07-18 16:13:41264 int ForkWithRealPid(const std::string& process_type, std::vector<int>& fds,
[email protected]8d5d7612011-10-20 18:23:14265 const std::string& channel_switch,
266 std::string* uma_name,
267 int* uma_sample, int* uma_boundary_value) {
268 const bool use_helper = (helper_ && helper_->CanHelp(process_type,
269 uma_name,
270 uma_sample,
271 uma_boundary_value));
[email protected]ce2ae442011-07-18 16:13:41272 if (!(use_helper || g_suid_sandbox_active)) {
[email protected]28ecba32010-09-16 10:03:09273 return fork();
[email protected]ce2ae442011-07-18 16:13:41274 }
[email protected]28ecba32010-09-16 10:03:09275
276 int dummy_fd;
277 ino_t dummy_inode;
278 int pipe_fds[2] = { -1, -1 };
[email protected]073040b2010-09-26 02:35:45279 base::ProcessId pid = 0;
[email protected]28ecba32010-09-16 10:03:09280
281 dummy_fd = socket(PF_UNIX, SOCK_DGRAM, 0);
282 if (dummy_fd < 0) {
283 LOG(ERROR) << "Failed to create dummy FD";
284 goto error;
285 }
286 if (!base::FileDescriptorGetInode(&dummy_inode, dummy_fd)) {
287 LOG(ERROR) << "Failed to get inode for dummy FD";
288 goto error;
289 }
290 if (pipe(pipe_fds) != 0) {
291 LOG(ERROR) << "Failed to create pipe";
292 goto error;
293 }
294
[email protected]ce2ae442011-07-18 16:13:41295 if (use_helper) {
296 fds.push_back(dummy_fd);
297 fds.push_back(pipe_fds[0]);
298 pid = helper_->Fork(fds);
299 } else {
300 pid = fork();
301 }
[email protected]28ecba32010-09-16 10:03:09302 if (pid < 0) {
303 goto error;
304 } else if (pid == 0) {
305 // In the child process.
306 close(pipe_fds[1]);
[email protected]e1d67a882011-08-31 21:11:04307 base::ProcessId real_pid;
[email protected]28ecba32010-09-16 10:03:09308 // Wait until the parent process has discovered our PID. We
309 // should not fork any child processes (which the seccomp
310 // sandbox does) until then, because that can interfere with the
311 // parent's discovery of our PID.
[email protected]e1d67a882011-08-31 21:11:04312 if (!file_util::ReadFromFD(pipe_fds[0],
313 reinterpret_cast<char*>(&real_pid),
314 sizeof(real_pid))) {
[email protected]28ecba32010-09-16 10:03:09315 LOG(FATAL) << "Failed to synchronise with parent zygote process";
316 }
[email protected]e1d67a882011-08-31 21:11:04317 if (real_pid <= 0) {
318 LOG(FATAL) << "Invalid pid from parent zygote";
319 }
320#if defined(OS_LINUX)
321 // Sandboxed processes need to send the global, non-namespaced PID when
322 // setting up an IPC channel to their parent.
323 IPC::Channel::SetGlobalPid(real_pid);
324#endif
[email protected]28ecba32010-09-16 10:03:09325 close(pipe_fds[0]);
326 close(dummy_fd);
327 return 0;
328 } else {
329 // In the parent process.
330 close(dummy_fd);
331 dummy_fd = -1;
332 close(pipe_fds[0]);
333 pipe_fds[0] = -1;
[email protected]4229b5d2011-07-16 02:47:37334 base::ProcessId real_pid;
[email protected]ce2ae442011-07-18 16:13:41335 if (g_suid_sandbox_active) {
336 uint8_t reply_buf[512];
337 Pickle request;
338 request.WriteInt(LinuxSandbox::METHOD_GET_CHILD_WITH_INODE);
339 request.WriteUInt64(dummy_inode);
340
341 const ssize_t r = UnixDomainSocket::SendRecvMsg(
342 kMagicSandboxIPCDescriptor, reply_buf, sizeof(reply_buf), NULL,
343 request);
344 if (r == -1) {
345 LOG(ERROR) << "Failed to get child process's real PID";
346 goto error;
347 }
348
349 Pickle reply(reinterpret_cast<char*>(reply_buf), r);
350 void* iter = NULL;
351 if (!reply.ReadInt(&iter, &real_pid))
352 goto error;
353 if (real_pid <= 0) {
354 // METHOD_GET_CHILD_WITH_INODE failed. Did the child die already?
355 LOG(ERROR) << "METHOD_GET_CHILD_WITH_INODE failed";
356 goto error;
357 }
358 real_pids_to_sandbox_pids[real_pid] = pid;
[email protected]4229b5d2011-07-16 02:47:37359 }
[email protected]ce2ae442011-07-18 16:13:41360 if (use_helper) {
361 real_pid = pid;
362 if (!helper_->AckChild(pipe_fds[1], channel_switch)) {
363 LOG(ERROR) << "Failed to synchronise with zygote fork helper";
364 goto error;
365 }
366 } else {
[email protected]e1d67a882011-08-31 21:11:04367 int written =
368 HANDLE_EINTR(write(pipe_fds[1], &real_pid, sizeof(real_pid)));
369 if (written != sizeof(real_pid)) {
[email protected]ce2ae442011-07-18 16:13:41370 LOG(ERROR) << "Failed to synchronise with child process";
371 goto error;
372 }
[email protected]28ecba32010-09-16 10:03:09373 }
374 close(pipe_fds[1]);
375 return real_pid;
376 }
377
378 error:
[email protected]72f891f42011-01-12 17:00:52379 if (pid > 0) {
380 if (waitpid(pid, NULL, WNOHANG) == -1)
381 LOG(ERROR) << "Failed to wait for process";
382 }
[email protected]28ecba32010-09-16 10:03:09383 if (dummy_fd >= 0)
384 close(dummy_fd);
385 if (pipe_fds[0] >= 0)
386 close(pipe_fds[0]);
387 if (pipe_fds[1] >= 0)
388 close(pipe_fds[1]);
389 return -1;
390 }
391
[email protected]35d86242011-09-30 15:29:08392 // Unpacks process type and arguments from |pickle| and forks a new process.
393 // Returns -1 on error, otherwise returns twice, returning 0 to the child
394 // process and the child process ID to the parent process, like fork().
395 base::ProcessId ReadArgsAndFork(const Pickle& pickle,
396 void* iter,
[email protected]8d5d7612011-10-20 18:23:14397 std::vector<int>& fds,
398 std::string* uma_name,
399 int* uma_sample,
400 int* uma_boundary_value) {
[email protected]cc8f1462009-06-12 17:36:55401 std::vector<std::string> args;
[email protected]35d86242011-09-30 15:29:08402 int argc = 0;
403 int numfds = 0;
[email protected]cc8f1462009-06-12 17:36:55404 base::GlobalDescriptors::Mapping mapping;
[email protected]ce2ae442011-07-18 16:13:41405 std::string process_type;
406 std::string channel_id;
407 const std::string channel_id_prefix = std::string("--")
408 + switches::kProcessChannelID + std::string("=");
409
410 if (!pickle.ReadString(&iter, &process_type))
[email protected]35d86242011-09-30 15:29:08411 return -1;
[email protected]cc8f1462009-06-12 17:36:55412 if (!pickle.ReadInt(&iter, &argc))
[email protected]35d86242011-09-30 15:29:08413 return -1;
[email protected]cc8f1462009-06-12 17:36:55414
415 for (int i = 0; i < argc; ++i) {
416 std::string arg;
417 if (!pickle.ReadString(&iter, &arg))
[email protected]35d86242011-09-30 15:29:08418 return -1;
[email protected]cc8f1462009-06-12 17:36:55419 args.push_back(arg);
[email protected]ce2ae442011-07-18 16:13:41420 if (arg.compare(0, channel_id_prefix.length(), channel_id_prefix) == 0)
421 channel_id = arg;
[email protected]cc8f1462009-06-12 17:36:55422 }
423
424 if (!pickle.ReadInt(&iter, &numfds))
[email protected]35d86242011-09-30 15:29:08425 return -1;
[email protected]cc8f1462009-06-12 17:36:55426 if (numfds != static_cast<int>(fds.size()))
[email protected]35d86242011-09-30 15:29:08427 return -1;
[email protected]cc8f1462009-06-12 17:36:55428
429 for (int i = 0; i < numfds; ++i) {
430 base::GlobalDescriptors::Key key;
431 if (!pickle.ReadUInt32(&iter, &key))
[email protected]35d86242011-09-30 15:29:08432 return -1;
[email protected]cc8f1462009-06-12 17:36:55433 mapping.push_back(std::make_pair(key, fds[i]));
434 }
435
[email protected]abe3ad92009-06-15 18:15:08436 mapping.push_back(std::make_pair(
[email protected]8ecd3aad2009-11-04 08:32:22437 static_cast<uint32_t>(kSandboxIPCChannel), kMagicSandboxIPCDescriptor));
438
[email protected]35d86242011-09-30 15:29:08439 // Returns twice, once per process.
[email protected]8d5d7612011-10-20 18:23:14440 base::ProcessId child_pid = ForkWithRealPid(process_type, fds, channel_id,
441 uma_name, uma_sample,
442 uma_boundary_value);
[email protected]35d86242011-09-30 15:29:08443 if (!child_pid) {
444 // This is the child process.
[email protected]36ea6c6f2010-03-17 20:08:01445#if defined(SECCOMP_SANDBOX)
[email protected]65f607f2011-08-03 21:08:12446 if (SeccompSandboxEnabled() && g_proc_fd >= 0) {
[email protected]2bc039a2011-07-29 23:05:41447 // Try to open /proc/self/maps as the seccomp sandbox needs access to it
[email protected]a9c54a172009-11-07 06:09:38448 int proc_self_maps = openat(g_proc_fd, "self/maps", O_RDONLY);
449 if (proc_self_maps >= 0) {
450 SeccompSandboxSetProcSelfMaps(proc_self_maps);
[email protected]2bc039a2011-07-29 23:05:41451 } else {
452 PLOG(ERROR) << "openat(/proc/self/maps)";
[email protected]a9c54a172009-11-07 06:09:38453 }
454 close(g_proc_fd);
455 g_proc_fd = -1;
456 }
[email protected]8015de32009-11-18 04:13:33457#endif
[email protected]a9c54a172009-11-07 06:09:38458
[email protected]8ecd3aad2009-11-04 08:32:22459 close(kBrowserDescriptor); // our socket from the browser
[email protected]cbcf9cc32010-02-17 04:05:59460 if (g_suid_sandbox_active)
461 close(kZygoteIdDescriptor); // another socket from the browser
[email protected]9b85081af2010-12-07 21:26:47462 base::GlobalDescriptors::GetInstance()->Reset(mapping);
[email protected]0189bbd2009-10-12 22:50:39463
[email protected]a89a55dd2010-04-19 14:51:13464#if defined(CHROMIUM_SELINUX)
465 SELinuxTransitionToTypeOrDie("chromium_renderer_t");
466#endif
467
[email protected]0189bbd2009-10-12 22:50:39468 // Reset the process-wide command line to our new command line.
[email protected]cc8f1462009-06-12 17:36:55469 CommandLine::Reset();
[email protected]0189bbd2009-10-12 22:50:39470 CommandLine::Init(0, NULL);
471 CommandLine::ForCurrentProcess()->InitFromArgv(args);
[email protected]74e9fa22010-12-29 21:06:43472
473 // Update the process title. The argv was already cached by the call to
474 // SetProcessTitleFromCommandLine in ChromeMain, so we can pass NULL here
475 // (we don't have the original argv at this point).
476 SetProcessTitleFromCommandLine(NULL);
[email protected]35d86242011-09-30 15:29:08477 } else if (child_pid < 0) {
478 LOG(ERROR) << "Zygote could not fork: process_type " << process_type
479 << " numfds " << numfds << " child_pid " << child_pid;
[email protected]cc8f1462009-06-12 17:36:55480 }
[email protected]35d86242011-09-30 15:29:08481 return child_pid;
482 }
[email protected]cc8f1462009-06-12 17:36:55483
[email protected]35d86242011-09-30 15:29:08484 // Handle a 'fork' request from the browser: this means that the browser
485 // wishes to start a new renderer. Returns true if we are in a new process,
486 // otherwise writes the child_pid back to the browser via |fd|. Writes a
487 // child_pid of -1 on error.
488 bool HandleForkRequest(int fd, const Pickle& pickle,
489 void* iter, std::vector<int>& fds) {
[email protected]8d5d7612011-10-20 18:23:14490 std::string uma_name;
491 int uma_sample;
492 int uma_boundary_value;
493 base::ProcessId child_pid = ReadArgsAndFork(pickle, iter, fds,
494 &uma_name, &uma_sample,
495 &uma_boundary_value);
[email protected]35d86242011-09-30 15:29:08496 if (child_pid == 0)
497 return true;
[email protected]28ecba32010-09-16 10:03:09498 for (std::vector<int>::const_iterator
499 i = fds.begin(); i != fds.end(); ++i)
500 close(*i);
[email protected]8d5d7612011-10-20 18:23:14501 if (uma_name.empty()) {
502 // There is no UMA report from this particular fork.
503 // Use the initial UMA report if any, and clear that record for next time.
504 // Note the swap method here is the efficient way to do this, since
505 // we know uma_name is empty.
506 uma_name.swap(initial_uma_name_);
507 uma_sample = initial_uma_sample_;
508 uma_boundary_value = initial_uma_boundary_value_;
509 }
[email protected]35d86242011-09-30 15:29:08510 // Must always send reply, as ZygoteHost blocks while waiting for it.
[email protected]8d5d7612011-10-20 18:23:14511 Pickle reply_pickle;
512 reply_pickle.WriteInt(child_pid);
513 reply_pickle.WriteString(uma_name);
514 if (!uma_name.empty()) {
515 reply_pickle.WriteInt(uma_sample);
516 reply_pickle.WriteInt(uma_boundary_value);
517 }
518 if (HANDLE_EINTR(write(fd, reply_pickle.data(), reply_pickle.size())) !=
519 static_cast<ssize_t> (reply_pickle.size()))
[email protected]28ecba32010-09-16 10:03:09520 PLOG(ERROR) << "write";
521 return false;
[email protected]cc8f1462009-06-12 17:36:55522 }
[email protected]8ecd3aad2009-11-04 08:32:22523
[email protected]715b4f262010-07-13 14:17:28524 bool HandleGetSandboxStatus(int fd, const Pickle& pickle, void* iter) {
525 if (HANDLE_EINTR(write(fd, &sandbox_flags_, sizeof(sandbox_flags_)) !=
526 sizeof(sandbox_flags_))) {
527 PLOG(ERROR) << "write";
528 }
529
530 return false;
531 }
532
[email protected]8ecd3aad2009-11-04 08:32:22533 // In the SUID sandbox, we try to use a new PID namespace. Thus the PIDs
534 // fork() returns are not the real PIDs, so we need to map the Real PIDS
535 // into the sandbox PID namespace.
536 typedef base::hash_map<base::ProcessHandle, base::ProcessHandle> ProcessMap;
537 ProcessMap real_pids_to_sandbox_pids;
[email protected]715b4f262010-07-13 14:17:28538
539 const int sandbox_flags_;
[email protected]f8ba13d2011-10-25 16:08:52540 content::ZygoteForkDelegate* helper_;
[email protected]8d5d7612011-10-20 18:23:14541
542 // These might be set by helper_->InitialUMA. They supply a UMA
543 // enumeration sample we should report on the first fork.
544 std::string initial_uma_name_;
545 int initial_uma_sample_;
546 int initial_uma_boundary_value_;
[email protected]cc8f1462009-06-12 17:36:55547};
548
[email protected]ad6d2c42009-09-15 20:13:38549// With SELinux we can carve out a precise sandbox, so we don't have to play
550// with intercepting libc calls.
551#if !defined(CHROMIUM_SELINUX)
552
[email protected]a0f200ea2009-08-06 18:44:06553static void ProxyLocaltimeCallToBrowser(time_t input, struct tm* output,
554 char* timezone_out,
555 size_t timezone_out_len) {
[email protected]73fa63992009-07-20 20:30:07556 Pickle request;
557 request.WriteInt(LinuxSandbox::METHOD_LOCALTIME);
558 request.WriteString(
559 std::string(reinterpret_cast<char*>(&input), sizeof(input)));
560
561 uint8_t reply_buf[512];
[email protected]cf3ac3972010-12-22 20:02:29562 const ssize_t r = UnixDomainSocket::SendRecvMsg(
[email protected]73fa63992009-07-20 20:30:07563 kMagicSandboxIPCDescriptor, reply_buf, sizeof(reply_buf), NULL, request);
564 if (r == -1) {
565 memset(output, 0, sizeof(struct tm));
566 return;
567 }
568
569 Pickle reply(reinterpret_cast<char*>(reply_buf), r);
570 void* iter = NULL;
[email protected]9debcda52009-07-22 20:06:51571 std::string result, timezone;
[email protected]73fa63992009-07-20 20:30:07572 if (!reply.ReadString(&iter, &result) ||
[email protected]9debcda52009-07-22 20:06:51573 !reply.ReadString(&iter, &timezone) ||
[email protected]73fa63992009-07-20 20:30:07574 result.size() != sizeof(struct tm)) {
575 memset(output, 0, sizeof(struct tm));
576 return;
577 }
578
579 memcpy(output, result.data(), sizeof(struct tm));
[email protected]9debcda52009-07-22 20:06:51580 if (timezone_out_len) {
581 const size_t copy_len = std::min(timezone_out_len - 1, timezone.size());
582 memcpy(timezone_out, timezone.data(), copy_len);
583 timezone_out[copy_len] = 0;
584 output->tm_zone = timezone_out;
585 } else {
586 output->tm_zone = NULL;
587 }
[email protected]73fa63992009-07-20 20:30:07588}
589
[email protected]a0f200ea2009-08-06 18:44:06590static bool g_am_zygote_or_renderer = false;
591
592// Sandbox interception of libc calls.
593//
594// Because we are running in a sandbox certain libc calls will fail (localtime
595// being the motivating example - it needs to read /etc/localtime). We need to
596// intercept these calls and proxy them to the browser. However, these calls
597// may come from us or from our libraries. In some cases we can't just change
598// our code.
599//
600// It's for these cases that we have the following setup:
601//
602// We define global functions for those functions which we wish to override.
603// Since we will be first in the dynamic resolution order, the dynamic linker
604// will point callers to our versions of these functions. However, we have the
605// same binary for both the browser and the renderers, which means that our
606// overrides will apply in the browser too.
607//
608// The global |g_am_zygote_or_renderer| is true iff we are in a zygote or
609// renderer process. It's set in ZygoteMain and inherited by the renderers when
610// they fork. (This means that it'll be incorrect for global constructor
611// functions and before ZygoteMain is called - beware).
612//
613// Our replacement functions can check this global and either proxy
614// the call to the browser over the sandbox IPC
615// (http://code.google.com/p/chromium/wiki/LinuxSandboxIPC) or they can use
616// dlsym with RTLD_NEXT to resolve the symbol, ignoring any symbols in the
617// current module.
618//
619// Other avenues:
620//
621// Our first attempt involved some assembly to patch the GOT of the current
622// module. This worked, but was platform specific and doesn't catch the case
623// where a library makes a call rather than current module.
624//
625// We also considered patching the function in place, but this would again by
626// platform specific and the above technique seems to work well enough.
627
[email protected]724df992010-09-21 18:19:10628typedef struct tm* (*LocaltimeFunction)(const time_t* timep);
629typedef struct tm* (*LocaltimeRFunction)(const time_t* timep,
630 struct tm* result);
631
632static pthread_once_t g_libc_localtime_funcs_guard = PTHREAD_ONCE_INIT;
633static LocaltimeFunction g_libc_localtime;
634static LocaltimeRFunction g_libc_localtime_r;
635
636static void InitLibcLocaltimeFunctions() {
637 g_libc_localtime = reinterpret_cast<LocaltimeFunction>(
638 dlsym(RTLD_NEXT, "localtime"));
639 g_libc_localtime_r = reinterpret_cast<LocaltimeRFunction>(
640 dlsym(RTLD_NEXT, "localtime_r"));
641
642 if (!g_libc_localtime || !g_libc_localtime_r) {
643 // http://code.google.com/p/chromium/issues/detail?id=16800
644 //
645 // Nvidia's libGL.so overrides dlsym for an unknown reason and replaces
646 // it with a version which doesn't work. In this case we'll get a NULL
647 // result. There's not a lot we can do at this point, so we just bodge it!
648 LOG(ERROR) << "Your system is broken: dlsym doesn't work! This has been "
649 "reported to be caused by Nvidia's libGL. You should expect"
650 " time related functions to misbehave. "
651 "http://code.google.com/p/chromium/issues/detail?id=16800";
652 }
653
654 if (!g_libc_localtime)
655 g_libc_localtime = gmtime;
656 if (!g_libc_localtime_r)
657 g_libc_localtime_r = gmtime_r;
658}
[email protected]a5d7bb82009-09-08 22:30:58659
[email protected]73fa63992009-07-20 20:30:07660struct tm* localtime(const time_t* timep) {
[email protected]a0f200ea2009-08-06 18:44:06661 if (g_am_zygote_or_renderer) {
662 static struct tm time_struct;
663 static char timezone_string[64];
664 ProxyLocaltimeCallToBrowser(*timep, &time_struct, timezone_string,
665 sizeof(timezone_string));
666 return &time_struct;
667 } else {
[email protected]724df992010-09-21 18:19:10668 CHECK_EQ(0, pthread_once(&g_libc_localtime_funcs_guard,
669 InitLibcLocaltimeFunctions));
670 return g_libc_localtime(timep);
[email protected]a0f200ea2009-08-06 18:44:06671 }
[email protected]73fa63992009-07-20 20:30:07672}
673
674struct tm* localtime_r(const time_t* timep, struct tm* result) {
[email protected]a0f200ea2009-08-06 18:44:06675 if (g_am_zygote_or_renderer) {
676 ProxyLocaltimeCallToBrowser(*timep, result, NULL, 0);
677 return result;
678 } else {
[email protected]724df992010-09-21 18:19:10679 CHECK_EQ(0, pthread_once(&g_libc_localtime_funcs_guard,
680 InitLibcLocaltimeFunctions));
681 return g_libc_localtime_r(timep, result);
[email protected]a0f200ea2009-08-06 18:44:06682 }
[email protected]73fa63992009-07-20 20:30:07683}
684
[email protected]ad6d2c42009-09-15 20:13:38685#endif // !CHROMIUM_SELINUX
[email protected]a5d7bb82009-09-08 22:30:58686
[email protected]ad6d2c42009-09-15 20:13:38687// This function triggers the static and lazy construction of objects that need
688// to be created before imposing the sandbox.
689static void PreSandboxInit() {
[email protected]b8419412010-03-29 20:18:29690 base::RandUint64();
[email protected]4378a822009-07-08 01:15:14691
[email protected]b8419412010-03-29 20:18:29692 base::SysInfo::MaxSharedMemorySize();
[email protected]80a086c52009-08-04 17:52:04693
[email protected]b8419412010-03-29 20:18:29694 // ICU DateFormat class (used in base/time_format.cc) needs to get the
695 // Olson timezone ID by accessing the zoneinfo files on disk. After
696 // TimeZone::createDefault is called once here, the timezone ID is
697 // cached and there's no more need to access the file system.
698 scoped_ptr<icu::TimeZone> zone(icu::TimeZone::createDefault());
[email protected]1831acf2009-10-05 16:38:41699
[email protected]eeb08552011-03-18 11:15:39700#if defined(USE_NSS)
[email protected]f6a67b42011-03-17 23:49:21701 // NSS libraries are loaded before sandbox is activated. This is to allow
702 // successful initialization of NSS which tries to load extra library files.
[email protected]4b559b4d2011-04-14 17:37:14703 crypto::LoadNSSLibraries();
[email protected]1f5548452011-10-06 06:46:15704#elif defined(USE_OPENSSL)
705 // OpenSSL is intentionally not supported in the sandboxed processes, see
706 // http://crbug.com/99163. If that ever changes we'll likely need to init
707 // OpenSSL here (at least, load the library and error strings).
[email protected]eeb08552011-03-18 11:15:39708#else
[email protected]1f5548452011-10-06 06:46:15709 // It's possible that another hypothetical crypto stack would not require
710 // pre-sandbox init, but more likely this is just a build configuration error.
711 #error Which SSL library are you using?
[email protected]f6a67b42011-03-17 23:49:21712#endif
[email protected]ed450f32011-03-16 01:26:49713
[email protected]17773042010-07-28 17:35:07714 // Ensure access to the Pepper plugins before the sandbox is turned on.
715 PepperPluginRegistry::PreloadModules();
[email protected]ad6d2c42009-09-15 20:13:38716}
717
718#if !defined(CHROMIUM_SELINUX)
719static bool EnterSandbox() {
[email protected]b8419412010-03-29 20:18:29720 // The SUID sandbox sets this environment variable to a file descriptor
721 // over which we can signal that we have completed our startup and can be
722 // chrooted.
[email protected]ad6d2c42009-09-15 20:13:38723 const char* const sandbox_fd_string = getenv("SBX_D");
[email protected]ad6d2c42009-09-15 20:13:38724
[email protected]0dc32322010-09-16 09:46:59725 if (sandbox_fd_string) {
726 // Use the SUID sandbox. This still allows the seccomp sandbox to
727 // be enabled by the process later.
[email protected]8ecd3aad2009-11-04 08:32:22728 g_suid_sandbox_active = true;
729
[email protected]ad6d2c42009-09-15 20:13:38730 char* endptr;
731 const long fd_long = strtol(sandbox_fd_string, &endptr, 10);
732 if (!*sandbox_fd_string || *endptr || fd_long < 0 || fd_long > INT_MAX)
733 return false;
734 const int fd = fd_long;
735
736 PreSandboxInit();
[email protected]c9e45da02009-08-05 17:35:08737
[email protected]eaebefaf2010-02-23 22:58:18738 static const char kMsgChrootMe = 'C';
739 static const char kMsgChrootSuccessful = 'O';
[email protected]abe3ad92009-06-15 18:15:08740
[email protected]eaebefaf2010-02-23 22:58:18741 if (HANDLE_EINTR(write(fd, &kMsgChrootMe, 1)) != 1) {
[email protected]0e1611122009-07-10 18:17:32742 LOG(ERROR) << "Failed to write to chroot pipe: " << errno;
[email protected]abe3ad92009-06-15 18:15:08743 return false;
[email protected]0e1611122009-07-10 18:17:32744 }
[email protected]abe3ad92009-06-15 18:15:08745
[email protected]87ed6952009-07-16 02:52:15746 // We need to reap the chroot helper process in any event:
747 wait(NULL);
748
[email protected]abe3ad92009-06-15 18:15:08749 char reply;
[email protected]87f8ce62009-07-10 19:14:31750 if (HANDLE_EINTR(read(fd, &reply, 1)) != 1) {
[email protected]0e1611122009-07-10 18:17:32751 LOG(ERROR) << "Failed to read from chroot pipe: " << errno;
[email protected]abe3ad92009-06-15 18:15:08752 return false;
[email protected]0e1611122009-07-10 18:17:32753 }
[email protected]87f8ce62009-07-10 19:14:31754
[email protected]eaebefaf2010-02-23 22:58:18755 if (reply != kMsgChrootSuccessful) {
[email protected]0e1611122009-07-10 18:17:32756 LOG(ERROR) << "Error code reply from chroot helper";
[email protected]abe3ad92009-06-15 18:15:08757 return false;
[email protected]0e1611122009-07-10 18:17:32758 }
[email protected]abe3ad92009-06-15 18:15:08759
[email protected]cf3ac3972010-12-22 20:02:29760 SkiaFontConfigSetImplementation(
761 new FontConfigIPC(kMagicSandboxIPCDescriptor));
[email protected]abe3ad92009-06-15 18:15:08762
[email protected]e60c0232011-11-11 19:56:35763#if !defined(OS_OPENBSD)
[email protected]415493be2009-07-10 17:50:24764 // Previously, we required that the binary be non-readable. This causes the
765 // kernel to mark the process as non-dumpable at startup. The thinking was
766 // that, although we were putting the renderers into a PID namespace (with
767 // the SUID sandbox), they would nonetheless be in the /same/ PID
768 // namespace. So they could ptrace each other unless they were non-dumpable.
769 //
770 // If the binary was readable, then there would be a window between process
771 // startup and the point where we set the non-dumpable flag in which a
772 // compromised renderer could ptrace attach.
773 //
774 // However, now that we have a zygote model, only the (trusted) zygote
775 // exists at this point and we can set the non-dumpable flag which is
776 // inherited by all our renderer children.
[email protected]4730db92009-07-22 00:40:48777 //
778 // Note: a non-dumpable process can't be debugged. To debug sandbox-related
779 // issues, one can specify --allow-sandbox-debugging to let the process be
780 // dumpable.
781 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
782 if (!command_line.HasSwitch(switches::kAllowSandboxDebugging)) {
783 prctl(PR_SET_DUMPABLE, 0, 0, 0, 0);
784 if (prctl(PR_GET_DUMPABLE, 0, 0, 0, 0)) {
785 LOG(ERROR) << "Failed to set non-dumpable flag";
786 return false;
787 }
[email protected]0e1611122009-07-10 18:17:32788 }
[email protected]e60c0232011-11-11 19:56:35789#endif
[email protected]2bc039a2011-07-29 23:05:41790#if defined(SECCOMP_SANDBOX)
[email protected]65f607f2011-08-03 21:08:12791 } else if (SeccompSandboxEnabled()) {
[email protected]0dc32322010-09-16 09:46:59792 PreSandboxInit();
[email protected]cf3ac3972010-12-22 20:02:29793 SkiaFontConfigSetImplementation(
794 new FontConfigIPC(kMagicSandboxIPCDescriptor));
[email protected]2bc039a2011-07-29 23:05:41795#endif
[email protected]abe3ad92009-06-15 18:15:08796 } else {
797 SkiaFontConfigUseDirectImplementation();
798 }
799
800 return true;
801}
[email protected]ad6d2c42009-09-15 20:13:38802#else // CHROMIUM_SELINUX
803
804static bool EnterSandbox() {
805 PreSandboxInit();
806 SkiaFontConfigUseIPCImplementation(kMagicSandboxIPCDescriptor);
[email protected]ad6d2c42009-09-15 20:13:38807 return true;
808}
809
810#endif // CHROMIUM_SELINUX
[email protected]abe3ad92009-06-15 18:15:08811
[email protected]4573fbd2011-10-31 20:25:18812bool ZygoteMain(const content::MainFunctionParams& params,
[email protected]f8ba13d2011-10-25 16:08:52813 content::ZygoteForkDelegate* forkdelegate) {
[email protected]ad6d2c42009-09-15 20:13:38814#if !defined(CHROMIUM_SELINUX)
[email protected]a0f200ea2009-08-06 18:44:06815 g_am_zygote_or_renderer = true;
[email protected]ad6d2c42009-09-15 20:13:38816#endif
[email protected]a0f200ea2009-08-06 18:44:06817
[email protected]36ea6c6f2010-03-17 20:08:01818#if defined(SECCOMP_SANDBOX)
[email protected]65f607f2011-08-03 21:08:12819 if (SeccompSandboxEnabled()) {
[email protected]2bc039a2011-07-29 23:05:41820 // The seccomp sandbox needs access to files in /proc, which might be denied
821 // after one of the other sandboxes have been started. So, obtain a suitable
822 // file handle in advance.
[email protected]a9c54a172009-11-07 06:09:38823 g_proc_fd = open("/proc", O_DIRECTORY | O_RDONLY);
824 if (g_proc_fd < 0) {
825 LOG(ERROR) << "WARNING! Cannot access \"/proc\". Disabling seccomp "
[email protected]2bc039a2011-07-29 23:05:41826 "sandboxing.";
[email protected]a9c54a172009-11-07 06:09:38827 }
828 }
[email protected]36ea6c6f2010-03-17 20:08:01829#endif // SECCOMP_SANDBOX
[email protected]a9c54a172009-11-07 06:09:38830
[email protected]ce2ae442011-07-18 16:13:41831 if (forkdelegate != NULL) {
832 VLOG(1) << "ZygoteMain: initializing fork delegate";
833 forkdelegate->Init(getenv("SBX_D") != NULL, // g_suid_sandbox_active,
834 kBrowserDescriptor,
835 kMagicSandboxIPCDescriptor);
836 } else {
837 VLOG(1) << "ZygoteMain: fork delegate is NULL";
838 }
839
[email protected]a9c54a172009-11-07 06:09:38840 // Turn on the SELinux or SUID sandbox
841 if (!EnterSandbox()) {
842 LOG(FATAL) << "Failed to enter sandbox. Fail safe abort. (errno: "
843 << errno << ")";
844 return false;
845 }
846
[email protected]715b4f262010-07-13 14:17:28847 int sandbox_flags = 0;
848 if (getenv("SBX_D"))
849 sandbox_flags |= ZygoteHost::kSandboxSUID;
850 if (getenv("SBX_PID_NS"))
851 sandbox_flags |= ZygoteHost::kSandboxPIDNS;
852 if (getenv("SBX_NET_NS"))
853 sandbox_flags |= ZygoteHost::kSandboxNetNS;
854
[email protected]36ea6c6f2010-03-17 20:08:01855#if defined(SECCOMP_SANDBOX)
[email protected]a9c54a172009-11-07 06:09:38856 // The seccomp sandbox will be turned on when the renderers start. But we can
857 // already check if sufficient support is available so that we only need to
858 // print one error message for the entire browser session.
[email protected]65f607f2011-08-03 21:08:12859 if (g_proc_fd >= 0 && SeccompSandboxEnabled()) {
[email protected]a9c54a172009-11-07 06:09:38860 if (!SupportsSeccompSandbox(g_proc_fd)) {
[email protected]e8c916a2009-11-04 17:52:47861 // There are a good number of users who cannot use the seccomp sandbox
862 // (e.g. because their distribution does not enable seccomp mode by
863 // default). While we would prefer to deny execution in this case, it
864 // seems more realistic to continue in degraded mode.
[email protected]1b5d28f2010-02-18 15:53:36865 LOG(ERROR) << "WARNING! This machine lacks support needed for the "
866 "Seccomp sandbox. Running renderers with Seccomp "
867 "sandboxing disabled.";
[email protected]e8c916a2009-11-04 17:52:47868 } else {
[email protected]0b4610a92011-08-04 18:08:09869 VLOG(1) << "Enabling experimental Seccomp sandbox.";
[email protected]715b4f262010-07-13 14:17:28870 sandbox_flags |= ZygoteHost::kSandboxSeccomp;
[email protected]e8c916a2009-11-04 17:52:47871 }
872 }
[email protected]36ea6c6f2010-03-17 20:08:01873#endif // SECCOMP_SANDBOX
[email protected]e8c916a2009-11-04 17:52:47874
[email protected]ce2ae442011-07-18 16:13:41875 Zygote zygote(sandbox_flags, forkdelegate);
[email protected]c548be22010-03-08 12:55:57876 // This function call can return multiple times, once per fork().
[email protected]cc8f1462009-06-12 17:36:55877 return zygote.ProcessRequests();
878}