blob: 973eccbdee79db7f18fa0a0cca16c35b9067cce6 [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]415c2cd2011-03-11 21:56:1133#include "content/common/main_function_params.h"
[email protected]cebc3dc2011-04-18 17:15:0034#include "content/common/pepper_plugin_registry.h"
[email protected]4dd57932011-03-17 06:06:1235#include "content/common/process_watcher.h"
[email protected]4dd57932011-03-17 06:06:1236#include "content/common/sandbox_methods_linux.h"
[email protected]65f607f2011-08-03 21:08:1237#include "content/common/seccomp_sandbox.h"
[email protected]4dd57932011-03-17 06:06:1238#include "content/common/set_process_title.h"
[email protected]797c3552011-03-17 00:26:1839#include "content/common/unix_domain_socket_posix.h"
[email protected]ce2ae442011-07-18 16:13:4140#include "content/common/zygote_fork_delegate_linux.h"
[email protected]c08950d22011-10-13 22:20:2941#include "content/public/common/content_switches.h"
[email protected]b39ef1cb2011-10-25 04:46:5542#include "content/public/common/result_codes.h"
[email protected]cf3ac3972010-12-22 20:02:2943#include "skia/ext/SkFontHost_fontconfig_control.h"
[email protected]1831acf2009-10-05 16:38:4144#include "unicode/timezone.h"
[email protected]e1d67a882011-08-31 21:11:0445#include "ipc/ipc_channel.h"
[email protected]ce2ae442011-07-18 16:13:4146#include "ipc/ipc_switches.h"
[email protected]1831acf2009-10-05 16:38:4147
[email protected]e63c4d72011-05-31 22:38:2948#if defined(OS_LINUX)
49#include <sys/epoll.h>
50#include <sys/prctl.h>
51#include <sys/signal.h>
52#else
53#include <signal.h>
54#endif
55
56#if defined(CHROMIUM_SELINUX)
57#include <selinux/selinux.h>
58#include <selinux/context.h>
59#endif
60
[email protected]cc8f1462009-06-12 17:36:5561// http://code.google.com/p/chromium/wiki/LinuxZygote
62
[email protected]8ecd3aad2009-11-04 08:32:2263static const int kBrowserDescriptor = 3;
[email protected]73fa63992009-07-20 20:30:0764static const int kMagicSandboxIPCDescriptor = 5;
[email protected]8ecd3aad2009-11-04 08:32:2265static const int kZygoteIdDescriptor = 7;
66static bool g_suid_sandbox_active = false;
[email protected]2bc039a2011-07-29 23:05:4167
[email protected]2bc039a2011-07-29 23:05:4168#if defined(SECCOMP_SANDBOX)
[email protected]2bc039a2011-07-29 23:05:4169static int g_proc_fd = -1;
[email protected]65f607f2011-08-03 21:08:1270#endif
[email protected]2bc039a2011-07-29 23:05:4171
[email protected]a89a55dd2010-04-19 14:51:1372#if defined(CHROMIUM_SELINUX)
73static void SELinuxTransitionToTypeOrDie(const char* type) {
74 security_context_t security_context;
75 if (getcon(&security_context))
76 LOG(FATAL) << "Cannot get SELinux context";
77
78 context_t context = context_new(security_context);
79 context_type_set(context, type);
80 const int r = setcon(context_str(context));
81 context_free(context);
82 freecon(security_context);
83
84 if (r) {
85 LOG(FATAL) << "dynamic transition to type '" << type << "' failed. "
86 "(this binary has been built with SELinux support, but maybe "
87 "the policies haven't been loaded into the kernel?)";
88 }
89}
90#endif // CHROMIUM_SELINUX
91
[email protected]cc8f1462009-06-12 17:36:5592// This is the object which implements the zygote. The ZygoteMain function,
[email protected]61883442010-07-12 15:14:3493// which is called from ChromeMain, simply constructs one of these objects and
94// runs it.
[email protected]cc8f1462009-06-12 17:36:5595class Zygote {
96 public:
[email protected]e7e38032011-07-26 17:25:2597 Zygote(int sandbox_flags, ZygoteForkDelegate* helper)
98 : sandbox_flags_(sandbox_flags), helper_(helper) {
[email protected]8d5d7612011-10-20 18:23:1499 if (helper_)
100 helper_->InitialUMA(&initial_uma_name_,
101 &initial_uma_sample_,
102 &initial_uma_boundary_value_);
[email protected]715b4f262010-07-13 14:17:28103 }
104
[email protected]cc8f1462009-06-12 17:36:55105 bool ProcessRequests() {
106 // A SOCK_SEQPACKET socket is installed in fd 3. We get commands from the
107 // browser on it.
[email protected]8ecd3aad2009-11-04 08:32:22108 // A SOCK_DGRAM is installed in fd 5. This is the sandbox IPC channel.
[email protected]abe3ad92009-06-15 18:15:08109 // See http://code.google.com/p/chromium/wiki/LinuxSandboxIPC
[email protected]cc8f1462009-06-12 17:36:55110
111 // We need to accept SIGCHLD, even though our handler is a no-op because
112 // otherwise we cannot wait on children. (According to POSIX 2001.)
113 struct sigaction action;
114 memset(&action, 0, sizeof(action));
115 action.sa_handler = SIGCHLDHandler;
116 CHECK(sigaction(SIGCHLD, &action, NULL) == 0);
117
[email protected]8ecd3aad2009-11-04 08:32:22118 if (g_suid_sandbox_active) {
119 // Let the ZygoteHost know we are ready to go.
[email protected]8a282712011-08-23 19:28:00120 // The receiving code is in content/browser/zygote_host_linux.cc.
[email protected]8ecd3aad2009-11-04 08:32:22121 std::vector<int> empty;
[email protected]cf3ac3972010-12-22 20:02:29122 bool r = UnixDomainSocket::SendMsg(kBrowserDescriptor, kZygoteMagic,
123 sizeof(kZygoteMagic), empty);
[email protected]bfc672a52011-07-20 07:51:27124#if defined(OS_CHROMEOS)
125 LOG_IF(WARNING, r) << "Sending zygote magic failed";
126 // Exit normally on chromeos because session manager may send SIGTERM
127 // right after the process starts and it may fail to send zygote magic
128 // number to browser process.
[email protected]a45f1832011-07-20 18:01:15129 if (!r)
130 _exit(content::RESULT_CODE_NORMAL_EXIT);
[email protected]bfc672a52011-07-20 07:51:27131#else
[email protected]8ecd3aad2009-11-04 08:32:22132 CHECK(r) << "Sending zygote magic failed";
[email protected]bfc672a52011-07-20 07:51:27133#endif
[email protected]8ecd3aad2009-11-04 08:32:22134 }
135
[email protected]cc8f1462009-06-12 17:36:55136 for (;;) {
[email protected]c548be22010-03-08 12:55:57137 // This function call can return multiple times, once per fork().
[email protected]8ecd3aad2009-11-04 08:32:22138 if (HandleRequestFromBrowser(kBrowserDescriptor))
[email protected]cc8f1462009-06-12 17:36:55139 return true;
140 }
141 }
142
143 private:
144 // See comment below, where sigaction is called.
145 static void SIGCHLDHandler(int signal) { }
146
147 // ---------------------------------------------------------------------------
148 // Requests from the browser...
149
150 // Read and process a request from the browser. Returns true if we are in a
151 // new process and thus need to unwind back into ChromeMain.
152 bool HandleRequestFromBrowser(int fd) {
153 std::vector<int> fds;
[email protected]2752bf62011-03-23 21:06:06154 static const unsigned kMaxMessageLength = 2048;
[email protected]cc8f1462009-06-12 17:36:55155 char buf[kMaxMessageLength];
[email protected]cf3ac3972010-12-22 20:02:29156 const ssize_t len = UnixDomainSocket::RecvMsg(fd, buf, sizeof(buf), &fds);
[email protected]7ae27b92010-09-24 17:33:36157
158 if (len == 0 || (len == -1 && errno == ECONNRESET)) {
159 // EOF from the browser. We should die.
160 _exit(0);
[email protected]cc8f1462009-06-12 17:36:55161 return false;
162 }
163
[email protected]7ae27b92010-09-24 17:33:36164 if (len == -1) {
165 PLOG(ERROR) << "Error reading message from browser";
[email protected]cc8f1462009-06-12 17:36:55166 return false;
167 }
168
169 Pickle pickle(buf, len);
170 void* iter = NULL;
171
172 int kind;
[email protected]57113ea2009-06-18 02:23:16173 if (pickle.ReadInt(&iter, &kind)) {
174 switch (kind) {
175 case ZygoteHost::kCmdFork:
[email protected]c548be22010-03-08 12:55:57176 // This function call can return multiple times, once per fork().
[email protected]57113ea2009-06-18 02:23:16177 return HandleForkRequest(fd, pickle, iter, fds);
[email protected]ce2ae442011-07-18 16:13:41178
[email protected]57113ea2009-06-18 02:23:16179 case ZygoteHost::kCmdReap:
180 if (!fds.empty())
181 break;
[email protected]c548be22010-03-08 12:55:57182 HandleReapRequest(fd, pickle, iter);
183 return false;
[email protected]443b80e2010-12-14 00:42:23184 case ZygoteHost::kCmdGetTerminationStatus:
[email protected]57113ea2009-06-18 02:23:16185 if (!fds.empty())
186 break;
[email protected]443b80e2010-12-14 00:42:23187 HandleGetTerminationStatus(fd, pickle, iter);
[email protected]c548be22010-03-08 12:55:57188 return false;
[email protected]715b4f262010-07-13 14:17:28189 case ZygoteHost::kCmdGetSandboxStatus:
190 HandleGetSandboxStatus(fd, pickle, iter);
191 return false;
[email protected]57113ea2009-06-18 02:23:16192 default:
193 NOTREACHED();
194 break;
195 }
[email protected]cc8f1462009-06-12 17:36:55196 }
197
[email protected]cc8f1462009-06-12 17:36:55198 LOG(WARNING) << "Error parsing message from browser";
199 for (std::vector<int>::const_iterator
200 i = fds.begin(); i != fds.end(); ++i)
201 close(*i);
202 return false;
203 }
204
[email protected]c548be22010-03-08 12:55:57205 void HandleReapRequest(int fd, const Pickle& pickle, void* iter) {
[email protected]8ecd3aad2009-11-04 08:32:22206 base::ProcessId child;
207 base::ProcessId actual_child;
[email protected]cc8f1462009-06-12 17:36:55208
209 if (!pickle.ReadInt(&iter, &child)) {
210 LOG(WARNING) << "Error parsing reap request from browser";
[email protected]c548be22010-03-08 12:55:57211 return;
[email protected]cc8f1462009-06-12 17:36:55212 }
213
[email protected]8ecd3aad2009-11-04 08:32:22214 if (g_suid_sandbox_active) {
215 actual_child = real_pids_to_sandbox_pids[child];
216 if (!actual_child)
[email protected]c548be22010-03-08 12:55:57217 return;
[email protected]8ecd3aad2009-11-04 08:32:22218 real_pids_to_sandbox_pids.erase(child);
219 } else {
220 actual_child = child;
221 }
222
223 ProcessWatcher::EnsureProcessTerminated(actual_child);
[email protected]cc8f1462009-06-12 17:36:55224 }
225
[email protected]443b80e2010-12-14 00:42:23226 void HandleGetTerminationStatus(int fd, const Pickle& pickle, void* iter) {
[email protected]57113ea2009-06-18 02:23:16227 base::ProcessHandle child;
228
229 if (!pickle.ReadInt(&iter, &child)) {
[email protected]443b80e2010-12-14 00:42:23230 LOG(WARNING) << "Error parsing GetTerminationStatus request "
231 << "from browser";
[email protected]c548be22010-03-08 12:55:57232 return;
[email protected]57113ea2009-06-18 02:23:16233 }
234
[email protected]443b80e2010-12-14 00:42:23235 base::TerminationStatus status;
236 int exit_code;
[email protected]8ecd3aad2009-11-04 08:32:22237 if (g_suid_sandbox_active)
238 child = real_pids_to_sandbox_pids[child];
[email protected]443b80e2010-12-14 00:42:23239 if (child) {
240 status = base::GetTerminationStatus(child, &exit_code);
241 } else {
242 // Assume that if we can't find the child in the sandbox, then
243 // it terminated normally.
244 status = base::TERMINATION_STATUS_NORMAL_TERMINATION;
[email protected]1fcfb202011-07-19 19:53:14245 exit_code = content::RESULT_CODE_NORMAL_EXIT;
[email protected]443b80e2010-12-14 00:42:23246 }
[email protected]57113ea2009-06-18 02:23:16247
248 Pickle write_pickle;
[email protected]443b80e2010-12-14 00:42:23249 write_pickle.WriteInt(static_cast<int>(status));
250 write_pickle.WriteInt(exit_code);
[email protected]8a861402011-01-28 19:59:11251 ssize_t written =
252 HANDLE_EINTR(write(fd, write_pickle.data(), write_pickle.size()));
253 if (written != static_cast<ssize_t>(write_pickle.size()))
[email protected]19cb9292010-04-16 23:00:15254 PLOG(ERROR) << "write";
[email protected]57113ea2009-06-18 02:23:16255 }
256
[email protected]28ecba32010-09-16 10:03:09257 // This is equivalent to fork(), except that, when using the SUID
258 // sandbox, it returns the real PID of the child process as it
259 // appears outside the sandbox, rather than returning the PID inside
[email protected]8d5d7612011-10-20 18:23:14260 // the sandbox. Optionally, it fills in uma_name et al with a report
261 // the helper wants to make via UMA_HISTOGRAM_ENUMERATION.
[email protected]ce2ae442011-07-18 16:13:41262 int ForkWithRealPid(const std::string& process_type, std::vector<int>& fds,
[email protected]8d5d7612011-10-20 18:23:14263 const std::string& channel_switch,
264 std::string* uma_name,
265 int* uma_sample, int* uma_boundary_value) {
266 const bool use_helper = (helper_ && helper_->CanHelp(process_type,
267 uma_name,
268 uma_sample,
269 uma_boundary_value));
[email protected]ce2ae442011-07-18 16:13:41270 if (!(use_helper || g_suid_sandbox_active)) {
[email protected]28ecba32010-09-16 10:03:09271 return fork();
[email protected]ce2ae442011-07-18 16:13:41272 }
[email protected]28ecba32010-09-16 10:03:09273
274 int dummy_fd;
275 ino_t dummy_inode;
276 int pipe_fds[2] = { -1, -1 };
[email protected]073040b2010-09-26 02:35:45277 base::ProcessId pid = 0;
[email protected]28ecba32010-09-16 10:03:09278
279 dummy_fd = socket(PF_UNIX, SOCK_DGRAM, 0);
280 if (dummy_fd < 0) {
281 LOG(ERROR) << "Failed to create dummy FD";
282 goto error;
283 }
284 if (!base::FileDescriptorGetInode(&dummy_inode, dummy_fd)) {
285 LOG(ERROR) << "Failed to get inode for dummy FD";
286 goto error;
287 }
288 if (pipe(pipe_fds) != 0) {
289 LOG(ERROR) << "Failed to create pipe";
290 goto error;
291 }
292
[email protected]ce2ae442011-07-18 16:13:41293 if (use_helper) {
294 fds.push_back(dummy_fd);
295 fds.push_back(pipe_fds[0]);
296 pid = helper_->Fork(fds);
297 } else {
298 pid = fork();
299 }
[email protected]28ecba32010-09-16 10:03:09300 if (pid < 0) {
301 goto error;
302 } else if (pid == 0) {
303 // In the child process.
304 close(pipe_fds[1]);
[email protected]e1d67a882011-08-31 21:11:04305 base::ProcessId real_pid;
[email protected]28ecba32010-09-16 10:03:09306 // Wait until the parent process has discovered our PID. We
307 // should not fork any child processes (which the seccomp
308 // sandbox does) until then, because that can interfere with the
309 // parent's discovery of our PID.
[email protected]e1d67a882011-08-31 21:11:04310 if (!file_util::ReadFromFD(pipe_fds[0],
311 reinterpret_cast<char*>(&real_pid),
312 sizeof(real_pid))) {
[email protected]28ecba32010-09-16 10:03:09313 LOG(FATAL) << "Failed to synchronise with parent zygote process";
314 }
[email protected]e1d67a882011-08-31 21:11:04315 if (real_pid <= 0) {
316 LOG(FATAL) << "Invalid pid from parent zygote";
317 }
318#if defined(OS_LINUX)
319 // Sandboxed processes need to send the global, non-namespaced PID when
320 // setting up an IPC channel to their parent.
321 IPC::Channel::SetGlobalPid(real_pid);
322#endif
[email protected]28ecba32010-09-16 10:03:09323 close(pipe_fds[0]);
324 close(dummy_fd);
325 return 0;
326 } else {
327 // In the parent process.
328 close(dummy_fd);
329 dummy_fd = -1;
330 close(pipe_fds[0]);
331 pipe_fds[0] = -1;
[email protected]4229b5d2011-07-16 02:47:37332 base::ProcessId real_pid;
[email protected]ce2ae442011-07-18 16:13:41333 if (g_suid_sandbox_active) {
334 uint8_t reply_buf[512];
335 Pickle request;
336 request.WriteInt(LinuxSandbox::METHOD_GET_CHILD_WITH_INODE);
337 request.WriteUInt64(dummy_inode);
338
339 const ssize_t r = UnixDomainSocket::SendRecvMsg(
340 kMagicSandboxIPCDescriptor, reply_buf, sizeof(reply_buf), NULL,
341 request);
342 if (r == -1) {
343 LOG(ERROR) << "Failed to get child process's real PID";
344 goto error;
345 }
346
347 Pickle reply(reinterpret_cast<char*>(reply_buf), r);
348 void* iter = NULL;
349 if (!reply.ReadInt(&iter, &real_pid))
350 goto error;
351 if (real_pid <= 0) {
352 // METHOD_GET_CHILD_WITH_INODE failed. Did the child die already?
353 LOG(ERROR) << "METHOD_GET_CHILD_WITH_INODE failed";
354 goto error;
355 }
356 real_pids_to_sandbox_pids[real_pid] = pid;
[email protected]4229b5d2011-07-16 02:47:37357 }
[email protected]ce2ae442011-07-18 16:13:41358 if (use_helper) {
359 real_pid = pid;
360 if (!helper_->AckChild(pipe_fds[1], channel_switch)) {
361 LOG(ERROR) << "Failed to synchronise with zygote fork helper";
362 goto error;
363 }
364 } else {
[email protected]e1d67a882011-08-31 21:11:04365 int written =
366 HANDLE_EINTR(write(pipe_fds[1], &real_pid, sizeof(real_pid)));
367 if (written != sizeof(real_pid)) {
[email protected]ce2ae442011-07-18 16:13:41368 LOG(ERROR) << "Failed to synchronise with child process";
369 goto error;
370 }
[email protected]28ecba32010-09-16 10:03:09371 }
372 close(pipe_fds[1]);
373 return real_pid;
374 }
375
376 error:
[email protected]72f891f42011-01-12 17:00:52377 if (pid > 0) {
378 if (waitpid(pid, NULL, WNOHANG) == -1)
379 LOG(ERROR) << "Failed to wait for process";
380 }
[email protected]28ecba32010-09-16 10:03:09381 if (dummy_fd >= 0)
382 close(dummy_fd);
383 if (pipe_fds[0] >= 0)
384 close(pipe_fds[0]);
385 if (pipe_fds[1] >= 0)
386 close(pipe_fds[1]);
387 return -1;
388 }
389
[email protected]35d86242011-09-30 15:29:08390 // Unpacks process type and arguments from |pickle| and forks a new process.
391 // Returns -1 on error, otherwise returns twice, returning 0 to the child
392 // process and the child process ID to the parent process, like fork().
393 base::ProcessId ReadArgsAndFork(const Pickle& pickle,
394 void* iter,
[email protected]8d5d7612011-10-20 18:23:14395 std::vector<int>& fds,
396 std::string* uma_name,
397 int* uma_sample,
398 int* uma_boundary_value) {
[email protected]cc8f1462009-06-12 17:36:55399 std::vector<std::string> args;
[email protected]35d86242011-09-30 15:29:08400 int argc = 0;
401 int numfds = 0;
[email protected]cc8f1462009-06-12 17:36:55402 base::GlobalDescriptors::Mapping mapping;
[email protected]ce2ae442011-07-18 16:13:41403 std::string process_type;
404 std::string channel_id;
405 const std::string channel_id_prefix = std::string("--")
406 + switches::kProcessChannelID + std::string("=");
407
408 if (!pickle.ReadString(&iter, &process_type))
[email protected]35d86242011-09-30 15:29:08409 return -1;
[email protected]cc8f1462009-06-12 17:36:55410 if (!pickle.ReadInt(&iter, &argc))
[email protected]35d86242011-09-30 15:29:08411 return -1;
[email protected]cc8f1462009-06-12 17:36:55412
413 for (int i = 0; i < argc; ++i) {
414 std::string arg;
415 if (!pickle.ReadString(&iter, &arg))
[email protected]35d86242011-09-30 15:29:08416 return -1;
[email protected]cc8f1462009-06-12 17:36:55417 args.push_back(arg);
[email protected]ce2ae442011-07-18 16:13:41418 if (arg.compare(0, channel_id_prefix.length(), channel_id_prefix) == 0)
419 channel_id = arg;
[email protected]cc8f1462009-06-12 17:36:55420 }
421
422 if (!pickle.ReadInt(&iter, &numfds))
[email protected]35d86242011-09-30 15:29:08423 return -1;
[email protected]cc8f1462009-06-12 17:36:55424 if (numfds != static_cast<int>(fds.size()))
[email protected]35d86242011-09-30 15:29:08425 return -1;
[email protected]cc8f1462009-06-12 17:36:55426
427 for (int i = 0; i < numfds; ++i) {
428 base::GlobalDescriptors::Key key;
429 if (!pickle.ReadUInt32(&iter, &key))
[email protected]35d86242011-09-30 15:29:08430 return -1;
[email protected]cc8f1462009-06-12 17:36:55431 mapping.push_back(std::make_pair(key, fds[i]));
432 }
433
[email protected]abe3ad92009-06-15 18:15:08434 mapping.push_back(std::make_pair(
[email protected]8ecd3aad2009-11-04 08:32:22435 static_cast<uint32_t>(kSandboxIPCChannel), kMagicSandboxIPCDescriptor));
436
[email protected]35d86242011-09-30 15:29:08437 // Returns twice, once per process.
[email protected]8d5d7612011-10-20 18:23:14438 base::ProcessId child_pid = ForkWithRealPid(process_type, fds, channel_id,
439 uma_name, uma_sample,
440 uma_boundary_value);
[email protected]35d86242011-09-30 15:29:08441 if (!child_pid) {
442 // This is the child process.
[email protected]36ea6c6f2010-03-17 20:08:01443#if defined(SECCOMP_SANDBOX)
[email protected]65f607f2011-08-03 21:08:12444 if (SeccompSandboxEnabled() && g_proc_fd >= 0) {
[email protected]2bc039a2011-07-29 23:05:41445 // Try to open /proc/self/maps as the seccomp sandbox needs access to it
[email protected]a9c54a172009-11-07 06:09:38446 int proc_self_maps = openat(g_proc_fd, "self/maps", O_RDONLY);
447 if (proc_self_maps >= 0) {
448 SeccompSandboxSetProcSelfMaps(proc_self_maps);
[email protected]2bc039a2011-07-29 23:05:41449 } else {
450 PLOG(ERROR) << "openat(/proc/self/maps)";
[email protected]a9c54a172009-11-07 06:09:38451 }
452 close(g_proc_fd);
453 g_proc_fd = -1;
454 }
[email protected]8015de32009-11-18 04:13:33455#endif
[email protected]a9c54a172009-11-07 06:09:38456
[email protected]8ecd3aad2009-11-04 08:32:22457 close(kBrowserDescriptor); // our socket from the browser
[email protected]cbcf9cc32010-02-17 04:05:59458 if (g_suid_sandbox_active)
459 close(kZygoteIdDescriptor); // another socket from the browser
[email protected]9b85081af2010-12-07 21:26:47460 base::GlobalDescriptors::GetInstance()->Reset(mapping);
[email protected]0189bbd2009-10-12 22:50:39461
[email protected]a89a55dd2010-04-19 14:51:13462#if defined(CHROMIUM_SELINUX)
463 SELinuxTransitionToTypeOrDie("chromium_renderer_t");
464#endif
465
[email protected]0189bbd2009-10-12 22:50:39466 // Reset the process-wide command line to our new command line.
[email protected]cc8f1462009-06-12 17:36:55467 CommandLine::Reset();
[email protected]0189bbd2009-10-12 22:50:39468 CommandLine::Init(0, NULL);
469 CommandLine::ForCurrentProcess()->InitFromArgv(args);
[email protected]74e9fa22010-12-29 21:06:43470
471 // Update the process title. The argv was already cached by the call to
472 // SetProcessTitleFromCommandLine in ChromeMain, so we can pass NULL here
473 // (we don't have the original argv at this point).
474 SetProcessTitleFromCommandLine(NULL);
[email protected]35d86242011-09-30 15:29:08475 } else if (child_pid < 0) {
476 LOG(ERROR) << "Zygote could not fork: process_type " << process_type
477 << " numfds " << numfds << " child_pid " << child_pid;
[email protected]cc8f1462009-06-12 17:36:55478 }
[email protected]35d86242011-09-30 15:29:08479 return child_pid;
480 }
[email protected]cc8f1462009-06-12 17:36:55481
[email protected]35d86242011-09-30 15:29:08482 // Handle a 'fork' request from the browser: this means that the browser
483 // wishes to start a new renderer. Returns true if we are in a new process,
484 // otherwise writes the child_pid back to the browser via |fd|. Writes a
485 // child_pid of -1 on error.
486 bool HandleForkRequest(int fd, const Pickle& pickle,
487 void* iter, std::vector<int>& fds) {
[email protected]8d5d7612011-10-20 18:23:14488 std::string uma_name;
489 int uma_sample;
490 int uma_boundary_value;
491 base::ProcessId child_pid = ReadArgsAndFork(pickle, iter, fds,
492 &uma_name, &uma_sample,
493 &uma_boundary_value);
[email protected]35d86242011-09-30 15:29:08494 if (child_pid == 0)
495 return true;
[email protected]28ecba32010-09-16 10:03:09496 for (std::vector<int>::const_iterator
497 i = fds.begin(); i != fds.end(); ++i)
498 close(*i);
[email protected]8d5d7612011-10-20 18:23:14499 if (uma_name.empty()) {
500 // There is no UMA report from this particular fork.
501 // Use the initial UMA report if any, and clear that record for next time.
502 // Note the swap method here is the efficient way to do this, since
503 // we know uma_name is empty.
504 uma_name.swap(initial_uma_name_);
505 uma_sample = initial_uma_sample_;
506 uma_boundary_value = initial_uma_boundary_value_;
507 }
[email protected]35d86242011-09-30 15:29:08508 // Must always send reply, as ZygoteHost blocks while waiting for it.
[email protected]8d5d7612011-10-20 18:23:14509 Pickle reply_pickle;
510 reply_pickle.WriteInt(child_pid);
511 reply_pickle.WriteString(uma_name);
512 if (!uma_name.empty()) {
513 reply_pickle.WriteInt(uma_sample);
514 reply_pickle.WriteInt(uma_boundary_value);
515 }
516 if (HANDLE_EINTR(write(fd, reply_pickle.data(), reply_pickle.size())) !=
517 static_cast<ssize_t> (reply_pickle.size()))
[email protected]28ecba32010-09-16 10:03:09518 PLOG(ERROR) << "write";
519 return false;
[email protected]cc8f1462009-06-12 17:36:55520 }
[email protected]8ecd3aad2009-11-04 08:32:22521
[email protected]715b4f262010-07-13 14:17:28522 bool HandleGetSandboxStatus(int fd, const Pickle& pickle, void* iter) {
523 if (HANDLE_EINTR(write(fd, &sandbox_flags_, sizeof(sandbox_flags_)) !=
524 sizeof(sandbox_flags_))) {
525 PLOG(ERROR) << "write";
526 }
527
528 return false;
529 }
530
[email protected]8ecd3aad2009-11-04 08:32:22531 // In the SUID sandbox, we try to use a new PID namespace. Thus the PIDs
532 // fork() returns are not the real PIDs, so we need to map the Real PIDS
533 // into the sandbox PID namespace.
534 typedef base::hash_map<base::ProcessHandle, base::ProcessHandle> ProcessMap;
535 ProcessMap real_pids_to_sandbox_pids;
[email protected]715b4f262010-07-13 14:17:28536
537 const int sandbox_flags_;
[email protected]ce2ae442011-07-18 16:13:41538 ZygoteForkDelegate* helper_;
[email protected]8d5d7612011-10-20 18:23:14539
540 // These might be set by helper_->InitialUMA. They supply a UMA
541 // enumeration sample we should report on the first fork.
542 std::string initial_uma_name_;
543 int initial_uma_sample_;
544 int initial_uma_boundary_value_;
[email protected]cc8f1462009-06-12 17:36:55545};
546
[email protected]ad6d2c42009-09-15 20:13:38547// With SELinux we can carve out a precise sandbox, so we don't have to play
548// with intercepting libc calls.
549#if !defined(CHROMIUM_SELINUX)
550
[email protected]a0f200ea2009-08-06 18:44:06551static void ProxyLocaltimeCallToBrowser(time_t input, struct tm* output,
552 char* timezone_out,
553 size_t timezone_out_len) {
[email protected]73fa63992009-07-20 20:30:07554 Pickle request;
555 request.WriteInt(LinuxSandbox::METHOD_LOCALTIME);
556 request.WriteString(
557 std::string(reinterpret_cast<char*>(&input), sizeof(input)));
558
559 uint8_t reply_buf[512];
[email protected]cf3ac3972010-12-22 20:02:29560 const ssize_t r = UnixDomainSocket::SendRecvMsg(
[email protected]73fa63992009-07-20 20:30:07561 kMagicSandboxIPCDescriptor, reply_buf, sizeof(reply_buf), NULL, request);
562 if (r == -1) {
563 memset(output, 0, sizeof(struct tm));
564 return;
565 }
566
567 Pickle reply(reinterpret_cast<char*>(reply_buf), r);
568 void* iter = NULL;
[email protected]9debcda52009-07-22 20:06:51569 std::string result, timezone;
[email protected]73fa63992009-07-20 20:30:07570 if (!reply.ReadString(&iter, &result) ||
[email protected]9debcda52009-07-22 20:06:51571 !reply.ReadString(&iter, &timezone) ||
[email protected]73fa63992009-07-20 20:30:07572 result.size() != sizeof(struct tm)) {
573 memset(output, 0, sizeof(struct tm));
574 return;
575 }
576
577 memcpy(output, result.data(), sizeof(struct tm));
[email protected]9debcda52009-07-22 20:06:51578 if (timezone_out_len) {
579 const size_t copy_len = std::min(timezone_out_len - 1, timezone.size());
580 memcpy(timezone_out, timezone.data(), copy_len);
581 timezone_out[copy_len] = 0;
582 output->tm_zone = timezone_out;
583 } else {
584 output->tm_zone = NULL;
585 }
[email protected]73fa63992009-07-20 20:30:07586}
587
[email protected]a0f200ea2009-08-06 18:44:06588static bool g_am_zygote_or_renderer = false;
589
590// Sandbox interception of libc calls.
591//
592// Because we are running in a sandbox certain libc calls will fail (localtime
593// being the motivating example - it needs to read /etc/localtime). We need to
594// intercept these calls and proxy them to the browser. However, these calls
595// may come from us or from our libraries. In some cases we can't just change
596// our code.
597//
598// It's for these cases that we have the following setup:
599//
600// We define global functions for those functions which we wish to override.
601// Since we will be first in the dynamic resolution order, the dynamic linker
602// will point callers to our versions of these functions. However, we have the
603// same binary for both the browser and the renderers, which means that our
604// overrides will apply in the browser too.
605//
606// The global |g_am_zygote_or_renderer| is true iff we are in a zygote or
607// renderer process. It's set in ZygoteMain and inherited by the renderers when
608// they fork. (This means that it'll be incorrect for global constructor
609// functions and before ZygoteMain is called - beware).
610//
611// Our replacement functions can check this global and either proxy
612// the call to the browser over the sandbox IPC
613// (http://code.google.com/p/chromium/wiki/LinuxSandboxIPC) or they can use
614// dlsym with RTLD_NEXT to resolve the symbol, ignoring any symbols in the
615// current module.
616//
617// Other avenues:
618//
619// Our first attempt involved some assembly to patch the GOT of the current
620// module. This worked, but was platform specific and doesn't catch the case
621// where a library makes a call rather than current module.
622//
623// We also considered patching the function in place, but this would again by
624// platform specific and the above technique seems to work well enough.
625
[email protected]724df992010-09-21 18:19:10626typedef struct tm* (*LocaltimeFunction)(const time_t* timep);
627typedef struct tm* (*LocaltimeRFunction)(const time_t* timep,
628 struct tm* result);
629
630static pthread_once_t g_libc_localtime_funcs_guard = PTHREAD_ONCE_INIT;
631static LocaltimeFunction g_libc_localtime;
632static LocaltimeRFunction g_libc_localtime_r;
633
634static void InitLibcLocaltimeFunctions() {
635 g_libc_localtime = reinterpret_cast<LocaltimeFunction>(
636 dlsym(RTLD_NEXT, "localtime"));
637 g_libc_localtime_r = reinterpret_cast<LocaltimeRFunction>(
638 dlsym(RTLD_NEXT, "localtime_r"));
639
640 if (!g_libc_localtime || !g_libc_localtime_r) {
641 // http://code.google.com/p/chromium/issues/detail?id=16800
642 //
643 // Nvidia's libGL.so overrides dlsym for an unknown reason and replaces
644 // it with a version which doesn't work. In this case we'll get a NULL
645 // result. There's not a lot we can do at this point, so we just bodge it!
646 LOG(ERROR) << "Your system is broken: dlsym doesn't work! This has been "
647 "reported to be caused by Nvidia's libGL. You should expect"
648 " time related functions to misbehave. "
649 "http://code.google.com/p/chromium/issues/detail?id=16800";
650 }
651
652 if (!g_libc_localtime)
653 g_libc_localtime = gmtime;
654 if (!g_libc_localtime_r)
655 g_libc_localtime_r = gmtime_r;
656}
[email protected]a5d7bb82009-09-08 22:30:58657
[email protected]73fa63992009-07-20 20:30:07658struct tm* localtime(const time_t* timep) {
[email protected]a0f200ea2009-08-06 18:44:06659 if (g_am_zygote_or_renderer) {
660 static struct tm time_struct;
661 static char timezone_string[64];
662 ProxyLocaltimeCallToBrowser(*timep, &time_struct, timezone_string,
663 sizeof(timezone_string));
664 return &time_struct;
665 } else {
[email protected]724df992010-09-21 18:19:10666 CHECK_EQ(0, pthread_once(&g_libc_localtime_funcs_guard,
667 InitLibcLocaltimeFunctions));
668 return g_libc_localtime(timep);
[email protected]a0f200ea2009-08-06 18:44:06669 }
[email protected]73fa63992009-07-20 20:30:07670}
671
672struct tm* localtime_r(const time_t* timep, struct tm* result) {
[email protected]a0f200ea2009-08-06 18:44:06673 if (g_am_zygote_or_renderer) {
674 ProxyLocaltimeCallToBrowser(*timep, result, NULL, 0);
675 return result;
676 } else {
[email protected]724df992010-09-21 18:19:10677 CHECK_EQ(0, pthread_once(&g_libc_localtime_funcs_guard,
678 InitLibcLocaltimeFunctions));
679 return g_libc_localtime_r(timep, result);
[email protected]a0f200ea2009-08-06 18:44:06680 }
[email protected]73fa63992009-07-20 20:30:07681}
682
[email protected]ad6d2c42009-09-15 20:13:38683#endif // !CHROMIUM_SELINUX
[email protected]a5d7bb82009-09-08 22:30:58684
[email protected]ad6d2c42009-09-15 20:13:38685// This function triggers the static and lazy construction of objects that need
686// to be created before imposing the sandbox.
687static void PreSandboxInit() {
[email protected]b8419412010-03-29 20:18:29688 base::RandUint64();
[email protected]4378a822009-07-08 01:15:14689
[email protected]b8419412010-03-29 20:18:29690 base::SysInfo::MaxSharedMemorySize();
[email protected]80a086c52009-08-04 17:52:04691
[email protected]b8419412010-03-29 20:18:29692 // ICU DateFormat class (used in base/time_format.cc) needs to get the
693 // Olson timezone ID by accessing the zoneinfo files on disk. After
694 // TimeZone::createDefault is called once here, the timezone ID is
695 // cached and there's no more need to access the file system.
696 scoped_ptr<icu::TimeZone> zone(icu::TimeZone::createDefault());
[email protected]1831acf2009-10-05 16:38:41697
[email protected]eeb08552011-03-18 11:15:39698#if defined(USE_NSS)
[email protected]f6a67b42011-03-17 23:49:21699 // NSS libraries are loaded before sandbox is activated. This is to allow
700 // successful initialization of NSS which tries to load extra library files.
[email protected]4b559b4d2011-04-14 17:37:14701 crypto::LoadNSSLibraries();
[email protected]1f5548452011-10-06 06:46:15702#elif defined(USE_OPENSSL)
703 // OpenSSL is intentionally not supported in the sandboxed processes, see
704 // http://crbug.com/99163. If that ever changes we'll likely need to init
705 // OpenSSL here (at least, load the library and error strings).
[email protected]eeb08552011-03-18 11:15:39706#else
[email protected]1f5548452011-10-06 06:46:15707 // It's possible that another hypothetical crypto stack would not require
708 // pre-sandbox init, but more likely this is just a build configuration error.
709 #error Which SSL library are you using?
[email protected]f6a67b42011-03-17 23:49:21710#endif
[email protected]ed450f32011-03-16 01:26:49711
[email protected]17773042010-07-28 17:35:07712 // Ensure access to the Pepper plugins before the sandbox is turned on.
713 PepperPluginRegistry::PreloadModules();
[email protected]ad6d2c42009-09-15 20:13:38714}
715
716#if !defined(CHROMIUM_SELINUX)
717static bool EnterSandbox() {
[email protected]b8419412010-03-29 20:18:29718 // The SUID sandbox sets this environment variable to a file descriptor
719 // over which we can signal that we have completed our startup and can be
720 // chrooted.
[email protected]ad6d2c42009-09-15 20:13:38721 const char* const sandbox_fd_string = getenv("SBX_D");
[email protected]ad6d2c42009-09-15 20:13:38722
[email protected]0dc32322010-09-16 09:46:59723 if (sandbox_fd_string) {
724 // Use the SUID sandbox. This still allows the seccomp sandbox to
725 // be enabled by the process later.
[email protected]8ecd3aad2009-11-04 08:32:22726 g_suid_sandbox_active = true;
727
[email protected]ad6d2c42009-09-15 20:13:38728 char* endptr;
729 const long fd_long = strtol(sandbox_fd_string, &endptr, 10);
730 if (!*sandbox_fd_string || *endptr || fd_long < 0 || fd_long > INT_MAX)
731 return false;
732 const int fd = fd_long;
733
734 PreSandboxInit();
[email protected]c9e45da02009-08-05 17:35:08735
[email protected]eaebefaf2010-02-23 22:58:18736 static const char kMsgChrootMe = 'C';
737 static const char kMsgChrootSuccessful = 'O';
[email protected]abe3ad92009-06-15 18:15:08738
[email protected]eaebefaf2010-02-23 22:58:18739 if (HANDLE_EINTR(write(fd, &kMsgChrootMe, 1)) != 1) {
[email protected]0e1611122009-07-10 18:17:32740 LOG(ERROR) << "Failed to write to chroot pipe: " << errno;
[email protected]abe3ad92009-06-15 18:15:08741 return false;
[email protected]0e1611122009-07-10 18:17:32742 }
[email protected]abe3ad92009-06-15 18:15:08743
[email protected]87ed6952009-07-16 02:52:15744 // We need to reap the chroot helper process in any event:
745 wait(NULL);
746
[email protected]abe3ad92009-06-15 18:15:08747 char reply;
[email protected]87f8ce62009-07-10 19:14:31748 if (HANDLE_EINTR(read(fd, &reply, 1)) != 1) {
[email protected]0e1611122009-07-10 18:17:32749 LOG(ERROR) << "Failed to read from chroot pipe: " << errno;
[email protected]abe3ad92009-06-15 18:15:08750 return false;
[email protected]0e1611122009-07-10 18:17:32751 }
[email protected]87f8ce62009-07-10 19:14:31752
[email protected]eaebefaf2010-02-23 22:58:18753 if (reply != kMsgChrootSuccessful) {
[email protected]0e1611122009-07-10 18:17:32754 LOG(ERROR) << "Error code reply from chroot helper";
[email protected]abe3ad92009-06-15 18:15:08755 return false;
[email protected]0e1611122009-07-10 18:17:32756 }
[email protected]abe3ad92009-06-15 18:15:08757
[email protected]cf3ac3972010-12-22 20:02:29758 SkiaFontConfigSetImplementation(
759 new FontConfigIPC(kMagicSandboxIPCDescriptor));
[email protected]abe3ad92009-06-15 18:15:08760
[email protected]415493be2009-07-10 17:50:24761 // Previously, we required that the binary be non-readable. This causes the
762 // kernel to mark the process as non-dumpable at startup. The thinking was
763 // that, although we were putting the renderers into a PID namespace (with
764 // the SUID sandbox), they would nonetheless be in the /same/ PID
765 // namespace. So they could ptrace each other unless they were non-dumpable.
766 //
767 // If the binary was readable, then there would be a window between process
768 // startup and the point where we set the non-dumpable flag in which a
769 // compromised renderer could ptrace attach.
770 //
771 // However, now that we have a zygote model, only the (trusted) zygote
772 // exists at this point and we can set the non-dumpable flag which is
773 // inherited by all our renderer children.
[email protected]4730db92009-07-22 00:40:48774 //
775 // Note: a non-dumpable process can't be debugged. To debug sandbox-related
776 // issues, one can specify --allow-sandbox-debugging to let the process be
777 // dumpable.
778 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
779 if (!command_line.HasSwitch(switches::kAllowSandboxDebugging)) {
780 prctl(PR_SET_DUMPABLE, 0, 0, 0, 0);
781 if (prctl(PR_GET_DUMPABLE, 0, 0, 0, 0)) {
782 LOG(ERROR) << "Failed to set non-dumpable flag";
783 return false;
784 }
[email protected]0e1611122009-07-10 18:17:32785 }
[email protected]2bc039a2011-07-29 23:05:41786#if defined(SECCOMP_SANDBOX)
[email protected]65f607f2011-08-03 21:08:12787 } else if (SeccompSandboxEnabled()) {
[email protected]0dc32322010-09-16 09:46:59788 PreSandboxInit();
[email protected]cf3ac3972010-12-22 20:02:29789 SkiaFontConfigSetImplementation(
790 new FontConfigIPC(kMagicSandboxIPCDescriptor));
[email protected]2bc039a2011-07-29 23:05:41791#endif
[email protected]abe3ad92009-06-15 18:15:08792 } else {
793 SkiaFontConfigUseDirectImplementation();
794 }
795
796 return true;
797}
[email protected]ad6d2c42009-09-15 20:13:38798#else // CHROMIUM_SELINUX
799
800static bool EnterSandbox() {
801 PreSandboxInit();
802 SkiaFontConfigUseIPCImplementation(kMagicSandboxIPCDescriptor);
[email protected]ad6d2c42009-09-15 20:13:38803 return true;
804}
805
806#endif // CHROMIUM_SELINUX
[email protected]abe3ad92009-06-15 18:15:08807
[email protected]ce2ae442011-07-18 16:13:41808bool ZygoteMain(const MainFunctionParams& params,
809 ZygoteForkDelegate* forkdelegate) {
[email protected]ad6d2c42009-09-15 20:13:38810#if !defined(CHROMIUM_SELINUX)
[email protected]a0f200ea2009-08-06 18:44:06811 g_am_zygote_or_renderer = true;
[email protected]ad6d2c42009-09-15 20:13:38812#endif
[email protected]a0f200ea2009-08-06 18:44:06813
[email protected]36ea6c6f2010-03-17 20:08:01814#if defined(SECCOMP_SANDBOX)
[email protected]65f607f2011-08-03 21:08:12815 if (SeccompSandboxEnabled()) {
[email protected]2bc039a2011-07-29 23:05:41816 // The seccomp sandbox needs access to files in /proc, which might be denied
817 // after one of the other sandboxes have been started. So, obtain a suitable
818 // file handle in advance.
[email protected]a9c54a172009-11-07 06:09:38819 g_proc_fd = open("/proc", O_DIRECTORY | O_RDONLY);
820 if (g_proc_fd < 0) {
821 LOG(ERROR) << "WARNING! Cannot access \"/proc\". Disabling seccomp "
[email protected]2bc039a2011-07-29 23:05:41822 "sandboxing.";
[email protected]a9c54a172009-11-07 06:09:38823 }
824 }
[email protected]36ea6c6f2010-03-17 20:08:01825#endif // SECCOMP_SANDBOX
[email protected]a9c54a172009-11-07 06:09:38826
[email protected]ce2ae442011-07-18 16:13:41827 if (forkdelegate != NULL) {
828 VLOG(1) << "ZygoteMain: initializing fork delegate";
829 forkdelegate->Init(getenv("SBX_D") != NULL, // g_suid_sandbox_active,
830 kBrowserDescriptor,
831 kMagicSandboxIPCDescriptor);
832 } else {
833 VLOG(1) << "ZygoteMain: fork delegate is NULL";
834 }
835
[email protected]a9c54a172009-11-07 06:09:38836 // Turn on the SELinux or SUID sandbox
837 if (!EnterSandbox()) {
838 LOG(FATAL) << "Failed to enter sandbox. Fail safe abort. (errno: "
839 << errno << ")";
840 return false;
841 }
842
[email protected]715b4f262010-07-13 14:17:28843 int sandbox_flags = 0;
844 if (getenv("SBX_D"))
845 sandbox_flags |= ZygoteHost::kSandboxSUID;
846 if (getenv("SBX_PID_NS"))
847 sandbox_flags |= ZygoteHost::kSandboxPIDNS;
848 if (getenv("SBX_NET_NS"))
849 sandbox_flags |= ZygoteHost::kSandboxNetNS;
850
[email protected]36ea6c6f2010-03-17 20:08:01851#if defined(SECCOMP_SANDBOX)
[email protected]a9c54a172009-11-07 06:09:38852 // The seccomp sandbox will be turned on when the renderers start. But we can
853 // already check if sufficient support is available so that we only need to
854 // print one error message for the entire browser session.
[email protected]65f607f2011-08-03 21:08:12855 if (g_proc_fd >= 0 && SeccompSandboxEnabled()) {
[email protected]a9c54a172009-11-07 06:09:38856 if (!SupportsSeccompSandbox(g_proc_fd)) {
[email protected]e8c916a2009-11-04 17:52:47857 // There are a good number of users who cannot use the seccomp sandbox
858 // (e.g. because their distribution does not enable seccomp mode by
859 // default). While we would prefer to deny execution in this case, it
860 // seems more realistic to continue in degraded mode.
[email protected]1b5d28f2010-02-18 15:53:36861 LOG(ERROR) << "WARNING! This machine lacks support needed for the "
862 "Seccomp sandbox. Running renderers with Seccomp "
863 "sandboxing disabled.";
[email protected]e8c916a2009-11-04 17:52:47864 } else {
[email protected]0b4610a92011-08-04 18:08:09865 VLOG(1) << "Enabling experimental Seccomp sandbox.";
[email protected]715b4f262010-07-13 14:17:28866 sandbox_flags |= ZygoteHost::kSandboxSeccomp;
[email protected]e8c916a2009-11-04 17:52:47867 }
868 }
[email protected]36ea6c6f2010-03-17 20:08:01869#endif // SECCOMP_SANDBOX
[email protected]e8c916a2009-11-04 17:52:47870
[email protected]ce2ae442011-07-18 16:13:41871 Zygote zygote(sandbox_flags, forkdelegate);
[email protected]c548be22010-03-08 12:55:57872 // This function call can return multiple times, once per fork().
[email protected]cc8f1462009-06-12 17:36:55873 return zygote.ProcessRequests();
874}