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 BPF_TEST_C(NaClNonSfiSandboxTest, | |
396 clock_gettime_allowed, | |
397 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | |
398 struct timespec ts; | |
399 BPF_ASSERT_EQ(0, clock_gettime(CLOCK_MONOTONIC, &ts)); | |
hamaji
2014/05/19 05:54:11
Maybe better to check if |ts| is filled.
mdempsky
2014/05/19 06:59:22
Done.
| |
400 BPF_ASSERT_EQ(0, clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts)); | |
401 BPF_ASSERT_EQ(0, clock_gettime(CLOCK_REALTIME, &ts)); | |
402 BPF_ASSERT_EQ(0, clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts)); | |
403 } | |
404 | |
405 class ClockGetTimeCrashCPUClockDelegate : public sandbox::BPFTesterDelegate { | |
hamaji
2014/05/19 05:54:11
Could you add a brief comment to explain why we ne
mdempsky
2014/05/19 06:59:22
Done.
| |
406 public: | |
407 ClockGetTimeCrashCPUClockDelegate() { | |
408 const pid_t kInitPID = 1; | |
409 CHECK_EQ(0, clock_getcpuclockid(kInitPID, &init_clock_id_)); | |
410 } | |
411 | |
412 virtual scoped_ptr<sandbox::SandboxBPFPolicy> GetSandboxBPFPolicy() OVERRIDE { | |
413 return scoped_ptr<sandbox::SandboxBPFPolicy>( | |
414 new nacl::nonsfi::NaClNonSfiBPFSandboxPolicy); | |
415 } | |
416 | |
417 virtual void RunTestFunction() OVERRIDE { | |
418 struct timespec ts; | |
419 clock_gettime(init_clock_id_, &ts); | |
420 } | |
421 | |
422 private: | |
423 clockid_t init_clock_id_; | |
424 }; | |
425 | |
426 BPF_DEATH_TEST_D(NaClNonSfiSandboxTest, | |
427 clock_gettime_crash_cpu_clock, | |
428 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), | |
429 ClockGetTimeCrashCPUClockDelegate); | |
hamaji
2014/05/19 05:54:11
I think you can also test CLOCK_MONOTONIC_RAW
mdempsky
2014/05/19 06:59:22
Done.
| |
430 | |
394 // The following test cases check if syscalls return EPERM regardless | 431 // The following test cases check if syscalls return EPERM regardless |
395 // of arguments. | 432 // of arguments. |
396 #define RESTRICT_SYSCALL_EPERM_TEST(name) \ | 433 #define RESTRICT_SYSCALL_EPERM_TEST(name) \ |
397 BPF_TEST_C(NaClNonSfiSandboxTest, \ | 434 BPF_TEST_C(NaClNonSfiSandboxTest, \ |
398 name##_EPERM, \ | 435 name##_EPERM, \ |
399 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { \ | 436 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { \ |
400 errno = 0; \ | 437 errno = 0; \ |
401 BPF_ASSERT_EQ(-1, syscall(__NR_##name, 0, 0, 0, 0, 0, 0)); \ | 438 BPF_ASSERT_EQ(-1, syscall(__NR_##name, 0, 0, 0, 0, 0, 0)); \ |
402 BPF_ASSERT_EQ(EPERM, errno); \ | 439 BPF_ASSERT_EQ(EPERM, errno); \ |
403 } | 440 } |
(...skipping 13 matching lines...) Expand all Loading... | |
417 RESTRICT_SYSCALL_EPERM_TEST(open); | 454 RESTRICT_SYSCALL_EPERM_TEST(open); |
418 RESTRICT_SYSCALL_EPERM_TEST(ptrace); | 455 RESTRICT_SYSCALL_EPERM_TEST(ptrace); |
419 RESTRICT_SYSCALL_EPERM_TEST(set_robust_list); | 456 RESTRICT_SYSCALL_EPERM_TEST(set_robust_list); |
420 #if defined(__i386__) || defined(__x86_64__) | 457 #if defined(__i386__) || defined(__x86_64__) |
421 RESTRICT_SYSCALL_EPERM_TEST(time); | 458 RESTRICT_SYSCALL_EPERM_TEST(time); |
422 #endif | 459 #endif |
423 | 460 |
424 } // namespace | 461 } // namespace |
425 | 462 |
426 #endif // !ADDRESS_SANITIZER && !THREAD_SANITIZER | 463 #endif // !ADDRESS_SANITIZER && !THREAD_SANITIZER |
OLD | NEW |