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

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

Issue 721553002: sandbox: Extend BrokerPolicy to support file creation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review fixups Created 6 years, 1 month 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 23 matching lines...) Expand all
34 #include "build/build_config.h" 34 #include "build/build_config.h"
35 #include "sandbox/linux/bpf_dsl/policy.h" 35 #include "sandbox/linux/bpf_dsl/policy.h"
36 #include "sandbox/linux/seccomp-bpf/bpf_tests.h" 36 #include "sandbox/linux/seccomp-bpf/bpf_tests.h"
37 #include "sandbox/linux/seccomp-bpf/die.h" 37 #include "sandbox/linux/seccomp-bpf/die.h"
38 #include "sandbox/linux/seccomp-bpf/errorcode.h" 38 #include "sandbox/linux/seccomp-bpf/errorcode.h"
39 #include "sandbox/linux/seccomp-bpf/linux_seccomp.h" 39 #include "sandbox/linux/seccomp-bpf/linux_seccomp.h"
40 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" 40 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h"
41 #include "sandbox/linux/seccomp-bpf/syscall.h" 41 #include "sandbox/linux/seccomp-bpf/syscall.h"
42 #include "sandbox/linux/seccomp-bpf/trap.h" 42 #include "sandbox/linux/seccomp-bpf/trap.h"
43 #include "sandbox/linux/services/linux_syscalls.h" 43 #include "sandbox/linux/services/linux_syscalls.h"
44 #include "sandbox/linux/syscall_broker/broker_process.h" 44 #include "sandbox/linux/syscall_broker/broker_process.h"
Jorge Lucangeli Obes 2014/11/20 21:03:00 Do you need to include "broker_file_permission.h"
leecam 2014/11/20 21:46:20 Done.
45 #include "sandbox/linux/tests/scoped_temporary_file.h" 45 #include "sandbox/linux/tests/scoped_temporary_file.h"
46 #include "sandbox/linux/tests/unit_tests.h" 46 #include "sandbox/linux/tests/unit_tests.h"
47 #include "testing/gtest/include/gtest/gtest.h" 47 #include "testing/gtest/include/gtest/gtest.h"
48 48
49 // Workaround for Android's prctl.h file. 49 // Workaround for Android's prctl.h file.
50 #ifndef PR_GET_ENDIAN 50 #ifndef PR_GET_ENDIAN
51 #define PR_GET_ENDIAN 19 51 #define PR_GET_ENDIAN 19
52 #endif 52 #endif
53 #ifndef PR_CAPBSET_READ 53 #ifndef PR_CAPBSET_READ
54 #define PR_CAPBSET_READ 23 54 #define PR_CAPBSET_READ 23
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 748
749 bool NoOpCallback() { 749 bool NoOpCallback() {
750 return true; 750 return true;
751 } 751 }
752 752
753 // Test a trap handler that makes use of a broker process to open(). 753 // Test a trap handler that makes use of a broker process to open().
754 754
755 class InitializedOpenBroker { 755 class InitializedOpenBroker {
756 public: 756 public:
757 InitializedOpenBroker() : initialized_(false) { 757 InitializedOpenBroker() : initialized_(false) {
758 std::vector<std::string> allowed_files; 758 std::vector<syscall_broker::BrokerFilePermission> permissions;
759 allowed_files.push_back("/proc/allowed"); 759 permissions.push_back(
760 allowed_files.push_back("/proc/cpuinfo"); 760 syscall_broker::BrokerFilePermission::ReadOnly("/proc/allowed"));
761 permissions.push_back(
762 syscall_broker::BrokerFilePermission::ReadOnly("/proc/cpuinfo"));
761 763
762 broker_process_.reset(new syscall_broker::BrokerProcess( 764 broker_process_.reset(
763 EPERM, allowed_files, std::vector<std::string>())); 765 new syscall_broker::BrokerProcess(EPERM, permissions));
764 BPF_ASSERT(broker_process() != NULL); 766 BPF_ASSERT(broker_process() != NULL);
765 BPF_ASSERT(broker_process_->Init(base::Bind(&NoOpCallback))); 767 BPF_ASSERT(broker_process_->Init(base::Bind(&NoOpCallback)));
766 768
767 initialized_ = true; 769 initialized_ = true;
768 } 770 }
769 bool initialized() { return initialized_; } 771 bool initialized() { return initialized_; }
770 class syscall_broker::BrokerProcess* broker_process() { 772 class syscall_broker::BrokerProcess* broker_process() {
771 return broker_process_.get(); 773 return broker_process_.get();
772 } 774 }
773 775
(...skipping 1619 matching lines...) Expand 10 before | Expand all | Expand 10 after
2393 BPF_ASSERT_EQ(ENOSYS, errno); 2395 BPF_ASSERT_EQ(ENOSYS, errno);
2394 2396
2395 BPF_ASSERT_EQ(-1, syscall(__NR_setgid, 300)); 2397 BPF_ASSERT_EQ(-1, syscall(__NR_setgid, 300));
2396 BPF_ASSERT_EQ(EPERM, errno); 2398 BPF_ASSERT_EQ(EPERM, errno);
2397 } 2399 }
2398 2400
2399 } // namespace 2401 } // namespace
2400 2402
2401 } // namespace bpf_dsl 2403 } // namespace bpf_dsl
2402 } // namespace sandbox 2404 } // namespace sandbox
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698