Chromium Code Reviews| Index: content/zygote/zygote_main_linux.cc |
| diff --git a/content/zygote/zygote_main_linux.cc b/content/zygote/zygote_main_linux.cc |
| index 11f06022d1fb3e5f58bb470b5dae174dcb9ee026..9d1a62aee22f59d2299d1de94fedd35ec02582c0 100644 |
| --- a/content/zygote/zygote_main_linux.cc |
| +++ b/content/zygote/zygote_main_linux.cc |
| @@ -58,6 +58,10 @@ |
| #include "third_party/libjingle/overrides/init_webrtc.h" |
| #endif |
| +#if defined(ADDRESS_SANITIZER) |
| +#include <sanitizer/asan_interface.h> |
| +#endif |
| + |
| namespace content { |
| // See http://code.google.com/p/chromium/wiki/LinuxZygote |
| @@ -420,6 +424,51 @@ static bool EnterSuidSandbox(sandbox::SetuidSandboxClient* setuid_sandbox) { |
| return true; |
| } |
| +#if defined(ADDRESS_SANITIZER) |
| +const size_t kSanitizerMaxMessageLength = 1 * 1024 * 1024; |
| + |
| +static void SanitizerCoverageHelper(int socket_fd) { |
| + int file_fd = -1; |
| + char buffer[kSanitizerMaxMessageLength]; |
| + while (true) { |
| + 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.
|
| + PCHECK(received_size >= 0) |
| + << "Sanitizer coverage helper: failed to read from socket."; |
| + if (received_size > 0) { |
| + if (file_fd < 0) { |
| + //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
|
| + 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.
|
| + 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
|
| + PCHECK(file_fd >= 0) |
| + << "Sanitizer coverage helper: failed to open file."; |
| + } |
| + 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.
|
| + PCHECK(written_size == received_size) |
| + << "Sanitizer coverage helper: error writing to file "; |
| + 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.
|
| + } |
| + } |
| +} |
| + |
| +static int ForkSanitizerCoverageHelper() { |
| + int fds[2]; |
| + 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.
|
| + << "Sanitizer coverage helper: failed to create a socket pair."; |
| + int pid = fork(); |
|
jln (very slow on Chromium)
2014/05/13 01:19:35
pid_t
earthdok
2014/05/14 17:00:26
Done.
|
| + PCHECK(pid >= 0) << "Sanitizer coverage helper: failed to fork."; |
| + if (pid == 0) { |
| + // In the child. |
| + 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.
|
| + SanitizerCoverageHelper(fds[0]); |
| + _exit(0); |
| + } else { |
| + // In the parent. |
| + close(fds[0]); |
|
jln (very slow on Chromium)
2014/05/13 01:17:35
PCHECK(0 ==...
earthdok
2014/05/14 17:00:26
Done.
|
| + return fds[1]; |
| + } |
| +} |
| +#endif |
| + |
| // If |is_suid_sandbox_child|, then make sure that the setuid sandbox is |
| // engaged. |
| static void EnterLayerOneSandbox(LinuxSandbox* linux_sandbox, |
| @@ -447,6 +496,19 @@ bool ZygoteMain(const MainFunctionParams& params, |
| sandbox::InitLibcUrandomOverrides(); |
| LinuxSandbox* linux_sandbox = LinuxSandbox::GetInstance(); |
| + |
| +#if defined(ADDRESS_SANITIZER) |
| + 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
|
| + struct __sanitizer_sandbox_arguments* sanitizer_args = |
| + new struct __sanitizer_sandbox_arguments; |
| + memset(sanitizer_args, 0, sizeof(*sanitizer_args)); |
| + sanitizer_args->coverage_sandboxed = 1; |
| + sanitizer_args->coverage_fd = sancov_helper_fd; |
| + sanitizer_args->coverage_max_block_size = kSanitizerMaxMessageLength; |
| + |
| + linux_sandbox->SetSanitizerArgs(sanitizer_args); |
| +#endif |
| + |
| // This will pre-initialize the various sandboxes that need it. |
| linux_sandbox->PreinitializeSandbox(); |