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

Side by Side Diff: content/common/sandbox_linux/sandbox_linux.cc

Issue 280303002: Add sandbox support for AsanCoverage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: helper exits on 0 bytes received, zygote waits on it 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
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 <dirent.h> 5 #include <dirent.h>
6 #include <fcntl.h> 6 #include <fcntl.h>
7 #include <sys/resource.h> 7 #include <sys/resource.h>
8 #include <sys/stat.h> 8 #include <sys/stat.h>
9 #include <sys/time.h> 9 #include <sys/time.h>
10 #include <sys/types.h> 10 #include <sys/types.h>
(...skipping 16 matching lines...) Expand all
27 #include "build/build_config.h" 27 #include "build/build_config.h"
28 #include "content/common/sandbox_linux/sandbox_linux.h" 28 #include "content/common/sandbox_linux/sandbox_linux.h"
29 #include "content/common/sandbox_linux/sandbox_seccomp_bpf_linux.h" 29 #include "content/common/sandbox_linux/sandbox_seccomp_bpf_linux.h"
30 #include "content/public/common/content_switches.h" 30 #include "content/public/common/content_switches.h"
31 #include "content/public/common/sandbox_linux.h" 31 #include "content/public/common/sandbox_linux.h"
32 #include "sandbox/linux/services/credentials.h" 32 #include "sandbox/linux/services/credentials.h"
33 #include "sandbox/linux/services/thread_helpers.h" 33 #include "sandbox/linux/services/thread_helpers.h"
34 #include "sandbox/linux/services/yama.h" 34 #include "sandbox/linux/services/yama.h"
35 #include "sandbox/linux/suid/client/setuid_sandbox_client.h" 35 #include "sandbox/linux/suid/client/setuid_sandbox_client.h"
36 36
37 #if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \
38 defined(LEAK_SANITIZER)
39 #include <sanitizer/common_interface_defs.h>
40 #endif
41
37 using sandbox::Yama; 42 using sandbox::Yama;
38 43
39 namespace { 44 namespace {
40 45
41 struct FDCloser { 46 struct FDCloser {
42 inline void operator()(int* fd) const { 47 inline void operator()(int* fd) const {
43 DCHECK(fd); 48 DCHECK(fd);
44 PCHECK(0 == IGNORE_EINTR(close(*fd))); 49 PCHECK(0 == IGNORE_EINTR(close(*fd)));
45 *fd = -1; 50 *fd = -1;
46 } 51 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 107
103 namespace content { 108 namespace content {
104 109
105 LinuxSandbox::LinuxSandbox() 110 LinuxSandbox::LinuxSandbox()
106 : proc_fd_(-1), 111 : proc_fd_(-1),
107 seccomp_bpf_started_(false), 112 seccomp_bpf_started_(false),
108 sandbox_status_flags_(kSandboxLinuxInvalid), 113 sandbox_status_flags_(kSandboxLinuxInvalid),
109 pre_initialized_(false), 114 pre_initialized_(false),
110 seccomp_bpf_supported_(false), 115 seccomp_bpf_supported_(false),
111 yama_is_enforcing_(false), 116 yama_is_enforcing_(false),
112 setuid_sandbox_client_(sandbox::SetuidSandboxClient::Create()) { 117 setuid_sandbox_client_(sandbox::SetuidSandboxClient::Create())
118 {
113 if (setuid_sandbox_client_ == NULL) { 119 if (setuid_sandbox_client_ == NULL) {
114 LOG(FATAL) << "Failed to instantiate the setuid sandbox client."; 120 LOG(FATAL) << "Failed to instantiate the setuid sandbox client.";
115 } 121 }
122 #if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \
123 defined(LEAK_SANITIZER)
124 sanitizer_args_ = make_scoped_ptr(new __sanitizer_sandbox_arguments);
125 *sanitizer_args_ = {0};
126 #endif
116 } 127 }
117 128
118 LinuxSandbox::~LinuxSandbox() { 129 LinuxSandbox::~LinuxSandbox() {
119 } 130 }
120 131
121 LinuxSandbox* LinuxSandbox::GetInstance() { 132 LinuxSandbox* LinuxSandbox::GetInstance() {
122 LinuxSandbox* instance = Singleton<LinuxSandbox>::get(); 133 LinuxSandbox* instance = Singleton<LinuxSandbox>::get();
123 CHECK(instance); 134 CHECK(instance);
124 return instance; 135 return instance;
125 } 136 }
126 137
127 #if (defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \
128 defined(LEAK_SANITIZER)) && defined(OS_LINUX)
129 // Sanitizer API call to notify the tool the sandbox is going to be turned on.
130 extern "C" void __sanitizer_sandbox_on_notify(void *reserved);
131 #endif
132
133 void LinuxSandbox::PreinitializeSandbox() { 138 void LinuxSandbox::PreinitializeSandbox() {
134 CHECK(!pre_initialized_); 139 CHECK(!pre_initialized_);
135 seccomp_bpf_supported_ = false; 140 seccomp_bpf_supported_ = false;
136 #if (defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \ 141 #if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \
137 defined(LEAK_SANITIZER)) && defined(OS_LINUX) 142 defined(LEAK_SANITIZER)
138 // Sanitizers need to open some resources before the sandbox is enabled. 143 // Sanitizers need to open some resources before the sandbox is enabled.
139 // This should not fork, not launch threads, not open a directory. 144 // This should not fork, not launch threads, not open a directory.
140 __sanitizer_sandbox_on_notify(/*reserved*/ NULL); 145 __sanitizer_sandbox_on_notify(sanitizer_args());
146 sanitizer_args_.reset();
141 #endif 147 #endif
142 148
143 #if !defined(NDEBUG) 149 #if !defined(NDEBUG)
144 // The in-process stack dumping needs to open /proc/self/maps and cache 150 // The in-process stack dumping needs to open /proc/self/maps and cache
145 // its contents before the sandbox is enabled. It also pre-opens the 151 // its contents before the sandbox is enabled. It also pre-opens the
146 // object files that are already loaded in the process address space. 152 // object files that are already loaded in the process address space.
147 base::debug::EnableInProcessStackDumpingForSandbox(); 153 base::debug::EnableInProcessStackDumpingForSandbox();
148 154
149 // Open proc_fd_ only in Debug mode so that forgetting to close it doesn't 155 // Open proc_fd_ only in Debug mode so that forgetting to close it doesn't
150 // produce a sandbox escape in Release mode. 156 // produce a sandbox escape in Release mode.
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 410
405 void LinuxSandbox::StopThreadAndEnsureNotCounted(base::Thread* thread) const { 411 void LinuxSandbox::StopThreadAndEnsureNotCounted(base::Thread* thread) const {
406 DCHECK(thread); 412 DCHECK(thread);
407 base::ScopedFD proc_self_task(OpenProcTaskFd(proc_fd_)); 413 base::ScopedFD proc_self_task(OpenProcTaskFd(proc_fd_));
408 PCHECK(proc_self_task.is_valid()); 414 PCHECK(proc_self_task.is_valid());
409 CHECK(sandbox::ThreadHelpers::StopThreadAndWatchProcFS(proc_self_task.get(), 415 CHECK(sandbox::ThreadHelpers::StopThreadAndWatchProcFS(proc_self_task.get(),
410 thread)); 416 thread));
411 } 417 }
412 418
413 } // namespace content 419 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698