| OLD | NEW |
| 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 #ifndef SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTS_H__ | 5 #ifndef SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTS_H__ |
| 6 #define SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTS_H__ | 6 #define SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTS_H__ |
| 7 | 7 |
| 8 #include <fcntl.h> |
| 9 #include <sys/stat.h> |
| 10 #include <sys/types.h> |
| 11 |
| 8 #include "sandbox/linux/tests/unit_tests.h" | 12 #include "sandbox/linux/tests/unit_tests.h" |
| 9 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" | 13 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" |
| 10 | 14 |
| 11 | 15 |
| 12 namespace sandbox { | 16 namespace sandbox { |
| 13 | 17 |
| 14 // A BPF_DEATH_TEST is just the same as a BPF_TEST, but it assumes that the | 18 // A BPF_DEATH_TEST is just the same as a BPF_TEST, but it assumes that the |
| 15 // test will fail with a particular known error condition. Use the DEATH_XXX() | 19 // test will fail with a particular known error condition. Use the DEATH_XXX() |
| 16 // macros from unit_tests.h to specify the expected error condition. | 20 // macros from unit_tests.h to specify the expected error condition. |
| 17 #define BPF_DEATH_TEST(test_case_name, test_name, death, policy, aux...) \ | 21 #define BPF_DEATH_TEST(test_case_name, test_name, death, policy, aux...) \ |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 playground2::Die::EnableSimpleExit(); | 78 playground2::Die::EnableSimpleExit(); |
| 75 if (playground2::Sandbox::SupportsSeccompSandbox(-1) == | 79 if (playground2::Sandbox::SupportsSeccompSandbox(-1) == |
| 76 playground2::Sandbox::STATUS_AVAILABLE) { | 80 playground2::Sandbox::STATUS_AVAILABLE) { |
| 77 // Ensure the the sandbox is actually available at this time | 81 // Ensure the the sandbox is actually available at this time |
| 78 int proc_fd; | 82 int proc_fd; |
| 79 BPF_ASSERT((proc_fd = open("/proc", O_RDONLY|O_DIRECTORY)) >= 0); | 83 BPF_ASSERT((proc_fd = open("/proc", O_RDONLY|O_DIRECTORY)) >= 0); |
| 80 BPF_ASSERT(playground2::Sandbox::SupportsSeccompSandbox(proc_fd) == | 84 BPF_ASSERT(playground2::Sandbox::SupportsSeccompSandbox(proc_fd) == |
| 81 playground2::Sandbox::STATUS_AVAILABLE); | 85 playground2::Sandbox::STATUS_AVAILABLE); |
| 82 | 86 |
| 83 // Initialize and then start the sandbox with our custom policy | 87 // Initialize and then start the sandbox with our custom policy |
| 84 playground2::Sandbox::set_proc_fd(proc_fd); | 88 playground2::Sandbox sandbox; |
| 85 playground2::Sandbox::SetSandboxPolicy(arg->policy(), &arg->aux_); | 89 sandbox.set_proc_fd(proc_fd); |
| 86 playground2::Sandbox::StartSandbox(); | 90 sandbox.SetSandboxPolicy(arg->policy(), &arg->aux_); |
| 91 sandbox.Sandbox::StartSandbox(); |
| 87 | 92 |
| 88 arg->test()(arg->aux_); | 93 arg->test()(arg->aux_); |
| 89 } else { | 94 } else { |
| 90 // Call the compiler and verify the policy. That's the least we can do, | 95 // Call the compiler and verify the policy. That's the least we can do, |
| 91 // if we don't have kernel support. | 96 // if we don't have kernel support. |
| 92 playground2::Sandbox::SetSandboxPolicy(arg->policy(), &arg->aux_); | 97 playground2::Sandbox sandbox; |
| 98 sandbox.SetSandboxPolicy(arg->policy(), &arg->aux_); |
| 93 playground2::Sandbox::Program *program = | 99 playground2::Sandbox::Program *program = |
| 94 playground2::Sandbox::AssembleFilter(true /* force_verification */); | 100 sandbox.AssembleFilter(true /* force_verification */); |
| 95 delete program; | 101 delete program; |
| 96 sandbox::UnitTests::IgnoreThisTest(); | 102 sandbox::UnitTests::IgnoreThisTest(); |
| 97 } | 103 } |
| 98 } | 104 } |
| 99 | 105 |
| 100 private: | 106 private: |
| 101 DISALLOW_IMPLICIT_CONSTRUCTORS(BpfTests); | 107 DISALLOW_IMPLICIT_CONSTRUCTORS(BpfTests); |
| 102 }; | 108 }; |
| 103 | 109 |
| 104 } // namespace | 110 } // namespace |
| 105 | 111 |
| 106 #endif // SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTS_H__ | 112 #endif // SANDBOX_LINUX_SECCOMP_BPF_BPF_TESTS_H__ |
| OLD | NEW |