| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/services/namespace_sandbox.h" | 5 #include "sandbox/linux/services/namespace_sandbox.h" |
| 6 | 6 |
| 7 #include <sys/types.h> | 7 #include <sys/types.h> |
| 8 #include <sys/wait.h> | 8 #include <sys/wait.h> |
| 9 #include <unistd.h> | 9 #include <unistd.h> |
| 10 | 10 |
| 11 #include <string> | 11 #include <string> |
| 12 #include <utility> | 12 #include <utility> |
| 13 | 13 |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/files/file_enumerator.h" | 15 #include "base/files/file_enumerator.h" |
| 16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/process/launch.h" | 19 #include "base/process/launch.h" |
| 20 #include "base/process/process.h" | 20 #include "base/process/process.h" |
| 21 #include "base/test/multiprocess_test.h" | 21 #include "base/test/multiprocess_test.h" |
| 22 #include "sandbox/linux/services/credentials.h" | 22 #include "sandbox/linux/services/credentials.h" |
| 23 #include "sandbox/linux/services/namespace_utils.h" | 23 #include "sandbox/linux/services/namespace_utils.h" |
| 24 #include "sandbox/linux/services/proc_util.h" |
| 24 #include "sandbox/linux/tests/unit_tests.h" | 25 #include "sandbox/linux/tests/unit_tests.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 26 #include "testing/multiprocess_func_list.h" | 27 #include "testing/multiprocess_func_list.h" |
| 27 | 28 |
| 28 namespace sandbox { | 29 namespace sandbox { |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| 31 | 32 |
| 32 bool RootDirectoryIsEmpty() { | 33 bool RootDirectoryIsEmpty() { |
| 33 base::FilePath root("/"); | 34 base::FilePath root("/"); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 return 0; | 79 return 0; |
| 79 } | 80 } |
| 80 | 81 |
| 81 TEST_F(NamespaceSandboxTest, BasicUsage) { | 82 TEST_F(NamespaceSandboxTest, BasicUsage) { |
| 82 TestProc("SimpleChildProcess"); | 83 TestProc("SimpleChildProcess"); |
| 83 } | 84 } |
| 84 | 85 |
| 85 MULTIPROCESS_TEST_MAIN(ChrootMe) { | 86 MULTIPROCESS_TEST_MAIN(ChrootMe) { |
| 86 CHECK(!RootDirectoryIsEmpty()); | 87 CHECK(!RootDirectoryIsEmpty()); |
| 87 CHECK(sandbox::Credentials::MoveToNewUserNS()); | 88 CHECK(sandbox::Credentials::MoveToNewUserNS()); |
| 88 CHECK(sandbox::Credentials::DropFileSystemAccess()); | 89 CHECK(sandbox::Credentials::DropFileSystemAccess(ProcUtil::OpenProc().get())); |
| 89 CHECK(RootDirectoryIsEmpty()); | 90 CHECK(RootDirectoryIsEmpty()); |
| 90 return 0; | 91 return 0; |
| 91 } | 92 } |
| 92 | 93 |
| 93 // Temporarily disabled on ASAN due to crbug.com/451603. | 94 // Temporarily disabled on ASAN due to crbug.com/451603. |
| 94 TEST_F(NamespaceSandboxTest, DISABLE_ON_ASAN(ChrootAndDropCapabilities)) { | 95 TEST_F(NamespaceSandboxTest, DISABLE_ON_ASAN(ChrootAndDropCapabilities)) { |
| 95 TestProc("ChrootMe"); | 96 TestProc("ChrootMe"); |
| 96 } | 97 } |
| 97 | 98 |
| 98 MULTIPROCESS_TEST_MAIN(NestedNamespaceSandbox) { | 99 MULTIPROCESS_TEST_MAIN(NestedNamespaceSandbox) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 113 return 0; | 114 return 0; |
| 114 } | 115 } |
| 115 | 116 |
| 116 TEST_F(NamespaceSandboxTest, NestedNamespaceSandbox) { | 117 TEST_F(NamespaceSandboxTest, NestedNamespaceSandbox) { |
| 117 TestProc("NestedNamespaceSandbox"); | 118 TestProc("NestedNamespaceSandbox"); |
| 118 } | 119 } |
| 119 | 120 |
| 120 } // namespace | 121 } // namespace |
| 121 | 122 |
| 122 } // namespace sandbox | 123 } // namespace sandbox |
| OLD | NEW |