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

Side by Side Diff: content/zygote/zygote_main_linux.cc

Issue 280303002: Add sandbox support for AsanCoverage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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
« content/gpu/gpu_main.cc ('K') | « content/gpu/gpu_main.cc ('k') | no next file » | 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/zygote/zygote_main.h" 5 #include "content/zygote/zygote_main.h"
6 6
7 #include <dlfcn.h> 7 #include <dlfcn.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <fcntl.h> 9 #include <fcntl.h>
10 #include <pthread.h> 10 #include <pthread.h>
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include <sys/prctl.h> 51 #include <sys/prctl.h>
52 #include <sys/signal.h> 52 #include <sys/signal.h>
53 #else 53 #else
54 #include <signal.h> 54 #include <signal.h>
55 #endif 55 #endif
56 56
57 #if defined(ENABLE_WEBRTC) 57 #if defined(ENABLE_WEBRTC)
58 #include "third_party/libjingle/overrides/init_webrtc.h" 58 #include "third_party/libjingle/overrides/init_webrtc.h"
59 #endif 59 #endif
60 60
61 #if defined(ADDRESS_SANITIZER)
62 #include <sanitizer/asan_interface.h>
63 #endif
64
61 namespace content { 65 namespace content {
62 66
63 // See http://code.google.com/p/chromium/wiki/LinuxZygote 67 // See http://code.google.com/p/chromium/wiki/LinuxZygote
64 68
65 static void ProxyLocaltimeCallToBrowser(time_t input, struct tm* output, 69 static void ProxyLocaltimeCallToBrowser(time_t input, struct tm* output,
66 char* timezone_out, 70 char* timezone_out,
67 size_t timezone_out_len) { 71 size_t timezone_out_len) {
68 Pickle request; 72 Pickle request;
69 request.WriteInt(LinuxSandbox::METHOD_LOCALTIME); 73 request.WriteInt(LinuxSandbox::METHOD_LOCALTIME);
70 request.WriteString( 74 request.WriteString(
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 if (prctl(PR_GET_DUMPABLE, 0, 0, 0, 0)) { 417 if (prctl(PR_GET_DUMPABLE, 0, 0, 0, 0)) {
414 LOG(ERROR) << "Failed to set non-dumpable flag"; 418 LOG(ERROR) << "Failed to set non-dumpable flag";
415 return false; 419 return false;
416 } 420 }
417 } 421 }
418 #endif 422 #endif
419 423
420 return true; 424 return true;
421 } 425 }
422 426
427 #if defined(ADDRESS_SANITIZER)
428 const size_t kSanitizerMaxMessageLength = 1 * 1024 * 1024;
429
430 static void SanitizerCoverageHelper(int socket_fd) {
431 int file_fd = -1;
432 char buffer[kSanitizerMaxMessageLength];
433 while (true) {
434 int received_size = recv(socket_fd, buffer, kSanitizerMaxMessageLength, 0);
jln (very slow on Chromium) 2014/05/13 01:17:35 HANDLE_EINTR()
earthdok 2014/05/14 17:00:26 Done.
435 PCHECK(received_size >= 0)
436 << "Sanitizer coverage helper: failed to read from socket.";
437 if (received_size > 0) {
438 if (file_fd < 0) {
439 //TODO: filename must include real pid
earthdok 2014/05/12 15:48:20 Does the Zygote know its real pid?
jln (very slow on Chromium) 2014/05/13 01:17:35 I don't think so. Matthew? Do you need it?
mdempsky 2014/05/13 01:40:47 Correct, currently the zygote never learns its own
earthdok 2014/05/14 17:00:26 The intention is to make the filename unique. Can
mdempsky 2014/05/14 17:11:29 Right now, no. I have some plans in the future to
440 char filename[64] = "zygote.sancov.packed";
jln (very slow on Chromium) 2014/05/13 01:17:35 const char kZygoteSanCovFileName[] = "zygote.sanco
earthdok 2014/05/14 17:00:26 Done.
441 file_fd = creat(filename, 0660);
jln (very slow on Chromium) 2014/05/13 01:17:35 HANDLE_EINTR. More importantly, I don't like crea
earthdok 2014/05/14 17:00:26 I wanted to do this the same way it's done in sani
442 PCHECK(file_fd >= 0)
443 << "Sanitizer coverage helper: failed to open file.";
444 }
445 int written_size = write(file_fd, buffer, received_size);
jln (very slow on Chromium) 2014/05/13 01:17:35 HANDLE_EINTR()
jln (very slow on Chromium) 2014/05/13 01:17:35 ssize_t
earthdok 2014/05/14 17:00:26 Done.
446 PCHECK(written_size == received_size)
447 << "Sanitizer coverage helper: error writing to file ";
448 fsync(file_fd);
jln (very slow on Chromium) 2014/05/13 01:17:35 PCHECK()
earthdok 2014/05/14 17:00:26 Done. Also added HANDLE_EINTR.
449 }
450 }
451 }
452
453 static int ForkSanitizerCoverageHelper() {
454 int fds[2];
455 PCHECK(0 == socketpair(AF_UNIX, SOCK_SEQPACKET, 0, fds))
jln (very slow on Chromium) 2014/05/13 01:17:35 You're only using the socketpair in one direction.
earthdok 2014/05/14 17:00:26 Done.
456 << "Sanitizer coverage helper: failed to create a socket pair.";
457 int pid = fork();
jln (very slow on Chromium) 2014/05/13 01:19:35 pid_t
earthdok 2014/05/14 17:00:26 Done.
458 PCHECK(pid >= 0) << "Sanitizer coverage helper: failed to fork.";
459 if (pid == 0) {
460 // In the child.
461 close(fds[1]);
jln (very slow on Chromium) 2014/05/13 01:17:35 PCHECK(0 == IGNORE_EINTR(close()));
earthdok 2014/05/14 17:00:26 Done.
462 SanitizerCoverageHelper(fds[0]);
463 _exit(0);
464 } else {
465 // In the parent.
466 close(fds[0]);
jln (very slow on Chromium) 2014/05/13 01:17:35 PCHECK(0 ==...
earthdok 2014/05/14 17:00:26 Done.
467 return fds[1];
468 }
469 }
470 #endif
471
423 // If |is_suid_sandbox_child|, then make sure that the setuid sandbox is 472 // If |is_suid_sandbox_child|, then make sure that the setuid sandbox is
424 // engaged. 473 // engaged.
425 static void EnterLayerOneSandbox(LinuxSandbox* linux_sandbox, 474 static void EnterLayerOneSandbox(LinuxSandbox* linux_sandbox,
426 bool is_suid_sandbox_child) { 475 bool is_suid_sandbox_child) {
427 DCHECK(linux_sandbox); 476 DCHECK(linux_sandbox);
428 477
429 ZygotePreSandboxInit(); 478 ZygotePreSandboxInit();
430 479
431 // Check that the pre-sandbox initialization didn't spawn threads. 480 // Check that the pre-sandbox initialization didn't spawn threads.
432 #if !defined(THREAD_SANITIZER) 481 #if !defined(THREAD_SANITIZER)
433 DCHECK(linux_sandbox->IsSingleThreaded()); 482 DCHECK(linux_sandbox->IsSingleThreaded());
434 #endif 483 #endif
435 484
436 sandbox::SetuidSandboxClient* setuid_sandbox = 485 sandbox::SetuidSandboxClient* setuid_sandbox =
437 linux_sandbox->setuid_sandbox_client(); 486 linux_sandbox->setuid_sandbox_client();
438 487
439 if (is_suid_sandbox_child) { 488 if (is_suid_sandbox_child) {
440 CHECK(EnterSuidSandbox(setuid_sandbox)) << "Failed to enter setuid sandbox"; 489 CHECK(EnterSuidSandbox(setuid_sandbox)) << "Failed to enter setuid sandbox";
441 } 490 }
442 } 491 }
443 492
444 bool ZygoteMain(const MainFunctionParams& params, 493 bool ZygoteMain(const MainFunctionParams& params,
445 ZygoteForkDelegate* forkdelegate) { 494 ZygoteForkDelegate* forkdelegate) {
446 g_am_zygote_or_renderer = true; 495 g_am_zygote_or_renderer = true;
447 sandbox::InitLibcUrandomOverrides(); 496 sandbox::InitLibcUrandomOverrides();
448 497
449 LinuxSandbox* linux_sandbox = LinuxSandbox::GetInstance(); 498 LinuxSandbox* linux_sandbox = LinuxSandbox::GetInstance();
499
500 #if defined(ADDRESS_SANITIZER)
501 int sancov_helper_fd = ForkSanitizerCoverageHelper();
jln (very slow on Chromium) 2014/05/13 01:17:35 As described in the bug, the Coverage Helper shoul
earthdok 2014/05/14 17:00:26 There's just one problem: that would cause any ASa
jln (very slow on Chromium) 2014/05/14 17:49:40 It could be a nice property to execute a similar c
earthdok 2014/05/14 19:21:47 That's not a bad idea. The only downside is that w
earthdok 2014/05/20 16:53:57 Done. Note that sanitizer args still have to be fi
502 struct __sanitizer_sandbox_arguments* sanitizer_args =
503 new struct __sanitizer_sandbox_arguments;
504 memset(sanitizer_args, 0, sizeof(*sanitizer_args));
505 sanitizer_args->coverage_sandboxed = 1;
506 sanitizer_args->coverage_fd = sancov_helper_fd;
507 sanitizer_args->coverage_max_block_size = kSanitizerMaxMessageLength;
508
509 linux_sandbox->SetSanitizerArgs(sanitizer_args);
510 #endif
511
450 // This will pre-initialize the various sandboxes that need it. 512 // This will pre-initialize the various sandboxes that need it.
451 linux_sandbox->PreinitializeSandbox(); 513 linux_sandbox->PreinitializeSandbox();
452 514
453 const bool must_enable_setuid_sandbox = 515 const bool must_enable_setuid_sandbox =
454 linux_sandbox->setuid_sandbox_client()->IsSuidSandboxChild(); 516 linux_sandbox->setuid_sandbox_client()->IsSuidSandboxChild();
455 if (must_enable_setuid_sandbox) { 517 if (must_enable_setuid_sandbox) {
456 linux_sandbox->setuid_sandbox_client()->CloseDummyFile(); 518 linux_sandbox->setuid_sandbox_client()->CloseDummyFile();
457 519
458 // Let the ZygoteHost know we're booting up. 520 // Let the ZygoteHost know we're booting up.
459 CHECK(UnixDomainSocket::SendMsg(kZygoteSocketPairFd, 521 CHECK(UnixDomainSocket::SendMsg(kZygoteSocketPairFd,
(...skipping 15 matching lines...) Expand all
475 int sandbox_flags = linux_sandbox->GetStatus(); 537 int sandbox_flags = linux_sandbox->GetStatus();
476 bool setuid_sandbox_engaged = sandbox_flags & kSandboxLinuxSUID; 538 bool setuid_sandbox_engaged = sandbox_flags & kSandboxLinuxSUID;
477 CHECK_EQ(must_enable_setuid_sandbox, setuid_sandbox_engaged); 539 CHECK_EQ(must_enable_setuid_sandbox, setuid_sandbox_engaged);
478 540
479 Zygote zygote(sandbox_flags, forkdelegate); 541 Zygote zygote(sandbox_flags, forkdelegate);
480 // This function call can return multiple times, once per fork(). 542 // This function call can return multiple times, once per fork().
481 return zygote.ProcessRequests(); 543 return zygote.ProcessRequests();
482 } 544 }
483 545
484 } // namespace content 546 } // namespace content
OLDNEW
« content/gpu/gpu_main.cc ('K') | « content/gpu/gpu_main.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698