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

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

Issue 286363003: Non-SFI NaCl: Disallow fancy clock IDs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Respond to mseaborn@ feedback 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
« no previous file with comments | « components/nacl/loader/nonsfi/nonsfi_sandbox.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // ASan internally uses some syscalls which non-SFI NaCl disallows. 5 // ASan internally uses some syscalls which non-SFI NaCl disallows.
6 // Seccomp-BPF tests die under TSan v2. See http://crbug.com/356588 6 // Seccomp-BPF tests die under TSan v2. See http://crbug.com/356588
7 #if !defined(ADDRESS_SANITIZER) && !defined(THREAD_SANITIZER) 7 #if !defined(ADDRESS_SANITIZER) && !defined(THREAD_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 <pthread.h> 13 #include <pthread.h>
14 #include <sched.h> 14 #include <sched.h>
15 #include <signal.h> 15 #include <signal.h>
16 #include <stdlib.h> 16 #include <stdlib.h>
17 #include <string.h> 17 #include <string.h>
18 #include <sys/mman.h> 18 #include <sys/mman.h>
19 #include <sys/prctl.h> 19 #include <sys/prctl.h>
20 #include <sys/ptrace.h> 20 #include <sys/ptrace.h>
21 #include <sys/socket.h> 21 #include <sys/socket.h>
22 #include <sys/syscall.h> 22 #include <sys/syscall.h>
23 #include <sys/types.h> 23 #include <sys/types.h>
24 #include <sys/wait.h> 24 #include <sys/wait.h>
25 #include <time.h>
25 #include <unistd.h> 26 #include <unistd.h>
26 27
27 #include "base/bind.h" 28 #include "base/bind.h"
28 #include "base/callback.h" 29 #include "base/callback.h"
29 #include "base/compiler_specific.h" 30 #include "base/compiler_specific.h"
30 #include "base/files/scoped_file.h" 31 #include "base/files/scoped_file.h"
31 #include "base/logging.h" 32 #include "base/logging.h"
32 #include "base/posix/eintr_wrapper.h" 33 #include "base/posix/eintr_wrapper.h"
33 #include "sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h" 34 #include "sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h"
34 #include "sandbox/linux/seccomp-bpf/bpf_tests.h" 35 #include "sandbox/linux/seccomp-bpf/bpf_tests.h"
36 #include "third_party/lss/linux_syscall_support.h" // for MAKE_PROCESS_CPUCLOCK
35 37
36 namespace { 38 namespace {
37 39
38 void DoPipe(base::ScopedFD* fds) { 40 void DoPipe(base::ScopedFD* fds) {
39 int tmp_fds[2]; 41 int tmp_fds[2];
40 BPF_ASSERT_EQ(0, pipe(tmp_fds)); 42 BPF_ASSERT_EQ(0, pipe(tmp_fds));
41 fds[0].reset(tmp_fds[0]); 43 fds[0].reset(tmp_fds[0]);
42 fds[1].reset(tmp_fds[1]); 44 fds[1].reset(tmp_fds[1]);
43 } 45 }
44 46
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { 386 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) {
385 char* next_brk = static_cast<char*>(sbrk(0)) + getpagesize(); 387 char* next_brk = static_cast<char*>(sbrk(0)) + getpagesize();
386 // The kernel interface must return zero for brk. 388 // The kernel interface must return zero for brk.
387 BPF_ASSERT_EQ(0, syscall(__NR_brk, next_brk)); 389 BPF_ASSERT_EQ(0, syscall(__NR_brk, next_brk));
388 // The libc wrapper translates it to ENOMEM. 390 // The libc wrapper translates it to ENOMEM.
389 errno = 0; 391 errno = 0;
390 BPF_ASSERT_EQ(-1, brk(next_brk)); 392 BPF_ASSERT_EQ(-1, brk(next_brk));
391 BPF_ASSERT_EQ(ENOMEM, errno); 393 BPF_ASSERT_EQ(ENOMEM, errno);
392 } 394 }
393 395
396 void CheckClock(clockid_t clockid) {
397 struct timespec ts;
398 ts.tv_sec = ts.tv_nsec = -1;
399 BPF_ASSERT_EQ(0, clock_gettime(clockid, &ts));
400 BPF_ASSERT_LE(0, ts.tv_sec);
401 BPF_ASSERT_LE(0, ts.tv_nsec);
402 }
403
404 BPF_TEST_C(NaClNonSfiSandboxTest,
405 clock_gettime_allowed,
406 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) {
407 CheckClock(CLOCK_MONOTONIC);
408 CheckClock(CLOCK_PROCESS_CPUTIME_ID);
409 CheckClock(CLOCK_REALTIME);
410 CheckClock(CLOCK_THREAD_CPUTIME_ID);
411 }
412
413 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest,
414 clock_gettime_crash_monotonic_raw,
415 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()),
416 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) {
417 struct timespec ts;
418 clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
419 }
420
421 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest,
422 clock_gettime_crash_cpu_clock,
423 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()),
424 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) {
425 // We can't use clock_getcpuclockid() because it's not implemented in newlib,
426 // and it might not work inside the sandbox anyway.
427 const pid_t kInitPID = 1;
428 const clockid_t kInitCPUClockID =
429 MAKE_PROCESS_CPUCLOCK(kInitPID, CPUCLOCK_SCHED);
430
431 struct timespec ts;
432 clock_gettime(kInitCPUClockID, &ts);
433 }
434
394 // The following test cases check if syscalls return EPERM regardless 435 // The following test cases check if syscalls return EPERM regardless
395 // of arguments. 436 // of arguments.
396 #define RESTRICT_SYSCALL_EPERM_TEST(name) \ 437 #define RESTRICT_SYSCALL_EPERM_TEST(name) \
397 BPF_TEST_C(NaClNonSfiSandboxTest, \ 438 BPF_TEST_C(NaClNonSfiSandboxTest, \
398 name##_EPERM, \ 439 name##_EPERM, \
399 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { \ 440 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { \
400 errno = 0; \ 441 errno = 0; \
401 BPF_ASSERT_EQ(-1, syscall(__NR_##name, 0, 0, 0, 0, 0, 0)); \ 442 BPF_ASSERT_EQ(-1, syscall(__NR_##name, 0, 0, 0, 0, 0, 0)); \
402 BPF_ASSERT_EQ(EPERM, errno); \ 443 BPF_ASSERT_EQ(EPERM, errno); \
403 } 444 }
(...skipping 13 matching lines...) Expand all
417 RESTRICT_SYSCALL_EPERM_TEST(open); 458 RESTRICT_SYSCALL_EPERM_TEST(open);
418 RESTRICT_SYSCALL_EPERM_TEST(ptrace); 459 RESTRICT_SYSCALL_EPERM_TEST(ptrace);
419 RESTRICT_SYSCALL_EPERM_TEST(set_robust_list); 460 RESTRICT_SYSCALL_EPERM_TEST(set_robust_list);
420 #if defined(__i386__) || defined(__x86_64__) 461 #if defined(__i386__) || defined(__x86_64__)
421 RESTRICT_SYSCALL_EPERM_TEST(time); 462 RESTRICT_SYSCALL_EPERM_TEST(time);
422 #endif 463 #endif
423 464
424 } // namespace 465 } // namespace
425 466
426 #endif // !ADDRESS_SANITIZER && !THREAD_SANITIZER 467 #endif // !ADDRESS_SANITIZER && !THREAD_SANITIZER
OLDNEW
« no previous file with comments | « components/nacl/loader/nonsfi/nonsfi_sandbox.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698