| 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> |
| 11 #include <unistd.h> | 11 #include <unistd.h> |
| 12 | 12 |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" | 16 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" |
| 17 #include "sandbox/linux/services/linux_syscalls.h" | 17 #include "sandbox/linux/services/linux_syscalls.h" |
| 18 #include "sandbox/linux/tests/unit_tests.h" | 18 #include "sandbox/linux/tests/unit_tests.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 20 |
| 21 namespace sandbox { | 21 namespace sandbox { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 ErrorCode EmptyPolicy(SandboxBPF* sandbox, int sysno, void* aux) { | |
| 26 // |aux| should always be NULL since a type was not specified as an argument | |
| 27 // to BPF_TEST. | |
| 28 BPF_ASSERT(NULL == aux); | |
| 29 if (!SandboxBPF::IsValidSyscallNumber(sysno)) { | |
| 30 return ErrorCode(ENOSYS); | |
| 31 } else { | |
| 32 return ErrorCode(ErrorCode::ERR_ALLOWED); | |
| 33 } | |
| 34 } | |
| 35 | |
| 36 BPF_TEST(BPFTest, BPFAUXIsNull, EmptyPolicy) { | |
| 37 // Check that the implicit BPF_AUX argument is NULL when we | |
| 38 // don't specify a fourth parameter to BPF_TEST. | |
| 39 BPF_ASSERT(NULL == BPF_AUX); | |
| 40 } | |
| 41 | |
| 42 class FourtyTwo { | 25 class FourtyTwo { |
| 43 public: | 26 public: |
| 44 static const int kMagicValue = 42; | 27 static const int kMagicValue = 42; |
| 45 FourtyTwo() : value_(kMagicValue) {} | 28 FourtyTwo() : value_(kMagicValue) {} |
| 46 int value() { return value_; } | 29 int value() { return value_; } |
| 47 | 30 |
| 48 private: | 31 private: |
| 49 int value_; | 32 int value_; |
| 50 DISALLOW_COPY_AND_ASSIGN(FourtyTwo); | 33 DISALLOW_COPY_AND_ASSIGN(FourtyTwo); |
| 51 }; | 34 }; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 BPF_TEST_C(BPFTest, BPFTestWithInlineTest, EnosysPtracePolicy) { | 130 BPF_TEST_C(BPFTest, BPFTestWithInlineTest, EnosysPtracePolicy) { |
| 148 errno = 0; | 131 errno = 0; |
| 149 int ret = ptrace(PTRACE_TRACEME, -1, NULL, NULL); | 132 int ret = ptrace(PTRACE_TRACEME, -1, NULL, NULL); |
| 150 BPF_ASSERT(-1 == ret); | 133 BPF_ASSERT(-1 == ret); |
| 151 BPF_ASSERT(ENOSYS == errno); | 134 BPF_ASSERT(ENOSYS == errno); |
| 152 } | 135 } |
| 153 | 136 |
| 154 } // namespace | 137 } // namespace |
| 155 | 138 |
| 156 } // namespace sandbox | 139 } // namespace sandbox |
| OLD | NEW |