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 // 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 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 } | 193 } |
| 194 | 194 |
| 195 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, | 195 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, |
| 196 prctl_SET_DUMPABLE, | 196 prctl_SET_DUMPABLE, |
| 197 DEATH_SEGV_MESSAGE( | 197 DEATH_SEGV_MESSAGE( |
| 198 sandbox::GetPrctlErrorMessageContentForTests()), | 198 sandbox::GetPrctlErrorMessageContentForTests()), |
| 199 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | 199 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
| 200 syscall(__NR_prctl, PR_SET_DUMPABLE, 1UL); | 200 syscall(__NR_prctl, PR_SET_DUMPABLE, 1UL); |
| 201 } | 201 } |
| 202 | 202 |
| 203 #if defined(OS_NACL_NONSFI) | |
| 204 BPF_DEATH_TEST_C(NaClNonsfiSandboxTest, | 203 BPF_DEATH_TEST_C(NaClNonsfiSandboxTest, |
| 205 socketpair_af_unix_disallowed, | 204 socketpair_af_unix_disallowed, |
| 206 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), | 205 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), |
| 207 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | 206 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
| 208 int tmp_fds[2]; | 207 int tmp_fds[2]; |
| 209 socketpair(AF_UNIX, SOCK_STREAM, 0, tmp_fds); | 208 socketpair(AF_UNIX, SOCK_STREAM, 0, tmp_fds); |
| 210 } | 209 } |
| 211 #else | |
| 212 BPF_TEST_C(NaClNonSfiSandboxTest, | |
| 213 socketcall_allowed, | |
| 214 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | |
| 215 base::ScopedFD fds[2]; | |
| 216 struct msghdr msg = {}; | |
| 217 struct iovec iov; | |
| 218 std::string payload("foo"); | |
| 219 iov.iov_base = &payload[0]; | |
| 220 iov.iov_len = payload.size(); | |
| 221 msg.msg_iov = &iov; | |
| 222 msg.msg_iovlen = 1; | |
| 223 DoSocketpair(fds); | |
| 224 BPF_ASSERT_EQ(static_cast<int>(payload.size()), | |
| 225 HANDLE_EINTR(sendmsg(fds[1].get(), &msg, 0))); | |
| 226 BPF_ASSERT_EQ(static_cast<int>(payload.size()), | |
| 227 HANDLE_EINTR(recvmsg(fds[0].get(), &msg, 0))); | |
| 228 BPF_ASSERT_EQ(0, shutdown(fds[0].get(), SHUT_RDWR)); | |
| 229 } | |
| 230 #endif | |
| 231 | 210 |
| 232 // On arm and x86_64 the arguments to socketpair are passed in registers, | 211 // On arm and x86_64 the arguments to socketpair are passed in registers, |
| 233 // so they can be filtered by seccomp-bpf. This filter cannot be applied | 212 // so they can be filtered by seccomp-bpf. This filter cannot be applied |
| 234 // on x86_32 as the arguments are passed in memory. | 213 // on x86_32 as the arguments are passed in memory. |
| 235 #if defined(__x86_64__) || defined(__arm__) | 214 #if defined(__x86_64__) || defined(__arm__) |
| 236 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, | 215 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, |
| 237 socketpair_af_inet_disallowed, | 216 socketpair_af_inet_disallowed, |
| 238 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), | 217 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), |
| 239 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | 218 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
| 240 int fds[2]; | 219 int fds[2]; |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 439 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), | 418 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), |
| 440 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | 419 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
| 441 base::ScopedFD fds[2]; | 420 base::ScopedFD fds[2]; |
| 442 DoPipe(fds); | 421 DoPipe(fds); |
| 443 fcntl(fds[0].get(), F_SETFL, O_APPEND); | 422 fcntl(fds[0].get(), F_SETFL, O_APPEND); |
| 444 } | 423 } |
| 445 | 424 |
| 446 void DoFcntl(int fd, int cmd) { | 425 void DoFcntl(int fd, int cmd) { |
| 447 // fcntl in PNaCl toolchain returns an error without calling actual system | 426 // fcntl in PNaCl toolchain returns an error without calling actual system |
| 448 // call for unknown |cmd|. So, instead, here we use syscall(). | 427 // call for unknown |cmd|. So, instead, here we use syscall(). |
| 449 #if defined(OS_NACL_NONSFI) | |
| 450 syscall(__NR_fcntl64, fd, cmd); | 428 syscall(__NR_fcntl64, fd, cmd); |
| 451 #else | |
| 452 fcntl(fd, cmd); | |
| 453 #endif | |
| 454 } | 429 } |
| 455 | 430 |
| 456 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, | 431 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, |
| 457 fcntl_DUPFD, | 432 fcntl_DUPFD, |
| 458 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), | 433 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), |
| 459 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | 434 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
| 460 DoFcntl(0, F_DUPFD); | 435 DoFcntl(0, F_DUPFD); |
| 461 } | 436 } |
| 462 | 437 |
| 463 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, | 438 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 496 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, | 471 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, |
| 497 FutexWithUnlockPIPrivate, | 472 FutexWithUnlockPIPrivate, |
| 498 DEATH_SEGV_MESSAGE( | 473 DEATH_SEGV_MESSAGE( |
| 499 sandbox::GetFutexErrorMessageContentForTests()), | 474 sandbox::GetFutexErrorMessageContentForTests()), |
| 500 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | 475 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
| 501 syscall(__NR_futex, NULL, FUTEX_UNLOCK_PI_PRIVATE, 0, NULL, NULL, 0); | 476 syscall(__NR_futex, NULL, FUTEX_UNLOCK_PI_PRIVATE, 0, NULL, NULL, 0); |
| 502 _exit(1); | 477 _exit(1); |
| 503 } | 478 } |
| 504 | 479 |
| 505 void* DoMmap(int prot, int flags) { | 480 void* DoMmap(int prot, int flags) { |
| 506 #if defined(OS_NACL_NONSFI) | |
| 507 // When PROT_EXEC is set, PNaCl toolchain's mmap() system call wrapper uses | 481 // When PROT_EXEC is set, PNaCl toolchain's mmap() system call wrapper uses |
| 508 // two system calls mmap2(2) and mprotect(2), so that we cannot test | 482 // two system calls mmap2(2) and mprotect(2), so that we cannot test |
| 509 // sandbox with the wrapper. Instead, here we use syscall(). | 483 // sandbox with the wrapper. Instead, here we use syscall(). |
| 510 return reinterpret_cast<void*>( | 484 return reinterpret_cast<void*>( |
| 511 syscall(__NR_mmap2, NULL, getpagesize(), prot, flags, -1, 0)); | 485 syscall(__NR_mmap2, NULL, getpagesize(), prot, flags, -1, 0)); |
| 512 #else | |
| 513 return mmap(NULL, getpagesize(), prot, flags, -1, 0); | |
| 514 #endif | |
| 515 } | 486 } |
| 516 | 487 |
| 517 void* DoAllowedAnonymousMmap() { | 488 void* DoAllowedAnonymousMmap() { |
| 518 return DoMmap(PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED); | 489 return DoMmap(PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED); |
| 519 } | 490 } |
| 520 | 491 |
| 521 BPF_TEST_C(NaClNonSfiSandboxTest, | 492 BPF_TEST_C(NaClNonSfiSandboxTest, |
| 522 mmap_allowed, | 493 mmap_allowed, |
| 523 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | 494 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
| 524 void* ptr = DoAllowedAnonymousMmap(); | 495 void* ptr = DoAllowedAnonymousMmap(); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 588 BPF_ASSERT_NE(MAP_FAILED, ptr); | 559 BPF_ASSERT_NE(MAP_FAILED, ptr); |
| 589 mprotect(ptr, getpagesize(), PROT_READ | PROT_GROWSDOWN); | 560 mprotect(ptr, getpagesize(), PROT_READ | PROT_GROWSDOWN); |
| 590 } | 561 } |
| 591 | 562 |
| 592 BPF_TEST_C(NaClNonSfiSandboxTest, | 563 BPF_TEST_C(NaClNonSfiSandboxTest, |
| 593 brk, | 564 brk, |
| 594 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | 565 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
| 595 char* next_brk = static_cast<char*>(sbrk(0)) + getpagesize(); | 566 char* next_brk = static_cast<char*>(sbrk(0)) + getpagesize(); |
| 596 // The kernel interface must return zero for brk. | 567 // The kernel interface must return zero for brk. |
| 597 BPF_ASSERT_EQ(0, syscall(__NR_brk, next_brk)); | 568 BPF_ASSERT_EQ(0, syscall(__NR_brk, next_brk)); |
| 598 // The libc wrapper translates it to ENOMEM. | 569 // The libc wrapper translates it to ENOMEM. |
|
Mark Seaborn
2015/10/15 18:10:11
This comment applies to the code being removed, I
hidehiko
2015/10/19 04:39:18
Done.
| |
| 599 | |
| 600 // Note: PNaCl toolchain does not provide brk() system call wrapper. | |
| 601 #if !defined(OS_NACL_NONSFI) | |
| 602 errno = 0; | |
| 603 BPF_ASSERT_EQ(-1, brk(next_brk)); | |
| 604 BPF_ASSERT_EQ(ENOMEM, errno); | |
| 605 #endif | |
| 606 } | 570 } |
| 607 | 571 |
| 608 // clockid restrictions are mostly tested in sandbox/ with the | 572 // clockid restrictions are mostly tested in sandbox/ with the |
| 609 // RestrictClockID() unittests. Some basic tests are duplicated here as | 573 // RestrictClockID() unittests. Some basic tests are duplicated here as |
| 610 // a precaution. | 574 // a precaution. |
| 611 | 575 |
| 612 void CheckClock(clockid_t clockid) { | 576 void CheckClock(clockid_t clockid) { |
| 613 struct timespec ts; | 577 struct timespec ts; |
| 614 ts.tv_sec = ts.tv_nsec = -1; | 578 ts.tv_sec = ts.tv_nsec = -1; |
| 615 BPF_ASSERT_EQ(0, clock_gettime(clockid, &ts)); | 579 BPF_ASSERT_EQ(0, clock_gettime(clockid, &ts)); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 737 RESTRICT_SYSCALL_EPERM_TEST(ptrace); | 701 RESTRICT_SYSCALL_EPERM_TEST(ptrace); |
| 738 RESTRICT_SYSCALL_EPERM_TEST(set_robust_list); | 702 RESTRICT_SYSCALL_EPERM_TEST(set_robust_list); |
| 739 #if defined(__i386__) || defined(__x86_64__) | 703 #if defined(__i386__) || defined(__x86_64__) |
| 740 RESTRICT_SYSCALL_EPERM_TEST(time); | 704 RESTRICT_SYSCALL_EPERM_TEST(time); |
| 741 #endif | 705 #endif |
| 742 | 706 |
| 743 } // namespace | 707 } // namespace |
| 744 | 708 |
| 745 #endif // !ADDRESS_SANITIZER && !THREAD_SANITIZER && | 709 #endif // !ADDRESS_SANITIZER && !THREAD_SANITIZER && |
| 746 // !MEMORY_SANITIZER && !LEAK_SANITIZER | 710 // !MEMORY_SANITIZER && !LEAK_SANITIZER |
| OLD | NEW |