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 #include "sandbox/linux/seccomp-bpf/bpf_tests.h" | 5 #include "sandbox/linux/seccomp-bpf/bpf_tests.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <sys/ptrace.h> | 8 #include <sys/ptrace.h> |
9 #include <sys/syscall.h> | 9 #include <sys/syscall.h> |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
(...skipping 29 matching lines...) Expand all Loading... |
40 }; | 40 }; |
41 | 41 |
42 class EmptyClassTakingPolicy : public SandboxBPFDSLPolicy { | 42 class EmptyClassTakingPolicy : public SandboxBPFDSLPolicy { |
43 public: | 43 public: |
44 explicit EmptyClassTakingPolicy(FourtyTwo* fourty_two) { | 44 explicit EmptyClassTakingPolicy(FourtyTwo* fourty_two) { |
45 BPF_ASSERT(fourty_two); | 45 BPF_ASSERT(fourty_two); |
46 BPF_ASSERT(FourtyTwo::kMagicValue == fourty_two->value()); | 46 BPF_ASSERT(FourtyTwo::kMagicValue == fourty_two->value()); |
47 } | 47 } |
48 virtual ~EmptyClassTakingPolicy() {} | 48 virtual ~EmptyClassTakingPolicy() {} |
49 | 49 |
50 virtual ResultExpr EvaluateSyscall(int sysno) const OVERRIDE { | 50 virtual ResultExpr EvaluateSyscall(int sysno) const override { |
51 DCHECK(SandboxBPF::IsValidSyscallNumber(sysno)); | 51 DCHECK(SandboxBPF::IsValidSyscallNumber(sysno)); |
52 return Allow(); | 52 return Allow(); |
53 } | 53 } |
54 }; | 54 }; |
55 | 55 |
56 BPF_TEST(BPFTest, | 56 BPF_TEST(BPFTest, |
57 BPFAUXPointsToClass, | 57 BPFAUXPointsToClass, |
58 EmptyClassTakingPolicy, | 58 EmptyClassTakingPolicy, |
59 FourtyTwo /* *BPF_AUX */) { | 59 FourtyTwo /* *BPF_AUX */) { |
60 // BPF_AUX should point to an instance of FourtyTwo. | 60 // BPF_AUX should point to an instance of FourtyTwo. |
(...skipping 23 matching lines...) Expand all Loading... |
84 public: | 84 public: |
85 EnosysPtracePolicy() { | 85 EnosysPtracePolicy() { |
86 my_pid_ = syscall(__NR_getpid); | 86 my_pid_ = syscall(__NR_getpid); |
87 } | 87 } |
88 virtual ~EnosysPtracePolicy() { | 88 virtual ~EnosysPtracePolicy() { |
89 // Policies should be able to bind with the process on which they are | 89 // Policies should be able to bind with the process on which they are |
90 // created. They should never be created in a parent process. | 90 // created. They should never be created in a parent process. |
91 BPF_ASSERT_EQ(my_pid_, syscall(__NR_getpid)); | 91 BPF_ASSERT_EQ(my_pid_, syscall(__NR_getpid)); |
92 } | 92 } |
93 | 93 |
94 virtual ResultExpr EvaluateSyscall(int system_call_number) const OVERRIDE { | 94 virtual ResultExpr EvaluateSyscall(int system_call_number) const override { |
95 CHECK(SandboxBPF::IsValidSyscallNumber(system_call_number)); | 95 CHECK(SandboxBPF::IsValidSyscallNumber(system_call_number)); |
96 if (system_call_number == __NR_ptrace) { | 96 if (system_call_number == __NR_ptrace) { |
97 // The EvaluateSyscall function should run in the process that created | 97 // The EvaluateSyscall function should run in the process that created |
98 // the current object. | 98 // the current object. |
99 BPF_ASSERT_EQ(my_pid_, syscall(__NR_getpid)); | 99 BPF_ASSERT_EQ(my_pid_, syscall(__NR_getpid)); |
100 return Error(ENOSYS); | 100 return Error(ENOSYS); |
101 } else { | 101 } else { |
102 return Allow(); | 102 return Allow(); |
103 } | 103 } |
104 } | 104 } |
105 | 105 |
106 private: | 106 private: |
107 pid_t my_pid_; | 107 pid_t my_pid_; |
108 DISALLOW_COPY_AND_ASSIGN(EnosysPtracePolicy); | 108 DISALLOW_COPY_AND_ASSIGN(EnosysPtracePolicy); |
109 }; | 109 }; |
110 | 110 |
111 class BasicBPFTesterDelegate : public BPFTesterDelegate { | 111 class BasicBPFTesterDelegate : public BPFTesterDelegate { |
112 public: | 112 public: |
113 BasicBPFTesterDelegate() {} | 113 BasicBPFTesterDelegate() {} |
114 virtual ~BasicBPFTesterDelegate() {} | 114 virtual ~BasicBPFTesterDelegate() {} |
115 | 115 |
116 virtual scoped_ptr<SandboxBPFPolicy> GetSandboxBPFPolicy() OVERRIDE { | 116 virtual scoped_ptr<SandboxBPFPolicy> GetSandboxBPFPolicy() override { |
117 return scoped_ptr<SandboxBPFPolicy>(new EnosysPtracePolicy()); | 117 return scoped_ptr<SandboxBPFPolicy>(new EnosysPtracePolicy()); |
118 } | 118 } |
119 virtual void RunTestFunction() OVERRIDE { | 119 virtual void RunTestFunction() override { |
120 errno = 0; | 120 errno = 0; |
121 int ret = ptrace(PTRACE_TRACEME, -1, NULL, NULL); | 121 int ret = ptrace(PTRACE_TRACEME, -1, NULL, NULL); |
122 BPF_ASSERT(-1 == ret); | 122 BPF_ASSERT(-1 == ret); |
123 BPF_ASSERT(ENOSYS == errno); | 123 BPF_ASSERT(ENOSYS == errno); |
124 } | 124 } |
125 | 125 |
126 private: | 126 private: |
127 DISALLOW_COPY_AND_ASSIGN(BasicBPFTesterDelegate); | 127 DISALLOW_COPY_AND_ASSIGN(BasicBPFTesterDelegate); |
128 }; | 128 }; |
129 | 129 |
(...skipping 15 matching lines...) Expand all Loading... |
145 BPFDeathTestWithInlineTest, | 145 BPFDeathTestWithInlineTest, |
146 DEATH_MESSAGE(kHelloMessage), | 146 DEATH_MESSAGE(kHelloMessage), |
147 EnosysPtracePolicy) { | 147 EnosysPtracePolicy) { |
148 LOG(ERROR) << kHelloMessage; | 148 LOG(ERROR) << kHelloMessage; |
149 _exit(1); | 149 _exit(1); |
150 } | 150 } |
151 | 151 |
152 } // namespace | 152 } // namespace |
153 | 153 |
154 } // namespace sandbox | 154 } // namespace sandbox |
OLD | NEW |