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 <errno.h> | 5 #include <errno.h> |
6 #include <pthread.h> | 6 #include <pthread.h> |
7 #include <sched.h> | 7 #include <sched.h> |
8 #include <signal.h> | 8 #include <signal.h> |
9 #include <sys/prctl.h> | 9 #include <sys/prctl.h> |
10 #include <sys/ptrace.h> | 10 #include <sys/ptrace.h> |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #endif | 21 #endif |
22 #include <linux/futex.h> | 22 #include <linux/futex.h> |
23 | 23 |
24 #include <ostream> | 24 #include <ostream> |
25 | 25 |
26 #include "base/bind.h" | 26 #include "base/bind.h" |
27 #include "base/logging.h" | 27 #include "base/logging.h" |
28 #include "base/macros.h" | 28 #include "base/macros.h" |
29 #include "base/memory/scoped_ptr.h" | 29 #include "base/memory/scoped_ptr.h" |
30 #include "base/posix/eintr_wrapper.h" | 30 #include "base/posix/eintr_wrapper.h" |
31 #include "base/synchronization/waitable_event.h" | |
31 #include "build/build_config.h" | 32 #include "build/build_config.h" |
32 #include "sandbox/linux/seccomp-bpf/bpf_tests.h" | 33 #include "sandbox/linux/seccomp-bpf/bpf_tests.h" |
33 #include "sandbox/linux/seccomp-bpf/syscall.h" | 34 #include "sandbox/linux/seccomp-bpf/syscall.h" |
34 #include "sandbox/linux/seccomp-bpf/trap.h" | 35 #include "sandbox/linux/seccomp-bpf/trap.h" |
35 #include "sandbox/linux/seccomp-bpf/verifier.h" | 36 #include "sandbox/linux/seccomp-bpf/verifier.h" |
36 #include "sandbox/linux/services/broker_process.h" | 37 #include "sandbox/linux/services/broker_process.h" |
37 #include "sandbox/linux/services/linux_syscalls.h" | 38 #include "sandbox/linux/services/linux_syscalls.h" |
38 #include "sandbox/linux/tests/scoped_temporary_file.h" | 39 #include "sandbox/linux/tests/scoped_temporary_file.h" |
39 #include "sandbox/linux/tests/unit_tests.h" | 40 #include "sandbox/linux/tests/unit_tests.h" |
40 #include "testing/gtest/include/gtest/gtest.h" | 41 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 2097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2138 BPF_ASSERT(FullPread64(temp_file.fd(), | 2139 BPF_ASSERT(FullPread64(temp_file.fd(), |
2139 read_test_string, | 2140 read_test_string, |
2140 sizeof(read_test_string), | 2141 sizeof(read_test_string), |
2141 kLargeOffset)); | 2142 kLargeOffset)); |
2142 BPF_ASSERT_EQ(0, memcmp(kTestString, read_test_string, sizeof(kTestString))); | 2143 BPF_ASSERT_EQ(0, memcmp(kTestString, read_test_string, sizeof(kTestString))); |
2143 BPF_ASSERT(pread_64_was_forwarded); | 2144 BPF_ASSERT(pread_64_was_forwarded); |
2144 } | 2145 } |
2145 | 2146 |
2146 #endif // !defined(OS_ANDROID) | 2147 #endif // !defined(OS_ANDROID) |
2147 | 2148 |
2149 void* TsyncApplyToTwoThreadsFunc(void* cond_ptr) { | |
2150 base::WaitableEvent* event = static_cast<base::WaitableEvent*>(cond_ptr); | |
2151 | |
2152 // Wait for the main thread to signal that the filter has been applied. | |
2153 if (!event->IsSignaled()) { | |
2154 event->Wait(); | |
2155 } | |
2156 | |
2157 BPF_ASSERT(event->IsSignaled()); | |
2158 | |
2159 // Nanosleep is now blacklisted, so this should fail. | |
jln (very slow on Chromium)
2014/08/20 21:34:20
I would split that into a separate NanoSleepFails(
Robert Sesek
2014/08/21 16:50:18
Done.
| |
2160 const struct timespec ts = {0, 0}; | |
2161 errno = 0; | |
2162 BPF_ASSERT(syscall(__NR_nanosleep, &ts, NULL) == -1); | |
2163 BPF_ASSERT(errno == EACCES); | |
2164 | |
2165 return NULL; | |
2166 } | |
2167 | |
2168 TEST(SandboxBPF, Tsync) { | |
jln (very slow on Chromium)
2014/08/20 21:34:21
We should not write tests that affects the current
Robert Sesek
2014/08/21 16:50:18
Done.
| |
2169 if (SandboxBPF::SupportsSeccompThreadFilterSynchronization() != | |
2170 SandboxBPF::STATUS_AVAILABLE) { | |
2171 LOG(INFO) << "Skipping test: tsync unavailable"; | |
2172 return; | |
2173 } | |
2174 | |
2175 base::WaitableEvent event(true, false); | |
2176 | |
2177 // Create a thread on which to invoke the blocked syscall. | |
2178 pthread_t thread; | |
2179 BPF_ASSERT_EQ(0, | |
2180 pthread_create(&thread, NULL, &TsyncApplyToTwoThreadsFunc, &event)); | |
2181 | |
2182 // Engage the sandbox. | |
2183 SandboxBPF sandbox; | |
2184 sandbox.SetSandboxPolicy(new BlacklistNanosleepPolicy()); | |
2185 BPF_ASSERT(sandbox.StartSandbox(SandboxBPF::PROCESS_MULTI_THREADED)); | |
2186 | |
2187 // Signal the condition to invoke the system call. | |
2188 event.Signal(); | |
2189 | |
2190 // Wait for the thread to finish. | |
2191 BPF_ASSERT_EQ(0, pthread_join(thread, NULL)); | |
2192 } | |
2193 | |
jln (very slow on Chromium)
2014/08/20 21:34:20
If you feel like writing more tests, I think a dea
Robert Sesek
2014/08/21 16:50:18
Depending on the discussion around the other comme
| |
2148 } // namespace | 2194 } // namespace |
2149 | 2195 |
2150 } // namespace sandbox | 2196 } // namespace sandbox |
OLD | NEW |