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

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: address most of jln@'s comments 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 #if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \
119 defined(LEAK_SANITIZER)
120 , sanitizer_args_(new __sanitizer_sandbox_arguments)
121 #endif
jln (very slow on Chromium) 2014/05/14 17:49:41 Maybe just put it below in the body of the constru
earthdok 2014/05/20 16:53:57 Done.
122 {
113 if (setuid_sandbox_client_ == NULL) { 123 if (setuid_sandbox_client_ == NULL) {
114 LOG(FATAL) << "Failed to instantiate the setuid sandbox client."; 124 LOG(FATAL) << "Failed to instantiate the setuid sandbox client.";
115 } 125 }
126 #if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \
127 defined(LEAK_SANITIZER)
128 *sanitizer_args_ = {0};
129 #endif
116 } 130 }
117 131
118 LinuxSandbox::~LinuxSandbox() { 132 LinuxSandbox::~LinuxSandbox() {
119 } 133 }
120 134
121 LinuxSandbox* LinuxSandbox::GetInstance() { 135 LinuxSandbox* LinuxSandbox::GetInstance() {
122 LinuxSandbox* instance = Singleton<LinuxSandbox>::get(); 136 LinuxSandbox* instance = Singleton<LinuxSandbox>::get();
123 CHECK(instance); 137 CHECK(instance);
124 return instance; 138 return instance;
125 } 139 }
126 140
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() { 141 void LinuxSandbox::PreinitializeSandbox() {
134 CHECK(!pre_initialized_); 142 CHECK(!pre_initialized_);
135 seccomp_bpf_supported_ = false; 143 seccomp_bpf_supported_ = false;
136 #if (defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \ 144 #if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \
137 defined(LEAK_SANITIZER)) && defined(OS_LINUX) 145 defined(LEAK_SANITIZER)
138 // Sanitizers need to open some resources before the sandbox is enabled. 146 // Sanitizers need to open some resources before the sandbox is enabled.
139 // This should not fork, not launch threads, not open a directory. 147 // This should not fork, not launch threads, not open a directory.
140 __sanitizer_sandbox_on_notify(/*reserved*/ NULL); 148 __sanitizer_sandbox_on_notify(sanitizer_args());
jln (very slow on Chromium) 2014/05/14 17:49:41 Before the process exits, when the LinuxSandbox si
earthdok 2014/05/14 19:21:47 In the current implementation, the structure is on
jln (very slow on Chromium) 2014/05/14 23:26:30 Ok. Let's have a GetSanitizerArgs() that .Pass() t
jln (very slow on Chromium) 2014/05/14 23:27:41 err, no need to .reset() manually, it will happen
earthdok 2014/05/20 16:53:57 Making this accessor .Pass() the pointer is incorr
141 #endif 149 #endif
142 150
143 #if !defined(NDEBUG) 151 #if !defined(NDEBUG)
144 // The in-process stack dumping needs to open /proc/self/maps and cache 152 // 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 153 // its contents before the sandbox is enabled. It also pre-opens the
146 // object files that are already loaded in the process address space. 154 // object files that are already loaded in the process address space.
147 base::debug::EnableInProcessStackDumpingForSandbox(); 155 base::debug::EnableInProcessStackDumpingForSandbox();
148 156
149 // Open proc_fd_ only in Debug mode so that forgetting to close it doesn't 157 // Open proc_fd_ only in Debug mode so that forgetting to close it doesn't
150 // produce a sandbox escape in Release mode. 158 // produce a sandbox escape in Release mode.
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 412
405 void LinuxSandbox::StopThreadAndEnsureNotCounted(base::Thread* thread) const { 413 void LinuxSandbox::StopThreadAndEnsureNotCounted(base::Thread* thread) const {
406 DCHECK(thread); 414 DCHECK(thread);
407 base::ScopedFD proc_self_task(OpenProcTaskFd(proc_fd_)); 415 base::ScopedFD proc_self_task(OpenProcTaskFd(proc_fd_));
408 PCHECK(proc_self_task.is_valid()); 416 PCHECK(proc_self_task.is_valid());
409 CHECK(sandbox::ThreadHelpers::StopThreadAndWatchProcFS(proc_self_task.get(), 417 CHECK(sandbox::ThreadHelpers::StopThreadAndWatchProcFS(proc_self_task.get(),
410 thread)); 418 thread));
411 } 419 }
412 420
413 } // namespace content 421 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698