Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 384 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | 385 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
| 385 char* next_brk = static_cast<char*>(sbrk(0)) + getpagesize(); | 386 char* next_brk = static_cast<char*>(sbrk(0)) + getpagesize(); |
| 386 // The kernel interface must return zero for brk. | 387 // The kernel interface must return zero for brk. |
| 387 BPF_ASSERT_EQ(0, syscall(__NR_brk, next_brk)); | 388 BPF_ASSERT_EQ(0, syscall(__NR_brk, next_brk)); |
| 388 // The libc wrapper translates it to ENOMEM. | 389 // The libc wrapper translates it to ENOMEM. |
| 389 errno = 0; | 390 errno = 0; |
| 390 BPF_ASSERT_EQ(-1, brk(next_brk)); | 391 BPF_ASSERT_EQ(-1, brk(next_brk)); |
| 391 BPF_ASSERT_EQ(ENOMEM, errno); | 392 BPF_ASSERT_EQ(ENOMEM, errno); |
| 392 } | 393 } |
| 393 | 394 |
| 395 void CheckClock(clockid_t clockid) { | |
| 396 struct timespec ts; | |
| 397 ts.tv_sec = ts.tv_nsec = -1; | |
| 398 BPF_ASSERT_EQ(0, clock_gettime(clockid, &ts)); | |
| 399 BPF_ASSERT_LE(0, ts.tv_sec); | |
| 400 BPF_ASSERT_LE(0, ts.tv_nsec); | |
| 401 } | |
| 402 | |
| 403 BPF_TEST_C(NaClNonSfiSandboxTest, | |
| 404 clock_gettime_allowed, | |
| 405 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | |
| 406 CheckClock(CLOCK_MONOTONIC); | |
| 407 CheckClock(CLOCK_PROCESS_CPUTIME_ID); | |
| 408 CheckClock(CLOCK_REALTIME); | |
| 409 CheckClock(CLOCK_THREAD_CPUTIME_ID); | |
| 410 } | |
| 411 | |
| 412 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, | |
| 413 clock_gettime_crash_monotonic_raw, | |
| 414 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), | |
| 415 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | |
| 416 struct timespec ts; | |
| 417 clock_gettime(CLOCK_MONOTONIC_RAW, &ts); | |
| 418 } | |
| 419 | |
| 420 // We need this test delegate so we can compute the clock ID for the init | |
|
Mark Seaborn
2014/05/20 21:21:30
You might also test this by constructing the clock
mdempsky
2014/05/20 23:02:51
Done. I found that LSS has the same MAKE_PROCESS_
| |
| 421 // process's CPU clock before enabling the seccomp-BPF policy. | |
| 422 class ClockGetTimeCrashCPUClockDelegate : public sandbox::BPFTesterDelegate { | |
| 423 public: | |
| 424 ClockGetTimeCrashCPUClockDelegate() { | |
| 425 const pid_t kInitPID = 1; | |
| 426 CHECK_EQ(0, clock_getcpuclockid(kInitPID, &init_clock_id_)); | |
| 427 } | |
| 428 | |
| 429 virtual scoped_ptr<sandbox::SandboxBPFPolicy> GetSandboxBPFPolicy() OVERRIDE { | |
| 430 return scoped_ptr<sandbox::SandboxBPFPolicy>( | |
| 431 new nacl::nonsfi::NaClNonSfiBPFSandboxPolicy); | |
| 432 } | |
| 433 | |
| 434 virtual void RunTestFunction() OVERRIDE { | |
| 435 struct timespec ts; | |
| 436 clock_gettime(init_clock_id_, &ts); | |
| 437 } | |
| 438 | |
| 439 private: | |
| 440 clockid_t init_clock_id_; | |
| 441 }; | |
| 442 | |
| 443 BPF_DEATH_TEST_D(NaClNonSfiSandboxTest, | |
| 444 clock_gettime_crash_cpu_clock, | |
| 445 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), | |
| 446 ClockGetTimeCrashCPUClockDelegate); | |
| 447 | |
| 394 // The following test cases check if syscalls return EPERM regardless | 448 // The following test cases check if syscalls return EPERM regardless |
| 395 // of arguments. | 449 // of arguments. |
| 396 #define RESTRICT_SYSCALL_EPERM_TEST(name) \ | 450 #define RESTRICT_SYSCALL_EPERM_TEST(name) \ |
| 397 BPF_TEST_C(NaClNonSfiSandboxTest, \ | 451 BPF_TEST_C(NaClNonSfiSandboxTest, \ |
| 398 name##_EPERM, \ | 452 name##_EPERM, \ |
| 399 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { \ | 453 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { \ |
| 400 errno = 0; \ | 454 errno = 0; \ |
| 401 BPF_ASSERT_EQ(-1, syscall(__NR_##name, 0, 0, 0, 0, 0, 0)); \ | 455 BPF_ASSERT_EQ(-1, syscall(__NR_##name, 0, 0, 0, 0, 0, 0)); \ |
| 402 BPF_ASSERT_EQ(EPERM, errno); \ | 456 BPF_ASSERT_EQ(EPERM, errno); \ |
| 403 } | 457 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 417 RESTRICT_SYSCALL_EPERM_TEST(open); | 471 RESTRICT_SYSCALL_EPERM_TEST(open); |
| 418 RESTRICT_SYSCALL_EPERM_TEST(ptrace); | 472 RESTRICT_SYSCALL_EPERM_TEST(ptrace); |
| 419 RESTRICT_SYSCALL_EPERM_TEST(set_robust_list); | 473 RESTRICT_SYSCALL_EPERM_TEST(set_robust_list); |
| 420 #if defined(__i386__) || defined(__x86_64__) | 474 #if defined(__i386__) || defined(__x86_64__) |
| 421 RESTRICT_SYSCALL_EPERM_TEST(time); | 475 RESTRICT_SYSCALL_EPERM_TEST(time); |
| 422 #endif | 476 #endif |
| 423 | 477 |
| 424 } // namespace | 478 } // namespace |
| 425 | 479 |
| 426 #endif // !ADDRESS_SANITIZER && !THREAD_SANITIZER | 480 #endif // !ADDRESS_SANITIZER && !THREAD_SANITIZER |
| OLD | NEW |