OLD | NEW |
---|---|
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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
102 | 102 |
103 namespace content { | 103 namespace content { |
104 | 104 |
105 LinuxSandbox::LinuxSandbox() | 105 LinuxSandbox::LinuxSandbox() |
106 : proc_fd_(-1), | 106 : proc_fd_(-1), |
107 seccomp_bpf_started_(false), | 107 seccomp_bpf_started_(false), |
108 sandbox_status_flags_(kSandboxLinuxInvalid), | 108 sandbox_status_flags_(kSandboxLinuxInvalid), |
109 pre_initialized_(false), | 109 pre_initialized_(false), |
110 seccomp_bpf_supported_(false), | 110 seccomp_bpf_supported_(false), |
111 yama_is_enforcing_(false), | 111 yama_is_enforcing_(false), |
112 setuid_sandbox_client_(sandbox::SetuidSandboxClient::Create()) { | 112 setuid_sandbox_client_(sandbox::SetuidSandboxClient::Create()) |
113 #if (defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \ | |
114 defined(LEAK_SANITIZER)) && defined(OS_LINUX) | |
115 , sanitizer_args_(NULL) | |
116 #endif | |
117 { | |
113 if (setuid_sandbox_client_ == NULL) { | 118 if (setuid_sandbox_client_ == NULL) { |
114 LOG(FATAL) << "Failed to instantiate the setuid sandbox client."; | 119 LOG(FATAL) << "Failed to instantiate the setuid sandbox client."; |
115 } | 120 } |
116 } | 121 } |
117 | 122 |
118 LinuxSandbox::~LinuxSandbox() { | 123 LinuxSandbox::~LinuxSandbox() { |
119 } | 124 } |
120 | 125 |
121 LinuxSandbox* LinuxSandbox::GetInstance() { | 126 LinuxSandbox* LinuxSandbox::GetInstance() { |
122 LinuxSandbox* instance = Singleton<LinuxSandbox>::get(); | 127 LinuxSandbox* instance = Singleton<LinuxSandbox>::get(); |
123 CHECK(instance); | 128 CHECK(instance); |
124 return instance; | 129 return instance; |
125 } | 130 } |
126 | 131 |
127 #if (defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \ | 132 #if (defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \ |
128 defined(LEAK_SANITIZER)) && defined(OS_LINUX) | 133 defined(LEAK_SANITIZER)) && defined(OS_LINUX) |
129 // Sanitizer API call to notify the tool the sandbox is going to be turned on. | 134 // 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); | 135 extern "C" void __sanitizer_sandbox_on_notify(void *reserved); |
136 | |
137 void LinuxSandbox::SetSanitizerArgs(void *sanitizer_args) { | |
jln (very slow on Chromium)
2014/05/13 01:17:35
style: "void* blah".
jln (very slow on Chromium)
2014/05/13 01:17:35
Let's respect the order of declarations in the hea
earthdok
2014/05/14 17:00:26
Done.
earthdok
2014/05/14 17:00:26
Done.
| |
138 sanitizer_args_ = sanitizer_args; | |
139 } | |
131 #endif | 140 #endif |
132 | 141 |
133 void LinuxSandbox::PreinitializeSandbox() { | 142 void LinuxSandbox::PreinitializeSandbox() { |
134 CHECK(!pre_initialized_); | 143 CHECK(!pre_initialized_); |
135 seccomp_bpf_supported_ = false; | 144 seccomp_bpf_supported_ = false; |
136 #if (defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \ | 145 #if (defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \ |
137 defined(LEAK_SANITIZER)) && defined(OS_LINUX) | 146 defined(LEAK_SANITIZER)) && defined(OS_LINUX) |
138 // Sanitizers need to open some resources before the sandbox is enabled. | 147 // Sanitizers need to open some resources before the sandbox is enabled. |
139 // This should not fork, not launch threads, not open a directory. | 148 // This should not fork, not launch threads, not open a directory. |
140 __sanitizer_sandbox_on_notify(/*reserved*/ NULL); | 149 __sanitizer_sandbox_on_notify(sanitizer_args_); |
141 #endif | 150 #endif |
142 | 151 |
143 #if !defined(NDEBUG) | 152 #if !defined(NDEBUG) |
144 // The in-process stack dumping needs to open /proc/self/maps and cache | 153 // 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 | 154 // its contents before the sandbox is enabled. It also pre-opens the |
146 // object files that are already loaded in the process address space. | 155 // object files that are already loaded in the process address space. |
147 base::debug::EnableInProcessStackDumpingForSandbox(); | 156 base::debug::EnableInProcessStackDumpingForSandbox(); |
148 | 157 |
149 // Open proc_fd_ only in Debug mode so that forgetting to close it doesn't | 158 // Open proc_fd_ only in Debug mode so that forgetting to close it doesn't |
150 // produce a sandbox escape in Release mode. | 159 // produce a sandbox escape in Release mode. |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
404 | 413 |
405 void LinuxSandbox::StopThreadAndEnsureNotCounted(base::Thread* thread) const { | 414 void LinuxSandbox::StopThreadAndEnsureNotCounted(base::Thread* thread) const { |
406 DCHECK(thread); | 415 DCHECK(thread); |
407 base::ScopedFD proc_self_task(OpenProcTaskFd(proc_fd_)); | 416 base::ScopedFD proc_self_task(OpenProcTaskFd(proc_fd_)); |
408 PCHECK(proc_self_task.is_valid()); | 417 PCHECK(proc_self_task.is_valid()); |
409 CHECK(sandbox::ThreadHelpers::StopThreadAndWatchProcFS(proc_self_task.get(), | 418 CHECK(sandbox::ThreadHelpers::StopThreadAndWatchProcFS(proc_self_task.get(), |
410 thread)); | 419 thread)); |
411 } | 420 } |
412 | 421 |
413 } // namespace content | 422 } // namespace content |
OLD | NEW |