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

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

Issue 247563004: Non-SFI NaCl: Disallow mmap with PROT_EXEC (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment update 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
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 MAP_ANONYMOUS | MAP_POPULATE, -1, 0); 298 MAP_ANONYMOUS | MAP_POPULATE, -1, 0);
299 } 299 }
300 300
301 BPF_DEATH_TEST(NaClNonSfiSandboxTest, mmap_unallowed_prot, 301 BPF_DEATH_TEST(NaClNonSfiSandboxTest, mmap_unallowed_prot,
302 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), 302 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()),
303 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { 303 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) {
304 mmap(NULL, getpagesize(), PROT_READ | PROT_GROWSDOWN, 304 mmap(NULL, getpagesize(), PROT_READ | PROT_GROWSDOWN,
305 MAP_ANONYMOUS, -1, 0); 305 MAP_ANONYMOUS, -1, 0);
306 } 306 }
307 307
308 // TODO(hamaji): Disallow RWX mmap. 308 BPF_DEATH_TEST(NaClNonSfiSandboxTest, mmap_exec,
309 #if 0 309 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()),
310 BPF_DEATH_TEST(NaClNonSfiSandboxTest, mmap_rwx, 310 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) {
311 mmap(NULL, getpagesize(), PROT_EXEC, MAP_ANONYMOUS, -1, 0);
312 }
313
314 BPF_DEATH_TEST(NaClNonSfiSandboxTest, mmap_read_exec,
315 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()),
316 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) {
317 mmap(NULL, getpagesize(), PROT_READ | PROT_EXEC, MAP_ANONYMOUS, -1, 0);
318 }
319
320 BPF_DEATH_TEST(NaClNonSfiSandboxTest, mmap_write_exec,
321 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()),
322 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) {
323 mmap(NULL, getpagesize(), PROT_WRITE | PROT_EXEC, MAP_ANONYMOUS, -1, 0);
324 }
325
326 BPF_DEATH_TEST(NaClNonSfiSandboxTest, mmap_read_write_exec,
311 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()), 327 DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()),
312 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { 328 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) {
313 mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE | PROT_EXEC, 329 mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE | PROT_EXEC,
314 MAP_ANONYMOUS, -1, 0); 330 MAP_ANONYMOUS, -1, 0);
315 } 331 }
316 #endif
317 332
318 BPF_TEST(NaClNonSfiSandboxTest, mprotect_allowed, 333 BPF_TEST(NaClNonSfiSandboxTest, mprotect_allowed,
319 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { 334 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) {
320 void* ptr = DoAllowedAnonymousMmap(); 335 void* ptr = DoAllowedAnonymousMmap();
321 BPF_ASSERT_NE(MAP_FAILED, ptr); 336 BPF_ASSERT_NE(MAP_FAILED, ptr);
322 BPF_ASSERT_EQ(0, mprotect(ptr, getpagesize(), PROT_READ)); 337 BPF_ASSERT_EQ(0, mprotect(ptr, getpagesize(), PROT_READ));
323 BPF_ASSERT_EQ(0, munmap(ptr, getpagesize())); 338 BPF_ASSERT_EQ(0, munmap(ptr, getpagesize()));
324 } 339 }
325 340
326 BPF_DEATH_TEST(NaClNonSfiSandboxTest, mprotect_unallowed_prot, 341 BPF_DEATH_TEST(NaClNonSfiSandboxTest, mprotect_unallowed_prot,
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) { 477 nacl::nonsfi::NaClNonSfiBPFSandboxPolicy::EvaluateSyscallImpl) {
463 errno = 0; 478 errno = 0;
464 BPF_ASSERT_EQ(-1, syscall(__NR_time)); 479 BPF_ASSERT_EQ(-1, syscall(__NR_time));
465 BPF_ASSERT_EQ(EPERM, errno); 480 BPF_ASSERT_EQ(EPERM, errno);
466 } 481 }
467 #endif 482 #endif
468 483
469 } // namespace 484 } // namespace
470 485
471 #endif // !ADDRESS_SANITIZER && !THREAD_SANITIZER 486 #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