| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Integration tests for restricted tokens. |
| 6 |
| 7 #include <stddef.h> |
| 8 #include <string> |
| 9 |
| 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/win/scoped_handle.h" |
| 12 #include "sandbox/win/src/sandbox.h" |
| 13 #include "sandbox/win/src/sandbox_factory.h" |
| 14 #include "sandbox/win/src/target_services.h" |
| 15 #include "sandbox/win/tests/common/controller.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 |
| 18 namespace sandbox { |
| 19 |
| 20 namespace { |
| 21 |
| 22 int RunOpenProcessTest(bool unsandboxed, |
| 23 bool lockdown_dacl, |
| 24 DWORD access_mask) { |
| 25 TestRunner runner(JOB_NONE, USER_RESTRICTED_SAME_ACCESS, USER_LOCKDOWN); |
| 26 runner.GetPolicy()->SetDelayedIntegrityLevel(INTEGRITY_LEVEL_UNTRUSTED); |
| 27 runner.GetPolicy()->SetIntegrityLevel(INTEGRITY_LEVEL_LOW); |
| 28 if (lockdown_dacl) |
| 29 runner.GetPolicy()->SetLockdownDefaultDacl(); |
| 30 runner.SetAsynchronous(true); |
| 31 // This spins up a renderer level process, we don't care about the result. |
| 32 runner.RunTest(L"IntegrationTestsTest_args 1"); |
| 33 |
| 34 TestRunner runner2(JOB_NONE, USER_RESTRICTED_SAME_ACCESS, USER_LIMITED); |
| 35 runner2.GetPolicy()->SetDelayedIntegrityLevel(INTEGRITY_LEVEL_LOW); |
| 36 runner2.GetPolicy()->SetIntegrityLevel(INTEGRITY_LEVEL_LOW); |
| 37 runner2.SetUnsandboxed(unsandboxed); |
| 38 return runner2.RunTest( |
| 39 base::StringPrintf(L"RestrictedTokenTest_openprocess %d 0x%08X", |
| 40 runner.process_id(), access_mask) |
| 41 .c_str()); |
| 42 } |
| 43 |
| 44 } // namespace |
| 45 |
| 46 // Opens a process based on a PID and access mask passed on the command line. |
| 47 // Returns SBOX_TEST_SUCCEEDED if process opened successfully. |
| 48 SBOX_TESTS_COMMAND int RestrictedTokenTest_openprocess(int argc, |
| 49 wchar_t** argv) { |
| 50 if (argc < 2) |
| 51 return SBOX_TEST_NOT_FOUND; |
| 52 DWORD pid = _wtoi(argv[0]); |
| 53 if (pid == 0) |
| 54 return SBOX_TEST_NOT_FOUND; |
| 55 DWORD desired_access = wcstoul(argv[1], nullptr, 0); |
| 56 base::win::ScopedHandle process_handle( |
| 57 ::OpenProcess(desired_access, FALSE, pid)); |
| 58 if (process_handle.IsValid()) |
| 59 return SBOX_TEST_SUCCEEDED; |
| 60 |
| 61 return SBOX_TEST_DENIED; |
| 62 } |
| 63 |
| 64 TEST(RestrictedTokenTest, OpenLowPrivilegedProcess) { |
| 65 // Test limited privilege to renderer open. |
| 66 ASSERT_EQ(SBOX_TEST_SUCCEEDED, |
| 67 RunOpenProcessTest(false, false, GENERIC_READ | GENERIC_WRITE)); |
| 68 // Test limited privilege to renderer open with lockdowned DACL. |
| 69 ASSERT_EQ(SBOX_TEST_DENIED, |
| 70 RunOpenProcessTest(false, true, GENERIC_READ | GENERIC_WRITE)); |
| 71 // Ensure we also can't get any access to the process. |
| 72 ASSERT_EQ(SBOX_TEST_DENIED, RunOpenProcessTest(false, true, MAXIMUM_ALLOWED)); |
| 73 // Also check for explicit owner allowed WRITE_DAC right. |
| 74 ASSERT_EQ(SBOX_TEST_DENIED, RunOpenProcessTest(false, true, WRITE_DAC)); |
| 75 // Ensure unsandboxed process can still open the renderer for all access. |
| 76 ASSERT_EQ(SBOX_TEST_SUCCEEDED, |
| 77 RunOpenProcessTest(true, true, PROCESS_ALL_ACCESS)); |
| 78 } |
| 79 |
| 80 } // namespace sandbox |
| OLD | NEW |