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

Side by Side Diff: sandbox/linux/bpf_dsl/bpf_dsl_more_unittest.cc

Issue 881763003: Roll Clang 223108:228742 (Closed) Base URL: precise:/work/chromium/src@clang_roll_226907
Patch Set: Don't run SandboxBPF.SigBus under ASan; SIGBUS is treated as a fatal signal after r225630 Created 5 years, 10 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "sandbox/linux/bpf_dsl/bpf_dsl.h" 5 #include "sandbox/linux/bpf_dsl/bpf_dsl.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <pthread.h> 9 #include <pthread.h>
10 #include <sched.h> 10 #include <sched.h>
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 setenv(kSandboxDebuggingEnv, "t", 0); 645 setenv(kSandboxDebuggingEnv, "t", 0);
646 Die::SuppressInfoMessages(true); 646 Die::SuppressInfoMessages(true);
647 647
648 // Some system calls must always be allowed, if our policy wants to make 648 // Some system calls must always be allowed, if our policy wants to make
649 // use of UnsafeTrap() 649 // use of UnsafeTrap()
650 if (SandboxBPF::IsRequiredForUnsafeTrap(sysno)) 650 if (SandboxBPF::IsRequiredForUnsafeTrap(sysno))
651 return Allow(); 651 return Allow();
652 return UnsafeTrap(AllowRedirectedSyscall, NULL); 652 return UnsafeTrap(AllowRedirectedSyscall, NULL);
653 } 653 }
654 654
655 #if !defined(ADDRESS_SANITIZER)
656 // ASan does not allow changing the signal handler for SIGBUS, and treats it as
657 // a fatal signal.
658
655 int bus_handler_fd_ = -1; 659 int bus_handler_fd_ = -1;
656 660
657 void SigBusHandler(int, siginfo_t* info, void* void_context) { 661 void SigBusHandler(int, siginfo_t* info, void* void_context) {
658 BPF_ASSERT(write(bus_handler_fd_, "\x55", 1) == 1); 662 BPF_ASSERT(write(bus_handler_fd_, "\x55", 1) == 1);
659 } 663 }
660 664
661 BPF_TEST_C(SandboxBPF, SigBus, RedirectAllSyscallsPolicy) { 665 BPF_TEST_C(SandboxBPF, SigBus, RedirectAllSyscallsPolicy) {
662 // We use the SIGBUS bit in the signal mask as a thread-local boolean 666 // We use the SIGBUS bit in the signal mask as a thread-local boolean
663 // value in the implementation of UnsafeTrap(). This is obviously a bit 667 // value in the implementation of UnsafeTrap(). This is obviously a bit
664 // of a hack that could conceivably interfere with code that uses SIGBUS 668 // of a hack that could conceivably interfere with code that uses SIGBUS
665 // in more traditional ways. This test verifies that basic functionality 669 // in more traditional ways. This test verifies that basic functionality
666 // of SIGBUS is not impacted, but it is certainly possibly to construe 670 // of SIGBUS is not impacted, but it is certainly possibly to construe
667 // more complex uses of signals where our use of the SIGBUS mask is not 671 // more complex uses of signals where our use of the SIGBUS mask is not
668 // 100% transparent. This is expected behavior. 672 // 100% transparent. This is expected behavior.
669 int fds[2]; 673 int fds[2];
670 BPF_ASSERT(socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == 0); 674 BPF_ASSERT(socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == 0);
671 bus_handler_fd_ = fds[1]; 675 bus_handler_fd_ = fds[1];
672 struct sigaction sa = {}; 676 struct sigaction sa = {};
673 sa.sa_sigaction = SigBusHandler; 677 sa.sa_sigaction = SigBusHandler;
674 sa.sa_flags = SA_SIGINFO; 678 sa.sa_flags = SA_SIGINFO;
675 BPF_ASSERT(sigaction(SIGBUS, &sa, NULL) == 0); 679 BPF_ASSERT(sigaction(SIGBUS, &sa, NULL) == 0);
676 raise(SIGBUS); 680 raise(SIGBUS);
677 char c = '\000'; 681 char c = '\000';
678 BPF_ASSERT(read(fds[0], &c, 1) == 1); 682 BPF_ASSERT(read(fds[0], &c, 1) == 1);
679 BPF_ASSERT(close(fds[0]) == 0); 683 BPF_ASSERT(close(fds[0]) == 0);
680 BPF_ASSERT(close(fds[1]) == 0); 684 BPF_ASSERT(close(fds[1]) == 0);
681 BPF_ASSERT(c == 0x55); 685 BPF_ASSERT(c == 0x55);
682 } 686 }
687 #endif
jln (very slow on Chromium) 2015/02/05 23:54:14 Add // !defined(ADDRESS_SANITIZER)
hans 2015/02/06 00:05:34 Done.
683 688
684 BPF_TEST_C(SandboxBPF, SigMask, RedirectAllSyscallsPolicy) { 689 BPF_TEST_C(SandboxBPF, SigMask, RedirectAllSyscallsPolicy) {
685 // Signal masks are potentially tricky to handle. For instance, if we 690 // Signal masks are potentially tricky to handle. For instance, if we
686 // ever tried to update them from inside a Trap() or UnsafeTrap() handler, 691 // ever tried to update them from inside a Trap() or UnsafeTrap() handler,
687 // the call to sigreturn() at the end of the signal handler would undo 692 // the call to sigreturn() at the end of the signal handler would undo
688 // all of our efforts. So, it makes sense to test that sigprocmask() 693 // all of our efforts. So, it makes sense to test that sigprocmask()
689 // works, even if we have a policy in place that makes use of UnsafeTrap(). 694 // works, even if we have a policy in place that makes use of UnsafeTrap().
690 // In practice, this works because we force sigprocmask() to be handled 695 // In practice, this works because we force sigprocmask() to be handled
691 // entirely in the kernel. 696 // entirely in the kernel.
692 sigset_t mask0, mask1, mask2; 697 sigset_t mask0, mask1, mask2;
(...skipping 1695 matching lines...) Expand 10 before | Expand all | Expand 10 after
2388 BPF_ASSERT_EQ(ENOSYS, errno); 2393 BPF_ASSERT_EQ(ENOSYS, errno);
2389 2394
2390 BPF_ASSERT_EQ(-1, syscall(__NR_setgid, 300)); 2395 BPF_ASSERT_EQ(-1, syscall(__NR_setgid, 300));
2391 BPF_ASSERT_EQ(EPERM, errno); 2396 BPF_ASSERT_EQ(EPERM, errno);
2392 } 2397 }
2393 2398
2394 } // namespace 2399 } // namespace
2395 2400
2396 } // namespace bpf_dsl 2401 } // namespace bpf_dsl
2397 } // namespace sandbox 2402 } // namespace sandbox
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698