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

Unified Diff: sandbox/linux/seccomp-bpf/sandbox_bpf_unittest.cc

Issue 494743003: sandbox: Add support for the new seccomp() system call in kernel 3.17. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: sandbox/linux/seccomp-bpf/sandbox_bpf_unittest.cc
diff --git a/sandbox/linux/seccomp-bpf/sandbox_bpf_unittest.cc b/sandbox/linux/seccomp-bpf/sandbox_bpf_unittest.cc
index c25d6cf61141fceb8c933b0581cf2c57ac5d7dd6..362c1b2a5afe8533beac375f19797d4c0d9ca4d2 100644
--- a/sandbox/linux/seccomp-bpf/sandbox_bpf_unittest.cc
+++ b/sandbox/linux/seccomp-bpf/sandbox_bpf_unittest.cc
@@ -28,6 +28,7 @@
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/posix/eintr_wrapper.h"
+#include "base/synchronization/waitable_event.h"
#include "build/build_config.h"
#include "sandbox/linux/seccomp-bpf/bpf_tests.h"
#include "sandbox/linux/seccomp-bpf/syscall.h"
@@ -2145,6 +2146,51 @@ BPF_TEST_C(SandboxBPF, Pread64, TrapPread64Policy) {
#endif // !defined(OS_ANDROID)
+void* TsyncApplyToTwoThreadsFunc(void* cond_ptr) {
+ base::WaitableEvent* event = static_cast<base::WaitableEvent*>(cond_ptr);
+
+ // Wait for the main thread to signal that the filter has been applied.
+ if (!event->IsSignaled()) {
+ event->Wait();
+ }
+
+ BPF_ASSERT(event->IsSignaled());
+
+ // 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.
+ const struct timespec ts = {0, 0};
+ errno = 0;
+ BPF_ASSERT(syscall(__NR_nanosleep, &ts, NULL) == -1);
+ BPF_ASSERT(errno == EACCES);
+
+ return NULL;
+}
+
+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.
+ if (SandboxBPF::SupportsSeccompThreadFilterSynchronization() !=
+ SandboxBPF::STATUS_AVAILABLE) {
+ LOG(INFO) << "Skipping test: tsync unavailable";
+ return;
+ }
+
+ base::WaitableEvent event(true, false);
+
+ // Create a thread on which to invoke the blocked syscall.
+ pthread_t thread;
+ BPF_ASSERT_EQ(0,
+ pthread_create(&thread, NULL, &TsyncApplyToTwoThreadsFunc, &event));
+
+ // Engage the sandbox.
+ SandboxBPF sandbox;
+ sandbox.SetSandboxPolicy(new BlacklistNanosleepPolicy());
+ BPF_ASSERT(sandbox.StartSandbox(SandboxBPF::PROCESS_MULTI_THREADED));
+
+ // Signal the condition to invoke the system call.
+ event.Signal();
+
+ // Wait for the thread to finish.
+ BPF_ASSERT_EQ(0, pthread_join(thread, NULL));
+}
+
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
} // namespace
} // namespace sandbox

Powered by Google App Engine
This is Rietveld 408576698