| 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 |
| 11 #include <errno.h> | 11 #include <errno.h> |
| 12 #include <fcntl.h> | 12 #include <fcntl.h> |
| 13 #include <linux/net.h> | 13 #include <linux/net.h> |
| 14 #include <pthread.h> | 14 #include <pthread.h> |
| 15 #include <sched.h> | 15 #include <sched.h> |
| 16 #include <signal.h> | 16 #include <signal.h> |
| 17 #include <stdlib.h> | 17 #include <stdlib.h> |
| 18 #include <string.h> | 18 #include <string.h> |
| 19 #include <sys/mman.h> | 19 #include <sys/mman.h> |
| 20 #include <sys/prctl.h> | 20 #include <sys/prctl.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 <time.h> |
| 26 #include <unistd.h> | 26 #include <unistd.h> |
| 27 | 27 |
| 28 #include "base/at_exit.h" | |
| 29 #include "base/bind.h" | 28 #include "base/bind.h" |
| 30 #include "base/callback.h" | 29 #include "base/callback.h" |
| 31 #include "base/compiler_specific.h" | 30 #include "base/compiler_specific.h" |
| 32 #include "base/files/scoped_file.h" | 31 #include "base/files/scoped_file.h" |
| 33 #include "base/logging.h" | 32 #include "base/logging.h" |
| 34 #include "base/posix/eintr_wrapper.h" | 33 #include "base/posix/eintr_wrapper.h" |
| 35 #include "base/sys_info.h" | 34 #include "base/sys_info.h" |
| 36 #include "base/threading/thread.h" | 35 #include "base/threading/thread.h" |
| 37 #include "base/time/time.h" | 36 #include "base/time/time.h" |
| 38 #include "sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h" | 37 #include "sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h" |
| 39 #include "sandbox/linux/seccomp-bpf/bpf_tests.h" | 38 #include "sandbox/linux/seccomp-bpf/bpf_tests.h" |
| 40 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" | 39 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" |
| 41 #include "sandbox/linux/seccomp-bpf/syscall.h" | 40 #include "sandbox/linux/seccomp-bpf/syscall.h" |
| 42 #include "sandbox/linux/system_headers/linux_futex.h" | 41 #include "sandbox/linux/system_headers/linux_futex.h" |
| 43 #include "sandbox/linux/system_headers/linux_signal.h" | 42 #include "sandbox/linux/system_headers/linux_signal.h" |
| 44 #include "sandbox/linux/system_headers/linux_syscalls.h" | 43 #include "sandbox/linux/system_headers/linux_syscalls.h" |
| 45 | 44 |
| 46 // These defines are for PNaCl toolchain build. | |
| 47 #if !defined(F_DUPFD_CLOEXEC) | |
| 48 #define F_DUPFD_CLOEXEC 1030 | |
| 49 #endif | |
| 50 | |
| 51 #if !defined(MAP_POPULATE) | |
| 52 #define MAP_POPULATE 0x8000 | |
| 53 #endif | |
| 54 | |
| 55 #if !defined(PROT_GROWSDOWN) | |
| 56 #define PROT_GROWSDOWN 0x01000000 | |
| 57 #endif | |
| 58 | |
| 59 #if !defined(CLOCK_MONOTONIC_RAW) | |
| 60 #define CLOCK_MONOTONIC_RAW 4 | |
| 61 #endif | |
| 62 | |
| 63 #if !defined(AF_INET) | |
| 64 #define AF_INET 2 | |
| 65 #endif | |
| 66 | |
| 67 #if defined(__i386__) | |
| 68 | |
| 69 #if !defined(SYS_SOCKET) | |
| 70 #define SYS_SOCKET 1 | |
| 71 #endif | |
| 72 | |
| 73 #if !defined(SYS_BIND) | |
| 74 #define SYS_BIND 2 | |
| 75 #endif | |
| 76 | |
| 77 #if !defined(SYS_CONNECT) | |
| 78 #define SYS_CONNECT 3 | |
| 79 #endif | |
| 80 | |
| 81 #if !defined(SYS_LISTEN) | |
| 82 #define SYS_LISTEN 4 | |
| 83 #endif | |
| 84 | |
| 85 #if !defined(SYS_ACCEPT) | |
| 86 #define SYS_ACCEPT 5 | |
| 87 #endif | |
| 88 | |
| 89 #if !defined(SYS_GETSOCKNAME) | |
| 90 #define SYS_GETSOCKNAME 6 | |
| 91 #endif | |
| 92 | |
| 93 #if !defined(SYS_GETPEERNAME) | |
| 94 #define SYS_GETPEERNAME 7 | |
| 95 #endif | |
| 96 | |
| 97 #if !defined(SYS_SETSOCKOPT) | |
| 98 #define SYS_SETSOCKOPT 14 | |
| 99 #endif | |
| 100 | |
| 101 #if !defined(SYS_GETSOCKOPT) | |
| 102 #define SYS_GETSOCKOPT 15 | |
| 103 #endif | |
| 104 | |
| 105 #endif // defined(__i386__) | |
| 106 | |
| 107 namespace { | 45 namespace { |
| 108 | 46 |
| 109 void DoPipe(base::ScopedFD* fds) { | 47 void DoPipe(base::ScopedFD* fds) { |
| 110 int tmp_fds[2]; | 48 int tmp_fds[2]; |
| 111 BPF_ASSERT_EQ(0, pipe(tmp_fds)); | 49 BPF_ASSERT_EQ(0, pipe(tmp_fds)); |
| 112 fds[0].reset(tmp_fds[0]); | 50 fds[0].reset(tmp_fds[0]); |
| 113 fds[1].reset(tmp_fds[1]); | 51 fds[1].reset(tmp_fds[1]); |
| 114 } | 52 } |
| 115 | 53 |
| 116 void DoSocketpair(base::ScopedFD* fds) { | 54 void DoSocketpair(base::ScopedFD* fds) { |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 | 361 |
| 424 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, | 362 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, |
| 425 fcntl_GETFL_SETFL, | 363 fcntl_GETFL_SETFL, |
| 426 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), | 364 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), |
| 427 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | 365 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
| 428 base::ScopedFD fds[2]; | 366 base::ScopedFD fds[2]; |
| 429 DoSocketpair(fds); | 367 DoSocketpair(fds); |
| 430 fcntl(fds[0].get(), F_SETFL, O_APPEND); | 368 fcntl(fds[0].get(), F_SETFL, O_APPEND); |
| 431 } | 369 } |
| 432 | 370 |
| 433 void DoFcntl(int fd, int cmd) { | |
| 434 // fcntl in PNaCl toolchain returns an error without calling actual system | |
| 435 // call for unknown |cmd|. So, instead, here we use syscall(). | |
| 436 #if defined(OS_NACL_NONSFI) | |
| 437 syscall(__NR_fcntl64, fd, cmd); | |
| 438 #else | |
| 439 fcntl(fd, cmd); | |
| 440 #endif | |
| 441 } | |
| 442 | |
| 443 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, | 371 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, |
| 444 fcntl_DUPFD, | 372 fcntl_DUPFD, |
| 445 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), | 373 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), |
| 446 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | 374 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
| 447 DoFcntl(0, F_DUPFD); | 375 fcntl(0, F_DUPFD); |
| 448 } | 376 } |
| 449 | 377 |
| 450 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, | 378 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, |
| 451 fcntl_DUPFD_CLOEXEC, | 379 fcntl_DUPFD_CLOEXEC, |
| 452 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), | 380 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), |
| 453 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | 381 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
| 454 DoFcntl(0, F_DUPFD_CLOEXEC); | 382 fcntl(0, F_DUPFD_CLOEXEC); |
| 455 } | 383 } |
| 456 | 384 |
| 457 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, | 385 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, |
| 458 FutexWithRequeuePriorityInheritence, | 386 FutexWithRequeuePriorityInheritence, |
| 459 DEATH_SEGV_MESSAGE( | 387 DEATH_SEGV_MESSAGE( |
| 460 sandbox::GetFutexErrorMessageContentForTests()), | 388 sandbox::GetFutexErrorMessageContentForTests()), |
| 461 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | 389 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
| 462 syscall(__NR_futex, NULL, FUTEX_CMP_REQUEUE_PI, 0, NULL, NULL, 0); | 390 syscall(__NR_futex, NULL, FUTEX_CMP_REQUEUE_PI, 0, NULL, NULL, 0); |
| 463 _exit(1); | 391 _exit(1); |
| 464 } | 392 } |
| 465 | 393 |
| 466 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, | 394 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, |
| 467 FutexWithRequeuePriorityInheritencePrivate, | 395 FutexWithRequeuePriorityInheritencePrivate, |
| 468 DEATH_SEGV_MESSAGE( | 396 DEATH_SEGV_MESSAGE( |
| 469 sandbox::GetFutexErrorMessageContentForTests()), | 397 sandbox::GetFutexErrorMessageContentForTests()), |
| 470 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | 398 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
| 471 syscall(__NR_futex, NULL, FUTEX_CMP_REQUEUE_PI_PRIVATE, 0, NULL, NULL, 0); | 399 syscall(__NR_futex, NULL, FUTEX_CMP_REQUEUE_PI_PRIVATE, 0, NULL, NULL, 0); |
| 472 _exit(1); | 400 _exit(1); |
| 473 } | 401 } |
| 474 | 402 |
| 475 BPF_TEST_C(NaClNonSfiSandboxTest, | 403 BPF_TEST_C(NaClNonSfiSandboxTest, |
| 476 StartingAndJoiningThreadWorks, | 404 StartingAndJoiningThreadWorks, |
| 477 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | 405 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
| 478 #if defined(OS_NACL_NONSFI) | |
| 479 // base::Thread internally uses LazyInstance, which registers a callback to | |
| 480 // AtExitManager. However, in PNaCl toolchain build, it is not instantiated | |
| 481 // by the test runner, unlike host toolchain build (nacl_loader_unittests). | |
| 482 // Hence, declare it here so that the LazyInstance will work properly. | |
| 483 base::AtExitManager at_exit; | |
| 484 #endif | |
| 485 | |
| 486 base::Thread thread("sandbox_tests"); | 406 base::Thread thread("sandbox_tests"); |
| 487 BPF_ASSERT(thread.Start()); | 407 BPF_ASSERT(thread.Start()); |
| 488 // |thread|'s destructor will join the thread. | 408 // |thread|'s destructor will join the thread. |
| 489 } | 409 } |
| 490 | 410 |
| 491 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, | 411 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, |
| 492 FutexWithUnlockPIPrivate, | 412 FutexWithUnlockPIPrivate, |
| 493 DEATH_SEGV_MESSAGE( | 413 DEATH_SEGV_MESSAGE( |
| 494 sandbox::GetFutexErrorMessageContentForTests()), | 414 sandbox::GetFutexErrorMessageContentForTests()), |
| 495 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | 415 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
| 496 syscall(__NR_futex, NULL, FUTEX_UNLOCK_PI_PRIVATE, 0, NULL, NULL, 0); | 416 syscall(__NR_futex, NULL, FUTEX_UNLOCK_PI_PRIVATE, 0, NULL, NULL, 0); |
| 497 _exit(1); | 417 _exit(1); |
| 498 } | 418 } |
| 499 | 419 |
| 500 void* DoMmap(int prot, int flags) { | |
| 501 #if defined(OS_NACL_NONSFI) | |
| 502 // When PROT_EXEC is set, PNaCl toolchain's mmap() system call wrapper uses | |
| 503 // two system calls mmap2(2) and mprotect(2), so that we cannot test | |
| 504 // sandbox with the wrapper. Instead, here we use syscall(). | |
| 505 return reinterpret_cast<void*>( | |
| 506 syscall(__NR_mmap2, NULL, getpagesize(), prot, flags, -1, 0)); | |
| 507 #else | |
| 508 return mmap(NULL, getpagesize(), prot, flags, -1, 0); | |
| 509 #endif | |
| 510 } | |
| 511 | |
| 512 void* DoAllowedAnonymousMmap() { | 420 void* DoAllowedAnonymousMmap() { |
| 513 return DoMmap(PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED); | 421 return mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, |
| 422 MAP_ANONYMOUS | MAP_SHARED, -1, 0); |
| 514 } | 423 } |
| 515 | 424 |
| 516 BPF_TEST_C(NaClNonSfiSandboxTest, | 425 BPF_TEST_C(NaClNonSfiSandboxTest, |
| 517 mmap_allowed, | 426 mmap_allowed, |
| 518 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | 427 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
| 519 void* ptr = DoAllowedAnonymousMmap(); | 428 void* ptr = DoAllowedAnonymousMmap(); |
| 520 BPF_ASSERT_NE(MAP_FAILED, ptr); | 429 BPF_ASSERT_NE(MAP_FAILED, ptr); |
| 521 BPF_ASSERT_EQ(0, munmap(ptr, getpagesize())); | 430 BPF_ASSERT_EQ(0, munmap(ptr, getpagesize())); |
| 522 } | 431 } |
| 523 | 432 |
| 524 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, | 433 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, |
| 525 mmap_unallowed_flag, | 434 mmap_unallowed_flag, |
| 526 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), | 435 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), |
| 527 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | 436 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
| 528 DoMmap(PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_POPULATE); | 437 mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, |
| 438 MAP_ANONYMOUS | MAP_POPULATE, -1, 0); |
| 529 } | 439 } |
| 530 | 440 |
| 531 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, | 441 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, |
| 532 mmap_unallowed_prot, | 442 mmap_unallowed_prot, |
| 533 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), | 443 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), |
| 534 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | 444 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
| 535 DoMmap(PROT_READ | PROT_GROWSDOWN, MAP_ANONYMOUS); | 445 mmap(NULL, getpagesize(), PROT_READ | PROT_GROWSDOWN, |
| 446 MAP_ANONYMOUS, -1, 0); |
| 536 } | 447 } |
| 537 | 448 |
| 538 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, | 449 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, |
| 539 mmap_exec, | 450 mmap_exec, |
| 540 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), | 451 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), |
| 541 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | 452 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
| 542 DoMmap(PROT_EXEC, MAP_ANONYMOUS); | 453 mmap(NULL, getpagesize(), PROT_EXEC, MAP_ANONYMOUS, -1, 0); |
| 543 } | 454 } |
| 544 | 455 |
| 545 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, | 456 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, |
| 546 mmap_read_exec, | 457 mmap_read_exec, |
| 547 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), | 458 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), |
| 548 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | 459 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
| 549 DoMmap(PROT_READ | PROT_EXEC, MAP_ANONYMOUS); | 460 mmap(NULL, getpagesize(), PROT_READ | PROT_EXEC, MAP_ANONYMOUS, -1, 0); |
| 550 } | 461 } |
| 551 | 462 |
| 552 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, | 463 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, |
| 553 mmap_write_exec, | 464 mmap_write_exec, |
| 554 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), | 465 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), |
| 555 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | 466 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
| 556 DoMmap(PROT_WRITE | PROT_EXEC, MAP_ANONYMOUS); | 467 mmap(NULL, getpagesize(), PROT_WRITE | PROT_EXEC, MAP_ANONYMOUS, -1, 0); |
| 557 } | 468 } |
| 558 | 469 |
| 559 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, | 470 BPF_DEATH_TEST_C(NaClNonSfiSandboxTest, |
| 560 mmap_read_write_exec, | 471 mmap_read_write_exec, |
| 561 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), | 472 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), |
| 562 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | 473 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
| 563 DoMmap(PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANONYMOUS); | 474 mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE | PROT_EXEC, |
| 475 MAP_ANONYMOUS, -1, 0); |
| 564 } | 476 } |
| 565 | 477 |
| 566 BPF_TEST_C(NaClNonSfiSandboxTest, | 478 BPF_TEST_C(NaClNonSfiSandboxTest, |
| 567 mprotect_allowed, | 479 mprotect_allowed, |
| 568 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | 480 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
| 569 void* ptr = DoAllowedAnonymousMmap(); | 481 void* ptr = DoAllowedAnonymousMmap(); |
| 570 BPF_ASSERT_NE(MAP_FAILED, ptr); | 482 BPF_ASSERT_NE(MAP_FAILED, ptr); |
| 571 BPF_ASSERT_EQ(0, mprotect(ptr, getpagesize(), PROT_READ)); | 483 BPF_ASSERT_EQ(0, mprotect(ptr, getpagesize(), PROT_READ)); |
| 572 BPF_ASSERT_EQ(0, munmap(ptr, getpagesize())); | 484 BPF_ASSERT_EQ(0, munmap(ptr, getpagesize())); |
| 573 } | 485 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 584 mprotect(ptr, getpagesize(), PROT_READ | PROT_GROWSDOWN); | 496 mprotect(ptr, getpagesize(), PROT_READ | PROT_GROWSDOWN); |
| 585 } | 497 } |
| 586 | 498 |
| 587 BPF_TEST_C(NaClNonSfiSandboxTest, | 499 BPF_TEST_C(NaClNonSfiSandboxTest, |
| 588 brk, | 500 brk, |
| 589 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { | 501 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) { |
| 590 char* next_brk = static_cast<char*>(sbrk(0)) + getpagesize(); | 502 char* next_brk = static_cast<char*>(sbrk(0)) + getpagesize(); |
| 591 // The kernel interface must return zero for brk. | 503 // The kernel interface must return zero for brk. |
| 592 BPF_ASSERT_EQ(0, syscall(__NR_brk, next_brk)); | 504 BPF_ASSERT_EQ(0, syscall(__NR_brk, next_brk)); |
| 593 // The libc wrapper translates it to ENOMEM. | 505 // The libc wrapper translates it to ENOMEM. |
| 594 | |
| 595 // Note: PNaCl toolchain does not provide brk() system call wrapper. | |
| 596 #if !defined(OS_NACL_NONSFI) | |
| 597 errno = 0; | 506 errno = 0; |
| 598 BPF_ASSERT_EQ(-1, brk(next_brk)); | 507 BPF_ASSERT_EQ(-1, brk(next_brk)); |
| 599 BPF_ASSERT_EQ(ENOMEM, errno); | 508 BPF_ASSERT_EQ(ENOMEM, errno); |
| 600 #endif | |
| 601 } | 509 } |
| 602 | 510 |
| 603 // clockid restrictions are mostly tested in sandbox/ with the | 511 // clockid restrictions are mostly tested in sandbox/ with the |
| 604 // RestrictClockID() unittests. Some basic tests are duplicated here as | 512 // RestrictClockID() unittests. Some basic tests are duplicated here as |
| 605 // a precaution. | 513 // a precaution. |
| 606 | 514 |
| 607 void CheckClock(clockid_t clockid) { | 515 void CheckClock(clockid_t clockid) { |
| 608 struct timespec ts; | 516 struct timespec ts; |
| 609 ts.tv_sec = ts.tv_nsec = -1; | 517 ts.tv_sec = ts.tv_nsec = -1; |
| 610 BPF_ASSERT_EQ(0, clock_gettime(clockid, &ts)); | 518 BPF_ASSERT_EQ(0, clock_gettime(clockid, &ts)); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 RESTRICT_SYSCALL_EPERM_TEST(ptrace); | 572 RESTRICT_SYSCALL_EPERM_TEST(ptrace); |
| 665 RESTRICT_SYSCALL_EPERM_TEST(set_robust_list); | 573 RESTRICT_SYSCALL_EPERM_TEST(set_robust_list); |
| 666 #if defined(__i386__) || defined(__x86_64__) | 574 #if defined(__i386__) || defined(__x86_64__) |
| 667 RESTRICT_SYSCALL_EPERM_TEST(time); | 575 RESTRICT_SYSCALL_EPERM_TEST(time); |
| 668 #endif | 576 #endif |
| 669 | 577 |
| 670 } // namespace | 578 } // namespace |
| 671 | 579 |
| 672 #endif // !ADDRESS_SANITIZER && !THREAD_SANITIZER && | 580 #endif // !ADDRESS_SANITIZER && !THREAD_SANITIZER && |
| 673 // !MEMORY_SANITIZER && !LEAK_SANITIZER | 581 // !MEMORY_SANITIZER && !LEAK_SANITIZER |
| OLD | NEW |