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 15 matching lines...) Expand all Loading... | |
26 public: | 26 public: |
27 static const int kMagicValue = 42; | 27 static const int kMagicValue = 42; |
28 FourtyTwo() : value_(kMagicValue) {} | 28 FourtyTwo() : value_(kMagicValue) {} |
29 int value() { return value_; } | 29 int value() { return value_; } |
30 | 30 |
31 private: | 31 private: |
32 int value_; | 32 int value_; |
33 DISALLOW_COPY_AND_ASSIGN(FourtyTwo); | 33 DISALLOW_COPY_AND_ASSIGN(FourtyTwo); |
34 }; | 34 }; |
35 | 35 |
36 ErrorCode EmptyPolicyTakesClass(SandboxBPF* sandbox, | 36 class EmptyClassTakingPolicy : public SandboxBPFPolicy { |
37 int sysno, | 37 public: |
38 FourtyTwo* fourty_two) { | 38 EmptyClassTakingPolicy(FourtyTwo* fourty_two) { |
jln (very slow on Chromium)
2014/09/23 18:42:06
nit: explicit
mdempsky
2014/09/23 18:50:20
Done.
| |
39 // |aux| should point to an instance of FourtyTwo. | 39 BPF_ASSERT(fourty_two); |
40 BPF_ASSERT(fourty_two); | 40 BPF_ASSERT(FourtyTwo::kMagicValue == fourty_two->value()); |
41 BPF_ASSERT(FourtyTwo::kMagicValue == fourty_two->value()); | 41 } |
42 if (!SandboxBPF::IsValidSyscallNumber(sysno)) { | 42 virtual ~EmptyClassTakingPolicy() {} |
43 return ErrorCode(ENOSYS); | 43 |
44 } else { | 44 virtual ErrorCode EvaluateSyscall(SandboxBPF* sandbox, |
45 int sysno) const OVERRIDE { | |
46 DCHECK(SandboxBPF::IsValidSyscallNumber(sysno)); | |
45 return ErrorCode(ErrorCode::ERR_ALLOWED); | 47 return ErrorCode(ErrorCode::ERR_ALLOWED); |
46 } | 48 } |
47 } | 49 }; |
48 | 50 |
49 BPF_TEST(BPFTest, | 51 BPF_TEST(BPFTest, |
50 BPFAUXPointsToClass, | 52 BPFAUXPointsToClass, |
51 EmptyPolicyTakesClass, | 53 EmptyClassTakingPolicy, |
52 FourtyTwo /* *BPF_AUX */) { | 54 FourtyTwo /* *BPF_AUX */) { |
53 // BPF_AUX should point to an instance of FourtyTwo. | 55 // BPF_AUX should point to an instance of FourtyTwo. |
54 BPF_ASSERT(BPF_AUX); | 56 BPF_ASSERT(BPF_AUX); |
55 BPF_ASSERT(FourtyTwo::kMagicValue == BPF_AUX->value()); | 57 BPF_ASSERT(FourtyTwo::kMagicValue == BPF_AUX->value()); |
56 } | 58 } |
57 | 59 |
58 void DummyTestFunction(FourtyTwo *fourty_two) { | 60 void DummyTestFunction(FourtyTwo *fourty_two) { |
59 } | 61 } |
60 | 62 |
61 TEST(BPFTest, BPFTesterCompatibilityDelegateLeakTest) { | 63 TEST(BPFTest, BPFTesterCompatibilityDelegateLeakTest) { |
62 // Don't do anything, simply gives dynamic tools an opportunity to detect | 64 // Don't do anything, simply gives dynamic tools an opportunity to detect |
63 // leaks. | 65 // leaks. |
64 { | 66 { |
65 BPFTesterCompatibilityDelegate<FourtyTwo> simple_delegate( | 67 BPFTesterCompatibilityDelegate<EmptyClassTakingPolicy, FourtyTwo> |
66 DummyTestFunction, EmptyPolicyTakesClass); | 68 simple_delegate(DummyTestFunction); |
67 } | 69 } |
68 { | 70 { |
69 // Test polymorphism. | 71 // Test polymorphism. |
70 scoped_ptr<BPFTesterDelegate> simple_delegate( | 72 scoped_ptr<BPFTesterDelegate> simple_delegate( |
71 new BPFTesterCompatibilityDelegate<FourtyTwo>(DummyTestFunction, | 73 new BPFTesterCompatibilityDelegate<EmptyClassTakingPolicy, FourtyTwo>( |
72 EmptyPolicyTakesClass)); | 74 DummyTestFunction)); |
73 } | 75 } |
74 } | 76 } |
75 | 77 |
76 class EnosysPtracePolicy : public SandboxBPFPolicy { | 78 class EnosysPtracePolicy : public SandboxBPFPolicy { |
77 public: | 79 public: |
78 EnosysPtracePolicy() { | 80 EnosysPtracePolicy() { |
79 my_pid_ = syscall(__NR_getpid); | 81 my_pid_ = syscall(__NR_getpid); |
80 } | 82 } |
81 virtual ~EnosysPtracePolicy() { | 83 virtual ~EnosysPtracePolicy() { |
82 // Policies should be able to bind with the process on which they are | 84 // Policies should be able to bind with the process on which they are |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 BPFDeathTestWithInlineTest, | 142 BPFDeathTestWithInlineTest, |
141 DEATH_MESSAGE(kHelloMessage), | 143 DEATH_MESSAGE(kHelloMessage), |
142 EnosysPtracePolicy) { | 144 EnosysPtracePolicy) { |
143 LOG(ERROR) << kHelloMessage; | 145 LOG(ERROR) << kHelloMessage; |
144 _exit(1); | 146 _exit(1); |
145 } | 147 } |
146 | 148 |
147 } // namespace | 149 } // namespace |
148 | 150 |
149 } // namespace sandbox | 151 } // namespace sandbox |
OLD | NEW |