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

Side by Side Diff: components/nacl/loader/nonsfi/nonsfi_sandbox_unittest.cc

Issue 549653002: NonSFI sandbox: restrict futex(2) operations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 // Sanitizers internally use some syscalls which non-SFI NaCl disallows. 5 // Sanitizers internally use some syscalls which non-SFI NaCl disallows.
6 #if !defined(ADDRESS_SANITIZER) && !defined(THREAD_SANITIZER) && \ 6 #if !defined(ADDRESS_SANITIZER) && !defined(THREAD_SANITIZER) && \
7 !defined(MEMORY_SANITIZER) && !defined(LEAK_SANITIZER) 7 !defined(MEMORY_SANITIZER) && !defined(LEAK_SANITIZER)
8 8
9 #include "components/nacl/loader/nonsfi/nonsfi_sandbox.h" 9 #include "components/nacl/loader/nonsfi/nonsfi_sandbox.h"
10 10
11 #include <errno.h> 11 #include <errno.h>
12 #include <fcntl.h> 12 #include <fcntl.h>
13 #include <linux/futex.h>
13 #include <pthread.h> 14 #include <pthread.h>
14 #include <sched.h> 15 #include <sched.h>
15 #include <signal.h> 16 #include <signal.h>
16 #include <stdlib.h> 17 #include <stdlib.h>
17 #include <string.h> 18 #include <string.h>
18 #include <sys/mman.h> 19 #include <sys/mman.h>
19 #include <sys/prctl.h> 20 #include <sys/prctl.h>
20 #include <sys/ptrace.h> 21 #include <sys/ptrace.h>
21 #include <sys/socket.h> 22 #include <sys/socket.h>
22 #include <sys/syscall.h> 23 #include <sys/syscall.h>
23 #include <sys/types.h> 24 #include <sys/types.h>
24 #include <sys/wait.h> 25 #include <sys/wait.h>
25 #include <time.h> 26 #include <time.h>
26 #include <unistd.h> 27 #include <unistd.h>
27 28
28 #include "base/bind.h" 29 #include "base/bind.h"
29 #include "base/callback.h" 30 #include "base/callback.h"
30 #include "base/compiler_specific.h" 31 #include "base/compiler_specific.h"
31 #include "base/files/scoped_file.h" 32 #include "base/files/scoped_file.h"
32 #include "base/logging.h" 33 #include "base/logging.h"
33 #include "base/posix/eintr_wrapper.h" 34 #include "base/posix/eintr_wrapper.h"
34 #include "base/sys_info.h" 35 #include "base/sys_info.h"
36 #include "base/threading/thread.h"
35 #include "base/time/time.h" 37 #include "base/time/time.h"
36 #include "sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h" 38 #include "sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h"
37 #include "sandbox/linux/seccomp-bpf/bpf_tests.h" 39 #include "sandbox/linux/seccomp-bpf/bpf_tests.h"
38 #include "sandbox/linux/seccomp-bpf/syscall.h" 40 #include "sandbox/linux/seccomp-bpf/syscall.h"
39 #include "sandbox/linux/services/linux_syscalls.h" 41 #include "sandbox/linux/services/linux_syscalls.h"
40 #include "third_party/lss/linux_syscall_support.h" // for MAKE_PROCESS_CPUCLOCK 42 #include "third_party/lss/linux_syscall_support.h" // for MAKE_PROCESS_CPUCLOCK
41 43
42 namespace { 44 namespace {
43 45
44 void DoPipe(base::ScopedFD* fds) { 46 void DoPipe(base::ScopedFD* fds) {
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 fcntl(0, F_DUPFD); 301 fcntl(0, F_DUPFD);
300 } 302 }
301 303
302 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, 304 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest,
303 fcntl_DUPFD_CLOEXEC, 305 fcntl_DUPFD_CLOEXEC,
304 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), 306 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()),
305 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { 307 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) {
306 fcntl(0, F_DUPFD_CLOEXEC); 308 fcntl(0, F_DUPFD_CLOEXEC);
307 } 309 }
308 310
311 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest,
312 FutexWithRequeuePriorityInheritence,
313 DEATH_MESSAGE(sandbox::GetFutexErrorMessageContentForTests()),
314 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) {
315 syscall(__NR_futex, NULL, FUTEX_CMP_REQUEUE_PI, 0, NULL, NULL, 0);
316 _exit(1);
317 }
318
319 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest,
320 FutexWithRequeuePriorityInheritencePrivate,
321 DEATH_MESSAGE(sandbox::GetFutexErrorMessageContentForTests()),
322 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) {
323 syscall(__NR_futex, NULL, FUTEX_CMP_REQUEUE_PI_PRIVATE, 0, NULL, NULL, 0);
324 _exit(1);
325 }
326
327 BPF_TEST_C(NaClNonSfiSandboxTest,
328 StartingAndJoiningThreadWorks,
329 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) {
330 base::Thread thread("sandbox_tests");
Mark Seaborn 2014/09/06 00:36:47 Nit: fix indentation. You might want to comment t
jln (very slow on Chromium) 2014/09/06 00:45:37 Done.
331 BPF_ASSERT(thread.Start());
332 }
333
334 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest,
335 FutexWithUnlockPIPrivate,
336 DEATH_MESSAGE(sandbox::GetFutexErrorMessageContentForTests()),
337 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) {
338 syscall(__NR_futex, NULL, FUTEX_UNLOCK_PI_PRIVATE, 0, NULL, NULL, 0);
339 _exit(1);
340 }
341
309 void* DoAllowedAnonymousMmap() { 342 void* DoAllowedAnonymousMmap() {
310 return mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, 343 return mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE,
311 MAP_ANONYMOUS | MAP_SHARED, -1, 0); 344 MAP_ANONYMOUS | MAP_SHARED, -1, 0);
312 } 345 }
313 346
314 BPF_TEST_C(NaClNonSfiSandboxTest, 347 BPF_TEST_C(NaClNonSfiSandboxTest,
315 mmap_allowed, 348 mmap_allowed,
316 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { 349 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) {
317 void* ptr = DoAllowedAnonymousMmap(); 350 void* ptr = DoAllowedAnonymousMmap();
318 BPF_ASSERT_NE(MAP_FAILED, ptr); 351 BPF_ASSERT_NE(MAP_FAILED, ptr);
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 RESTRICT_SYSCALL_EPERM_TEST(ptrace); 551 RESTRICT_SYSCALL_EPERM_TEST(ptrace);
519 RESTRICT_SYSCALL_EPERM_TEST(set_robust_list); 552 RESTRICT_SYSCALL_EPERM_TEST(set_robust_list);
520 #if defined(__i386__) || defined(__x86_64__) 553 #if defined(__i386__) || defined(__x86_64__)
521 RESTRICT_SYSCALL_EPERM_TEST(time); 554 RESTRICT_SYSCALL_EPERM_TEST(time);
522 #endif 555 #endif
523 556
524 } // namespace 557 } // namespace
525 558
526 #endif // !ADDRESS_SANITIZER && !THREAD_SANITIZER && 559 #endif // !ADDRESS_SANITIZER && !THREAD_SANITIZER &&
527 // !MEMORY_SANITIZER && !LEAK_SANITIZER 560 // !MEMORY_SANITIZER && !LEAK_SANITIZER
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698