OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/win/src/process_mitigations.h" |
| 6 |
| 7 #include <psapi.h> |
| 8 |
| 9 #include "base/command_line.h" |
5 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
6 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
| 12 #include "base/memory/free_deleter.h" |
7 #include "base/path_service.h" | 13 #include "base/path_service.h" |
8 #include "base/process/launch.h" | 14 #include "base/process/launch.h" |
| 15 #include "base/scoped_native_library.h" |
9 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 17 #include "base/test/test_timeouts.h" |
| 18 #include "base/threading/platform_thread.h" |
| 19 #include "base/time/time.h" |
| 20 #include "base/win/registry.h" |
10 #include "base/win/scoped_handle.h" | 21 #include "base/win/scoped_handle.h" |
| 22 #include "base/win/startup_information.h" |
| 23 #include "base/win/win_util.h" |
11 #include "base/win/windows_version.h" | 24 #include "base/win/windows_version.h" |
12 #include "sandbox/win/src/nt_internals.h" | 25 #include "sandbox/win/src/nt_internals.h" |
13 #include "sandbox/win/src/process_mitigations.h" | |
14 #include "sandbox/win/src/sandbox.h" | 26 #include "sandbox/win/src/sandbox.h" |
15 #include "sandbox/win/src/sandbox_factory.h" | 27 #include "sandbox/win/src/sandbox_factory.h" |
16 #include "sandbox/win/src/target_services.h" | 28 #include "sandbox/win/src/target_services.h" |
17 #include "sandbox/win/src/win_utils.h" | |
18 #include "sandbox/win/tests/common/controller.h" | 29 #include "sandbox/win/tests/common/controller.h" |
| 30 #include "sandbox/win/tests/integration_tests/integration_tests_common.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
20 | 32 |
21 namespace { | 33 namespace { |
22 | 34 |
23 // API defined in winbase.h. | 35 // API defined in winbase.h. |
24 typedef decltype(GetProcessDEPPolicy)* GetProcessDEPPolicyFunction; | 36 typedef decltype(GetProcessDEPPolicy)* GetProcessDEPPolicyFunction; |
25 | 37 |
26 // API defined in processthreadsapi.h. | 38 // API defined in processthreadsapi.h. |
27 typedef decltype( | 39 typedef decltype( |
28 GetProcessMitigationPolicy)* GetProcessMitigationPolicyFunction; | 40 GetProcessMitigationPolicy)* GetProcessMitigationPolicyFunction; |
29 GetProcessMitigationPolicyFunction get_process_mitigation_policy; | 41 GetProcessMitigationPolicyFunction get_process_mitigation_policy; |
30 | 42 |
31 // APIs defined in wingdi.h. | 43 // APIs defined in wingdi.h. |
32 typedef decltype(AddFontMemResourceEx)* AddFontMemResourceExFunction; | 44 typedef decltype(AddFontMemResourceEx)* AddFontMemResourceExFunction; |
33 typedef decltype(RemoveFontMemResourceEx)* RemoveFontMemResourceExFunction; | 45 typedef decltype(RemoveFontMemResourceEx)* RemoveFontMemResourceExFunction; |
34 | 46 |
| 47 // APIs defined in integration_tests_common.h |
| 48 typedef decltype(WasHookCalled)* WasHookCalledFunction; |
| 49 typedef decltype(SetHook)* SetHookFunction; |
| 50 |
35 #if !defined(_WIN64) | 51 #if !defined(_WIN64) |
36 bool CheckWin8DepPolicy() { | 52 bool CheckWin8DepPolicy() { |
37 PROCESS_MITIGATION_DEP_POLICY policy = {}; | 53 PROCESS_MITIGATION_DEP_POLICY policy = {}; |
38 if (!get_process_mitigation_policy(::GetCurrentProcess(), ProcessDEPPolicy, | 54 if (!get_process_mitigation_policy(::GetCurrentProcess(), ProcessDEPPolicy, |
39 &policy, sizeof(policy))) { | 55 &policy, sizeof(policy))) { |
40 return false; | 56 return false; |
41 } | 57 } |
42 return policy.Enable && policy.Permanent; | 58 return policy.Enable && policy.Permanent; |
43 } | 59 } |
44 #endif // !defined(_WIN64) | 60 #endif // !defined(_WIN64) |
45 | 61 |
46 #if defined(NDEBUG) | 62 #if defined(NDEBUG) |
47 bool CheckWin8AslrPolicy() { | 63 bool CheckWin8AslrPolicy() { |
48 PROCESS_MITIGATION_ASLR_POLICY policy = {}; | 64 PROCESS_MITIGATION_ASLR_POLICY policy = {}; |
49 if (!get_process_mitigation_policy(::GetCurrentProcess(), ProcessASLRPolicy, | 65 if (!get_process_mitigation_policy(::GetCurrentProcess(), ProcessASLRPolicy, |
50 &policy, sizeof(policy))) { | 66 &policy, sizeof(policy))) { |
51 return false; | 67 return false; |
52 } | 68 } |
53 return policy.EnableForceRelocateImages && policy.DisallowStrippedImages; | 69 return policy.EnableForceRelocateImages && policy.DisallowStrippedImages; |
54 } | 70 } |
55 #endif // defined(NDEBUG) | 71 #endif // defined(NDEBUG) |
56 | 72 |
57 bool CheckWin8StrictHandlePolicy() { | 73 bool CheckWin8StrictHandlePolicy() { |
58 PROCESS_MITIGATION_STRICT_HANDLE_CHECK_POLICY policy = {}; | 74 PROCESS_MITIGATION_STRICT_HANDLE_CHECK_POLICY policy = {}; |
59 if (!get_process_mitigation_policy(::GetCurrentProcess(), | 75 if (!get_process_mitigation_policy(::GetCurrentProcess(), |
60 ProcessStrictHandleCheckPolicy, | 76 ProcessStrictHandleCheckPolicy, &policy, |
61 &policy, sizeof(policy))) { | 77 sizeof(policy))) { |
62 return false; | 78 return false; |
63 } | 79 } |
64 return policy.RaiseExceptionOnInvalidHandleReference && | 80 return policy.RaiseExceptionOnInvalidHandleReference && |
65 policy.HandleExceptionsPermanentlyEnabled; | 81 policy.HandleExceptionsPermanentlyEnabled; |
66 } | 82 } |
67 | 83 |
68 bool CheckWin8Win32CallPolicy() { | 84 bool CheckWin8Win32CallPolicy() { |
69 PROCESS_MITIGATION_SYSTEM_CALL_DISABLE_POLICY policy = {}; | 85 PROCESS_MITIGATION_SYSTEM_CALL_DISABLE_POLICY policy = {}; |
70 if (!get_process_mitigation_policy(::GetCurrentProcess(), | 86 if (!get_process_mitigation_policy(::GetCurrentProcess(), |
71 ProcessSystemCallDisablePolicy, | 87 ProcessSystemCallDisablePolicy, &policy, |
72 &policy, sizeof(policy))) { | 88 sizeof(policy))) { |
73 return false; | 89 return false; |
74 } | 90 } |
75 return policy.DisallowWin32kSystemCalls; | 91 return policy.DisallowWin32kSystemCalls; |
76 } | 92 } |
77 | 93 |
78 bool CheckWin8DllExtensionPolicy() { | 94 bool CheckWin8ExtensionPointPolicy() { |
79 PROCESS_MITIGATION_EXTENSION_POINT_DISABLE_POLICY policy = {}; | 95 PROCESS_MITIGATION_EXTENSION_POINT_DISABLE_POLICY policy = {}; |
80 if (!get_process_mitigation_policy(::GetCurrentProcess(), | 96 if (!get_process_mitigation_policy(::GetCurrentProcess(), |
81 ProcessExtensionPointDisablePolicy, | 97 ProcessExtensionPointDisablePolicy, |
82 &policy, sizeof(policy))) { | 98 &policy, sizeof(policy))) { |
83 return false; | 99 return false; |
84 } | 100 } |
85 return policy.DisableExtensionPoints; | 101 return policy.DisableExtensionPoints; |
86 } | 102 } |
87 | 103 |
88 bool CheckWin10FontPolicy() { | 104 bool CheckWin10FontPolicy() { |
89 PROCESS_MITIGATION_FONT_DISABLE_POLICY policy = {}; | 105 PROCESS_MITIGATION_FONT_DISABLE_POLICY policy = {}; |
90 if (!get_process_mitigation_policy(::GetCurrentProcess(), | 106 if (!get_process_mitigation_policy(::GetCurrentProcess(), |
91 ProcessFontDisablePolicy, &policy, | 107 ProcessFontDisablePolicy, &policy, |
92 sizeof(policy))) { | 108 sizeof(policy))) { |
93 return false; | 109 return false; |
94 } | 110 } |
95 return policy.DisableNonSystemFonts; | 111 return policy.DisableNonSystemFonts; |
96 } | 112 } |
97 | 113 |
98 bool CheckWin10ImageLoadNoRemotePolicy() { | 114 bool CheckWin10ImageLoadNoRemotePolicy() { |
99 PROCESS_MITIGATION_IMAGE_LOAD_POLICY policy = {}; | 115 PROCESS_MITIGATION_IMAGE_LOAD_POLICY policy = {}; |
100 if (!get_process_mitigation_policy(::GetCurrentProcess(), | 116 if (!get_process_mitigation_policy(::GetCurrentProcess(), |
101 ProcessImageLoadPolicy, &policy, | 117 ProcessImageLoadPolicy, &policy, |
102 sizeof(policy))) { | 118 sizeof(policy))) { |
103 return false; | 119 return false; |
104 } | 120 } |
105 return policy.NoRemoteImages; | 121 return policy.NoRemoteImages; |
106 } | 122 } |
107 | 123 |
| 124 // Spawn Windows process (with or without mitigation enabled). |
| 125 void SpawnWinProc(PROCESS_INFORMATION* pi, bool success_test, HANDLE* event) { |
| 126 base::win::StartupInformation startup_info; |
| 127 DWORD creation_flags = 0; |
| 128 |
| 129 if (!success_test) { |
| 130 DWORD64 flags = |
| 131 PROCESS_CREATION_MITIGATION_POLICY_EXTENSION_POINT_DISABLE_ALWAYS_ON; |
| 132 // This test only runs on >= Win8, so I don't have to worry about |
| 133 // illegal 64-bit flags on 32-bit <= Win7. |
| 134 size_t flags_size = sizeof(flags); |
| 135 |
| 136 EXPECT_TRUE(startup_info.InitializeProcThreadAttributeList(1)); |
| 137 EXPECT_TRUE(startup_info.UpdateProcThreadAttribute( |
| 138 PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY, &flags, flags_size)); |
| 139 creation_flags = EXTENDED_STARTUPINFO_PRESENT; |
| 140 } |
| 141 |
| 142 // Command line must be writable. |
| 143 std::unique_ptr<wchar_t, base::FreeDeleter> cmd_writeable( |
| 144 ::wcsdup(g_winproc_file)); |
| 145 |
| 146 EXPECT_TRUE(::CreateProcessW(NULL, cmd_writeable.get(), NULL, NULL, FALSE, |
| 147 creation_flags, NULL, NULL, |
| 148 startup_info.startup_info(), pi)); |
| 149 EXPECT_EQ(WAIT_OBJECT_0, |
| 150 ::WaitForSingleObject(*event, g_winproc_event_max_wait_ms)); |
| 151 |
| 152 return; |
| 153 } |
| 154 |
| 155 //------------------------------------------------------------------------------ |
| 156 // 1. Spawn our Windows process (with or without mitigation enabled). |
| 157 // 2. Load our hook Dll locally. |
| 158 // 3. Start the hook (for our WinProc or globally). |
| 159 // 4. Send a keystroke event. |
| 160 // 5. Ask the hook Dll if it received a hook callback. |
| 161 // 6. Cleanup the hooking. |
| 162 // 7. Signal our Windows process to shutdown. |
| 163 // |
| 164 // Do NOT use any ASSERTs in this function. Cleanup required. |
| 165 //------------------------------------------------------------------------------ |
| 166 void TestWin8ExtensionPointHookWrapper(bool is_success_test, bool global_hook) { |
| 167 // 1. Spawn WinProc. |
| 168 PROCESS_INFORMATION proc_info = {}; |
| 169 HANDLE event = ::CreateEventW(NULL, FALSE, FALSE, g_winproc_event); |
| 170 EXPECT_TRUE(event != NULL && event != INVALID_HANDLE_VALUE); |
| 171 SpawnWinProc(&proc_info, is_success_test, &event); |
| 172 |
| 173 // 2. Load the hook DLL. |
| 174 base::FilePath hook_dll_path(g_hook_dll_file); |
| 175 base::ScopedNativeLibrary dll(hook_dll_path); |
| 176 EXPECT_TRUE(dll.is_valid()); |
| 177 |
| 178 HOOKPROC hook_proc = |
| 179 reinterpret_cast<HOOKPROC>(dll.GetFunctionPointer(g_hook_handler_func)); |
| 180 WasHookCalledFunction WasHookCalled = reinterpret_cast<WasHookCalledFunction>( |
| 181 dll.GetFunctionPointer(g_was_hook_called_func)); |
| 182 SetHookFunction SetHook = reinterpret_cast<SetHookFunction>( |
| 183 dll.GetFunctionPointer(g_set_hook_func)); |
| 184 EXPECT_TRUE(hook_proc && WasHookCalled && SetHook); |
| 185 |
| 186 // 3. Try installing the hook (either on a remote target thread, |
| 187 // or globally). |
| 188 DWORD target = 0; |
| 189 if (!global_hook) |
| 190 target = proc_info.dwThreadId; |
| 191 HHOOK hook = ::SetWindowsHookExW(WH_KEYBOARD, hook_proc, dll.get(), target); |
| 192 EXPECT_TRUE(hook); |
| 193 SetHook(hook); |
| 194 |
| 195 // 4. Inject a keyboard event. |
| 196 |
| 197 // Note: that PostThreadMessage and SendMessage APIs will not deliver |
| 198 // a keystroke in such a way that triggers a "legitimate" hook. |
| 199 // Have to use targetless SendInput or keybd_event. The latter is |
| 200 // less code and easier to work with. |
| 201 keybd_event(VkKeyScan(L'A'), 0, 0, 0); |
| 202 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(500)); |
| 203 |
| 204 keybd_event(VkKeyScan(L'A'), 0, KEYEVENTF_KEYUP, 0); |
| 205 // Give it a chance to hit the hook handler... |
| 206 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1)); |
| 207 |
| 208 // 5. Did the hook get hit? Was it expected to? |
| 209 if (global_hook) |
| 210 EXPECT_EQ((is_success_test ? true : false), WasHookCalled()); |
| 211 else |
| 212 // ***IMPORTANT: when targeting a specific thread id, the |
| 213 // PROCESS_CREATION_MITIGATION_POLICY_EXTENSION_POINT_DISABLE |
| 214 // mitigation does NOT disable the hook API. It ONLY |
| 215 // stops global hooks from running in your process. Hence, |
| 216 // we expect the hook to have hit (TRUE) even in the "failure" |
| 217 // case for a non-global/targetted hook. |
| 218 EXPECT_EQ((is_success_test ? true : true), WasHookCalled()); |
| 219 |
| 220 // 6. Disable hook. |
| 221 if (hook) |
| 222 EXPECT_TRUE(::UnhookWindowsHookEx(hook)); |
| 223 |
| 224 // 7. Trigger shutdown of WinProc. |
| 225 if (::PostThreadMessageW(proc_info.dwThreadId, WM_QUIT, 0, 0)) { |
| 226 // Note: The combination/perfect-storm of a Global Hook, in a |
| 227 // WinProc that has the EXTENSION_POINT_DISABLE mitigation ON, and the |
| 228 // use of the SendInput or keybd_event API to inject a keystroke, |
| 229 // results in the target becoming unresponsive. If any one of these states |
| 230 // are changed, the problem does not occur. |
| 231 // This means the WM_QUIT message is not handled and the call to |
| 232 // WaitForSingleObject times out. Therefore not checking the return val. |
| 233 ::WaitForSingleObject(event, g_winproc_event_max_wait_ms); |
| 234 EXPECT_TRUE(::CloseHandle(event)); |
| 235 } else { |
| 236 // Make sure we don't leave a stray. |
| 237 ::TerminateProcess(proc_info.hProcess, 0); |
| 238 EXPECT_TRUE(false); |
| 239 } |
| 240 EXPECT_TRUE(::CloseHandle(proc_info.hThread)); |
| 241 EXPECT_TRUE(::CloseHandle(proc_info.hProcess)); |
| 242 } |
| 243 |
| 244 //------------------------------------------------------------------------------ |
| 245 // 1. Set up our AppInit Dll in registry settings. (Enable) |
| 246 // 2. Spawn our Windows process (with or without mitigation enabled). |
| 247 // 3. Check if our AppInit Dll is loaded in our Windows process or not. |
| 248 // 4. Signal our Windows process to shutdown. |
| 249 // 5. Restore original reg settings. |
| 250 // |
| 251 // Do NOT use any ASSERTs in this function. Cleanup required. |
| 252 //------------------------------------------------------------------------------ |
| 253 void TestWin8ExtensionPointAppInitWrapper(bool is_success_test) { |
| 254 // 0.5 Get path of current module. The appropriate build of the |
| 255 // AppInit DLL will be in the same directory (and we need to put the |
| 256 // full path in reg). |
| 257 wchar_t path[MAX_PATH]; |
| 258 EXPECT_TRUE(::GetModuleFileNameW(NULL, path, MAX_PATH)); |
| 259 // We just want the directory. |
| 260 wchar_t* last_separator = ::wcsrchr(path, L'\\'); |
| 261 EXPECT_TRUE(last_separator); |
| 262 last_separator++; |
| 263 *last_separator = L'\0'; |
| 264 ::wcsncat(path, g_hook_dll_file, (MAX_PATH - ::wcslen(path))); |
| 265 // Now make sure the path is in "short-name" form for registry. |
| 266 DWORD length = ::GetShortPathNameW(path, NULL, 0); |
| 267 std::vector<wchar_t> short_name(length); |
| 268 EXPECT_TRUE(::GetShortPathNameW(path, &short_name[0], length)); |
| 269 |
| 270 // 1. Reg setup. |
| 271 wchar_t* app_init_reg_path = |
| 272 L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Windows"; |
| 273 wchar_t* dlls_value_name = L"AppInit_DLLs"; |
| 274 wchar_t* enabled_value_name = L"LoadAppInit_DLLs"; |
| 275 wchar_t* signing_value_name = L"RequireSignedAppInit_DLLs"; |
| 276 std::wstring orig_dlls; |
| 277 std::wstring new_dlls; |
| 278 DWORD orig_enabled_value = 0; |
| 279 DWORD orig_signing_value = 0; |
| 280 base::win::RegKey app_init_key(HKEY_LOCAL_MACHINE, app_init_reg_path, |
| 281 KEY_QUERY_VALUE | KEY_SET_VALUE); |
| 282 // Backup the existing settings. |
| 283 EXPECT_TRUE(app_init_key.Valid()); |
| 284 EXPECT_TRUE(app_init_key.HasValue(dlls_value_name) && |
| 285 app_init_key.HasValue(enabled_value_name)); |
| 286 EXPECT_EQ(ERROR_SUCCESS, app_init_key.ReadValue(dlls_value_name, &orig_dlls)); |
| 287 EXPECT_EQ(ERROR_SUCCESS, |
| 288 app_init_key.ReadValueDW(enabled_value_name, &orig_enabled_value)); |
| 289 if (app_init_key.HasValue(signing_value_name)) |
| 290 EXPECT_EQ(ERROR_SUCCESS, app_init_key.ReadValueDW(signing_value_name, |
| 291 &orig_signing_value)); |
| 292 |
| 293 // Set the new settings we want (obviously requires local admin privileges). |
| 294 new_dlls = orig_dlls; |
| 295 if (0 != orig_dlls.compare(L"")) |
| 296 new_dlls.append(L","); |
| 297 new_dlls.append(short_name.data()); |
| 298 |
| 299 EXPECT_EQ(ERROR_SUCCESS, |
| 300 app_init_key.WriteValue(dlls_value_name, new_dlls.c_str())); |
| 301 if (app_init_key.HasValue(signing_value_name)) |
| 302 EXPECT_EQ(ERROR_SUCCESS, app_init_key.WriteValue(signing_value_name, |
| 303 static_cast<DWORD>(0))); |
| 304 EXPECT_EQ(ERROR_SUCCESS, |
| 305 app_init_key.WriteValue(enabled_value_name, static_cast<DWORD>(1))); |
| 306 |
| 307 // 2. Spawn WinProc. |
| 308 HANDLE event = ::CreateEventW(NULL, FALSE, FALSE, g_winproc_event); |
| 309 EXPECT_TRUE(event != NULL && event != INVALID_HANDLE_VALUE); |
| 310 base::win::ScopedHandle scoped_event(event); |
| 311 PROCESS_INFORMATION proc_info = {}; |
| 312 SpawnWinProc(&proc_info, is_success_test, &event); |
| 313 |
| 314 // 3. Check loaded modules in WinProc to see if AppInit dll is loaded. |
| 315 std::vector<HMODULE>(modules); |
| 316 EXPECT_TRUE( |
| 317 base::win::GetLoadedModulesSnapshot(proc_info.hProcess, &modules)); |
| 318 bool dll_loaded = false; |
| 319 |
| 320 for (auto module : modules) { |
| 321 wchar_t name[MAX_PATH]; |
| 322 EXPECT_TRUE( |
| 323 ::GetModuleFileNameExW(proc_info.hProcess, module, name, MAX_PATH)); |
| 324 |
| 325 // Compare to our dll name! |
| 326 if (::wcsstr(name, g_hook_dll_file)) { |
| 327 // Found it. |
| 328 dll_loaded = true; |
| 329 break; |
| 330 } |
| 331 } |
| 332 |
| 333 // Did we pass the test as expected? |
| 334 EXPECT_EQ((is_success_test ? true : false), dll_loaded); |
| 335 |
| 336 // 4. Trigger shutdown of WinProc. |
| 337 if (::PostThreadMessageW(proc_info.dwThreadId, WM_QUIT, 0, 0)) { |
| 338 ::WaitForSingleObject(event, g_winproc_event_max_wait_ms); |
| 339 } else { |
| 340 // Make sure we don't leave a stray. |
| 341 ::TerminateProcess(proc_info.hProcess, 0); |
| 342 EXPECT_TRUE(false); |
| 343 } |
| 344 EXPECT_TRUE(::CloseHandle(proc_info.hThread)); |
| 345 EXPECT_TRUE(::CloseHandle(proc_info.hProcess)); |
| 346 |
| 347 // 5. Reg Restore |
| 348 EXPECT_EQ(ERROR_SUCCESS, |
| 349 app_init_key.WriteValue(enabled_value_name, orig_enabled_value)); |
| 350 if (app_init_key.HasValue(signing_value_name)) |
| 351 EXPECT_EQ(ERROR_SUCCESS, |
| 352 app_init_key.WriteValue(signing_value_name, orig_signing_value)); |
| 353 EXPECT_EQ(ERROR_SUCCESS, |
| 354 app_init_key.WriteValue(dlls_value_name, orig_dlls.c_str())); |
| 355 app_init_key.Close(); |
| 356 } |
| 357 |
108 void TestWin10ImageLoadRemote(bool is_success_test) { | 358 void TestWin10ImageLoadRemote(bool is_success_test) { |
109 // ***Insert your manual testing share UNC path here! | 359 // ***Insert your manual testing share UNC path here! |
110 // E.g.: \\\\hostname\\sharename\\calc.exe | 360 // E.g.: \\\\hostname\\sharename\\calc.exe |
111 std::wstring unc = L"\"\\\\hostname\\sharename\\calc.exe\""; | 361 std::wstring unc = L"\"\\\\hostname\\sharename\\calc.exe\""; |
112 | 362 |
113 sandbox::TestRunner runner; | 363 sandbox::TestRunner runner; |
114 sandbox::TargetPolicy* policy = runner.GetPolicy(); | 364 sandbox::TargetPolicy* policy = runner.GetPolicy(); |
115 | 365 |
116 // Set a policy that would normally allow for process creation. | 366 // Set a policy that would normally allow for process creation. |
117 policy->SetJobLevel(sandbox::JOB_NONE, 0); | 367 policy->SetJobLevel(sandbox::JOB_NONE, 0); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 setup_proc.Terminate(desired_exit_code, false); | 480 setup_proc.Terminate(desired_exit_code, false); |
231 return SBOX_TEST_SUCCEEDED; | 481 return SBOX_TEST_SUCCEEDED; |
232 } | 482 } |
233 // Note: GetLastError from CreateProcess returns 5, "ERROR_ACCESS_DENIED". | 483 // Note: GetLastError from CreateProcess returns 5, "ERROR_ACCESS_DENIED". |
234 return SBOX_TEST_FAILED; | 484 return SBOX_TEST_FAILED; |
235 } | 485 } |
236 | 486 |
237 //------------------------------------------------------------------------------ | 487 //------------------------------------------------------------------------------ |
238 // Win8 Checks: | 488 // Win8 Checks: |
239 // MITIGATION_DEP(_NO_ATL_THUNK) | 489 // MITIGATION_DEP(_NO_ATL_THUNK) |
240 // MITIGATION_EXTENSION_DLL_DISABLE | |
241 // MITIGATION_RELOCATE_IMAGE(_REQUIRED) - ASLR, release only | 490 // MITIGATION_RELOCATE_IMAGE(_REQUIRED) - ASLR, release only |
242 // MITIGATION_STRICT_HANDLE_CHECKS | 491 // MITIGATION_STRICT_HANDLE_CHECKS |
243 // >= Win8 | 492 // >= Win8 |
244 //------------------------------------------------------------------------------ | 493 //------------------------------------------------------------------------------ |
245 | 494 |
246 SBOX_TESTS_COMMAND int CheckWin8(int argc, wchar_t **argv) { | 495 SBOX_TESTS_COMMAND int CheckWin8(int argc, wchar_t** argv) { |
247 get_process_mitigation_policy = | 496 get_process_mitigation_policy = |
248 reinterpret_cast<GetProcessMitigationPolicyFunction>( | 497 reinterpret_cast<GetProcessMitigationPolicyFunction>(::GetProcAddress( |
249 ::GetProcAddress(::GetModuleHandleW(L"kernel32.dll"), | 498 ::GetModuleHandleW(L"kernel32.dll"), "GetProcessMitigationPolicy")); |
250 "GetProcessMitigationPolicy")); | |
251 if (!get_process_mitigation_policy) | 499 if (!get_process_mitigation_policy) |
252 return SBOX_TEST_NOT_FOUND; | 500 return SBOX_TEST_NOT_FOUND; |
253 | 501 |
254 #if !defined(_WIN64) // DEP is always enabled on 64-bit. | 502 #if !defined(_WIN64) // DEP is always enabled on 64-bit. |
255 if (!CheckWin8DepPolicy()) | 503 if (!CheckWin8DepPolicy()) |
256 return SBOX_TEST_FIRST_ERROR; | 504 return SBOX_TEST_FIRST_ERROR; |
257 #endif | 505 #endif |
258 | 506 |
259 #if defined(NDEBUG) // ASLR cannot be forced in debug builds. | 507 #if defined(NDEBUG) // ASLR cannot be forced in debug builds. |
260 if (!CheckWin8AslrPolicy()) | 508 if (!CheckWin8AslrPolicy()) |
261 return SBOX_TEST_SECOND_ERROR; | 509 return SBOX_TEST_SECOND_ERROR; |
262 #endif | 510 #endif |
263 | 511 |
264 if (!CheckWin8StrictHandlePolicy()) | 512 if (!CheckWin8StrictHandlePolicy()) |
265 return SBOX_TEST_THIRD_ERROR; | 513 return SBOX_TEST_THIRD_ERROR; |
266 | 514 |
267 if (!CheckWin8DllExtensionPolicy()) | |
268 return SBOX_TEST_FIFTH_ERROR; | |
269 | |
270 return SBOX_TEST_SUCCEEDED; | 515 return SBOX_TEST_SUCCEEDED; |
271 } | 516 } |
272 | 517 |
273 TEST(ProcessMitigationsTest, CheckWin8) { | 518 TEST(ProcessMitigationsTest, CheckWin8) { |
274 if (base::win::GetVersion() < base::win::VERSION_WIN8) | 519 if (base::win::GetVersion() < base::win::VERSION_WIN8) |
275 return; | 520 return; |
276 | 521 |
277 TestRunner runner; | 522 TestRunner runner; |
278 sandbox::TargetPolicy* policy = runner.GetPolicy(); | 523 sandbox::TargetPolicy* policy = runner.GetPolicy(); |
279 | 524 |
280 sandbox::MitigationFlags mitigations = MITIGATION_DEP | | 525 sandbox::MitigationFlags mitigations = |
281 MITIGATION_DEP_NO_ATL_THUNK | | 526 MITIGATION_DEP | MITIGATION_DEP_NO_ATL_THUNK; |
282 MITIGATION_EXTENSION_DLL_DISABLE; | |
283 #if defined(NDEBUG) // ASLR cannot be forced in debug builds. | 527 #if defined(NDEBUG) // ASLR cannot be forced in debug builds. |
284 mitigations |= MITIGATION_RELOCATE_IMAGE | | 528 mitigations |= MITIGATION_RELOCATE_IMAGE | MITIGATION_RELOCATE_IMAGE_REQUIRED; |
285 MITIGATION_RELOCATE_IMAGE_REQUIRED; | |
286 #endif | 529 #endif |
287 | 530 |
288 EXPECT_EQ(policy->SetProcessMitigations(mitigations), SBOX_ALL_OK); | 531 EXPECT_EQ(policy->SetProcessMitigations(mitigations), SBOX_ALL_OK); |
289 | 532 |
290 mitigations |= MITIGATION_STRICT_HANDLE_CHECKS; | 533 mitigations |= MITIGATION_STRICT_HANDLE_CHECKS; |
291 | 534 |
292 EXPECT_EQ(policy->SetDelayedProcessMitigations(mitigations), SBOX_ALL_OK); | 535 EXPECT_EQ(policy->SetDelayedProcessMitigations(mitigations), SBOX_ALL_OK); |
293 | 536 |
294 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckWin8")); | 537 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckWin8")); |
295 } | 538 } |
296 | 539 |
297 //------------------------------------------------------------------------------ | 540 //------------------------------------------------------------------------------ |
298 // DEP (MITIGATION_DEP) | 541 // DEP (MITIGATION_DEP) |
299 // < Win8 x86 | 542 // < Win8 x86 |
300 //------------------------------------------------------------------------------ | 543 //------------------------------------------------------------------------------ |
301 | 544 |
302 SBOX_TESTS_COMMAND int CheckDep(int argc, wchar_t **argv) { | 545 SBOX_TESTS_COMMAND int CheckDep(int argc, wchar_t** argv) { |
303 GetProcessDEPPolicyFunction get_process_dep_policy = | 546 GetProcessDEPPolicyFunction get_process_dep_policy = |
304 reinterpret_cast<GetProcessDEPPolicyFunction>( | 547 reinterpret_cast<GetProcessDEPPolicyFunction>(::GetProcAddress( |
305 ::GetProcAddress(::GetModuleHandleW(L"kernel32.dll"), | 548 ::GetModuleHandleW(L"kernel32.dll"), "GetProcessDEPPolicy")); |
306 "GetProcessDEPPolicy")); | |
307 if (get_process_dep_policy) { | 549 if (get_process_dep_policy) { |
308 BOOL is_permanent = FALSE; | 550 BOOL is_permanent = FALSE; |
309 DWORD dep_flags = 0; | 551 DWORD dep_flags = 0; |
310 | 552 |
311 if (!get_process_dep_policy(::GetCurrentProcess(), &dep_flags, | 553 if (!get_process_dep_policy(::GetCurrentProcess(), &dep_flags, |
312 &is_permanent)) { | 554 &is_permanent)) { |
313 return SBOX_TEST_FIRST_ERROR; | 555 return SBOX_TEST_FIRST_ERROR; |
314 } | 556 } |
315 | 557 |
316 if (!(dep_flags & PROCESS_DEP_ENABLE) || !is_permanent) | 558 if (!(dep_flags & PROCESS_DEP_ENABLE) || !is_permanent) |
317 return SBOX_TEST_SECOND_ERROR; | 559 return SBOX_TEST_SECOND_ERROR; |
318 | 560 |
319 } else { | 561 } else { |
320 NtQueryInformationProcessFunction query_information_process = NULL; | 562 NtQueryInformationProcessFunction query_information_process = NULL; |
321 ResolveNTFunctionPtr("NtQueryInformationProcess", | 563 ResolveNTFunctionPtr("NtQueryInformationProcess", |
322 &query_information_process); | 564 &query_information_process); |
323 if (!query_information_process) | 565 if (!query_information_process) |
324 return SBOX_TEST_NOT_FOUND; | 566 return SBOX_TEST_NOT_FOUND; |
325 | 567 |
326 ULONG size = 0; | 568 ULONG size = 0; |
327 ULONG dep_flags = 0; | 569 ULONG dep_flags = 0; |
328 if (!SUCCEEDED(query_information_process(::GetCurrentProcess(), | 570 if (!SUCCEEDED(query_information_process(::GetCurrentProcess(), |
329 ProcessExecuteFlags, &dep_flags, | 571 ProcessExecuteFlags, &dep_flags, |
330 sizeof(dep_flags), &size))) { | 572 sizeof(dep_flags), &size))) { |
331 return SBOX_TEST_THIRD_ERROR; | 573 return SBOX_TEST_THIRD_ERROR; |
332 } | 574 } |
333 | 575 |
334 static const int MEM_EXECUTE_OPTION_DISABLE = 2; | 576 static const int MEM_EXECUTE_OPTION_DISABLE = 2; |
335 static const int MEM_EXECUTE_OPTION_PERMANENT = 8; | 577 static const int MEM_EXECUTE_OPTION_PERMANENT = 8; |
336 dep_flags &= 0xff; | 578 dep_flags &= 0xff; |
337 | 579 |
338 if (dep_flags != (MEM_EXECUTE_OPTION_DISABLE | | 580 if (dep_flags != |
339 MEM_EXECUTE_OPTION_PERMANENT)) { | 581 (MEM_EXECUTE_OPTION_DISABLE | MEM_EXECUTE_OPTION_PERMANENT)) { |
340 return SBOX_TEST_FOURTH_ERROR; | 582 return SBOX_TEST_FOURTH_ERROR; |
341 } | 583 } |
342 } | 584 } |
343 | 585 |
344 return SBOX_TEST_SUCCEEDED; | 586 return SBOX_TEST_SUCCEEDED; |
345 } | 587 } |
346 | 588 |
347 #if !defined(_WIN64) // DEP is always enabled on 64-bit. | 589 #if !defined(_WIN64) // DEP is always enabled on 64-bit. |
348 TEST(ProcessMitigationsTest, CheckDep) { | 590 TEST(ProcessMitigationsTest, CheckDep) { |
349 if (base::win::GetVersion() > base::win::VERSION_WIN7) | 591 if (base::win::GetVersion() > base::win::VERSION_WIN7) |
350 return; | 592 return; |
351 | 593 |
352 TestRunner runner; | 594 TestRunner runner; |
353 sandbox::TargetPolicy* policy = runner.GetPolicy(); | 595 sandbox::TargetPolicy* policy = runner.GetPolicy(); |
354 | 596 |
355 EXPECT_EQ(policy->SetProcessMitigations( | 597 EXPECT_EQ(policy->SetProcessMitigations(MITIGATION_DEP | |
356 MITIGATION_DEP | | 598 MITIGATION_DEP_NO_ATL_THUNK | |
357 MITIGATION_DEP_NO_ATL_THUNK | | 599 MITIGATION_SEHOP), |
358 MITIGATION_SEHOP), | |
359 SBOX_ALL_OK); | 600 SBOX_ALL_OK); |
360 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckDep")); | 601 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckDep")); |
361 } | 602 } |
362 #endif | 603 #endif |
363 | 604 |
364 //------------------------------------------------------------------------------ | 605 //------------------------------------------------------------------------------ |
365 // Win32k Lockdown (MITIGATION_WIN32K_DISABLE) | 606 // Win32k Lockdown (MITIGATION_WIN32K_DISABLE) |
366 // >= Win8 | 607 // >= Win8 |
367 //------------------------------------------------------------------------------ | 608 //------------------------------------------------------------------------------ |
368 | 609 |
369 SBOX_TESTS_COMMAND int CheckWin8Lockdown(int argc, wchar_t **argv) { | 610 SBOX_TESTS_COMMAND int CheckWin8Lockdown(int argc, wchar_t** argv) { |
370 get_process_mitigation_policy = | 611 get_process_mitigation_policy = |
371 reinterpret_cast<GetProcessMitigationPolicyFunction>( | 612 reinterpret_cast<GetProcessMitigationPolicyFunction>(::GetProcAddress( |
372 ::GetProcAddress(::GetModuleHandleW(L"kernel32.dll"), | 613 ::GetModuleHandleW(L"kernel32.dll"), "GetProcessMitigationPolicy")); |
373 "GetProcessMitigationPolicy")); | |
374 if (!get_process_mitigation_policy) | 614 if (!get_process_mitigation_policy) |
375 return SBOX_TEST_NOT_FOUND; | 615 return SBOX_TEST_NOT_FOUND; |
376 | 616 |
377 if (!CheckWin8Win32CallPolicy()) | 617 if (!CheckWin8Win32CallPolicy()) |
378 return SBOX_TEST_FIRST_ERROR; | 618 return SBOX_TEST_FIRST_ERROR; |
379 return SBOX_TEST_SUCCEEDED; | 619 return SBOX_TEST_SUCCEEDED; |
380 } | 620 } |
381 | 621 |
382 // This test validates that setting the MITIGATION_WIN32K_DISABLE mitigation on | 622 // This test validates that setting the MITIGATION_WIN32K_DISABLE mitigation on |
383 // the target process causes the launch to fail in process initialization. | 623 // the target process causes the launch to fail in process initialization. |
(...skipping 23 matching lines...) Expand all Loading... |
407 | 647 |
408 EXPECT_EQ(policy->SetProcessMitigations(MITIGATION_WIN32K_DISABLE), | 648 EXPECT_EQ(policy->SetProcessMitigations(MITIGATION_WIN32K_DISABLE), |
409 SBOX_ALL_OK); | 649 SBOX_ALL_OK); |
410 EXPECT_EQ(policy->AddRule(sandbox::TargetPolicy::SUBSYS_WIN32K_LOCKDOWN, | 650 EXPECT_EQ(policy->AddRule(sandbox::TargetPolicy::SUBSYS_WIN32K_LOCKDOWN, |
411 sandbox::TargetPolicy::FAKE_USER_GDI_INIT, NULL), | 651 sandbox::TargetPolicy::FAKE_USER_GDI_INIT, NULL), |
412 sandbox::SBOX_ALL_OK); | 652 sandbox::SBOX_ALL_OK); |
413 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckWin8Lockdown")); | 653 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckWin8Lockdown")); |
414 } | 654 } |
415 | 655 |
416 //------------------------------------------------------------------------------ | 656 //------------------------------------------------------------------------------ |
| 657 // Disable extension points (MITIGATION_EXTENSION_POINT_DISABLE). |
| 658 // >= Win8 |
| 659 //------------------------------------------------------------------------------ |
| 660 SBOX_TESTS_COMMAND int CheckWin8ExtensionPointSetting(int argc, |
| 661 wchar_t** argv) { |
| 662 get_process_mitigation_policy = |
| 663 reinterpret_cast<GetProcessMitigationPolicyFunction>(::GetProcAddress( |
| 664 ::GetModuleHandleW(L"kernel32.dll"), "GetProcessMitigationPolicy")); |
| 665 if (!get_process_mitigation_policy) |
| 666 return SBOX_TEST_NOT_FOUND; |
| 667 |
| 668 if (!CheckWin8ExtensionPointPolicy()) |
| 669 return SBOX_TEST_FIRST_ERROR; |
| 670 return SBOX_TEST_SUCCEEDED; |
| 671 } |
| 672 |
| 673 // This test validates that setting the MITIGATION_EXTENSION_POINT_DISABLE |
| 674 // mitigation enables the setting on a process. |
| 675 TEST(ProcessMitigationsTest, CheckWin8ExtensionPointPolicySuccess) { |
| 676 if (base::win::GetVersion() < base::win::VERSION_WIN8) |
| 677 return; |
| 678 |
| 679 TestRunner runner; |
| 680 sandbox::TargetPolicy* policy = runner.GetPolicy(); |
| 681 |
| 682 EXPECT_EQ(policy->SetProcessMitigations(MITIGATION_EXTENSION_POINT_DISABLE), |
| 683 SBOX_ALL_OK); |
| 684 EXPECT_EQ(SBOX_TEST_SUCCEEDED, |
| 685 runner.RunTest(L"CheckWin8ExtensionPointSetting")); |
| 686 } |
| 687 |
| 688 // This test validates that we CAN add a "legitimate" global hook on the |
| 689 // sandboxed |
| 690 // proc/thread if the MITIGATION_EXTENSION_POINT_DISABLE mitigation is not set. |
| 691 // |
| 692 // MANUAL testing only. |
| 693 TEST(ProcessMitigationsTest, |
| 694 DISABLED_CheckWin8ExtensionPoint_GlobalHook_Success) { |
| 695 if (base::win::GetVersion() < base::win::VERSION_WIN8) |
| 696 return; |
| 697 |
| 698 HANDLE mutex = ::CreateMutexW(NULL, FALSE, g_extension_point_test_mutex); |
| 699 EXPECT_TRUE(mutex != NULL && mutex != INVALID_HANDLE_VALUE); |
| 700 EXPECT_EQ(WAIT_OBJECT_0, |
| 701 ::WaitForSingleObject(mutex, g_test_mutex_max_wait_ms)); |
| 702 |
| 703 // (is_success_test, global_hook) |
| 704 TestWin8ExtensionPointHookWrapper(true, true); |
| 705 |
| 706 EXPECT_TRUE(::ReleaseMutex(mutex)); |
| 707 EXPECT_TRUE(::CloseHandle(mutex)); |
| 708 } |
| 709 |
| 710 // This test validates that setting the MITIGATION_EXTENSION_POINT_DISABLE |
| 711 // mitigation prevents a global hook in our WinProc. |
| 712 // |
| 713 // MANUAL testing only. |
| 714 TEST(ProcessMitigationsTest, |
| 715 DISABLED_CheckWin8ExtensionPoint_GlobalHook_Failure) { |
| 716 if (base::win::GetVersion() < base::win::VERSION_WIN8) |
| 717 return; |
| 718 |
| 719 HANDLE mutex = ::CreateMutexW(NULL, FALSE, g_extension_point_test_mutex); |
| 720 EXPECT_TRUE(mutex != NULL && mutex != INVALID_HANDLE_VALUE); |
| 721 EXPECT_EQ(WAIT_OBJECT_0, |
| 722 ::WaitForSingleObject(mutex, g_test_mutex_max_wait_ms)); |
| 723 |
| 724 // (is_success_test, global_hook) |
| 725 TestWin8ExtensionPointHookWrapper(false, true); |
| 726 |
| 727 EXPECT_TRUE(::ReleaseMutex(mutex)); |
| 728 EXPECT_TRUE(::CloseHandle(mutex)); |
| 729 } |
| 730 |
| 731 // This test validates that we CAN add a "legitimate" hook on the sandboxed |
| 732 // proc/thread if the MITIGATION_EXTENSION_POINT_DISABLE mitigation is not set. |
| 733 // |
| 734 // MANUAL testing only. |
| 735 TEST(ProcessMitigationsTest, DISABLED_CheckWin8ExtensionPoint_Hook_Success) { |
| 736 if (base::win::GetVersion() < base::win::VERSION_WIN8) |
| 737 return; |
| 738 |
| 739 HANDLE mutex = ::CreateMutexW(NULL, FALSE, g_extension_point_test_mutex); |
| 740 EXPECT_TRUE(mutex != NULL && mutex != INVALID_HANDLE_VALUE); |
| 741 EXPECT_EQ(WAIT_OBJECT_0, |
| 742 ::WaitForSingleObject(mutex, g_test_mutex_max_wait_ms)); |
| 743 |
| 744 // (is_success_test, global_hook) |
| 745 TestWin8ExtensionPointHookWrapper(true, false); |
| 746 |
| 747 EXPECT_TRUE(::ReleaseMutex(mutex)); |
| 748 EXPECT_TRUE(::CloseHandle(mutex)); |
| 749 } |
| 750 |
| 751 // *** Important: MITIGATION_EXTENSION_POINT_DISABLE does NOT prevent |
| 752 // hooks targetted at a specific thread id. It only prevents |
| 753 // global hooks. So this test does NOT actually expect the hook |
| 754 // to fail (see TestWin8ExtensionPointHookWrapper function) even |
| 755 // with the mitigation on. |
| 756 // |
| 757 // MANUAL testing only. |
| 758 TEST(ProcessMitigationsTest, DISABLED_CheckWin8ExtensionPoint_Hook_Failure) { |
| 759 if (base::win::GetVersion() < base::win::VERSION_WIN8) |
| 760 return; |
| 761 |
| 762 HANDLE mutex = ::CreateMutexW(NULL, FALSE, g_extension_point_test_mutex); |
| 763 EXPECT_TRUE(mutex != NULL && mutex != INVALID_HANDLE_VALUE); |
| 764 EXPECT_EQ(WAIT_OBJECT_0, |
| 765 ::WaitForSingleObject(mutex, g_test_mutex_max_wait_ms)); |
| 766 |
| 767 // (is_success_test, global_hook) |
| 768 TestWin8ExtensionPointHookWrapper(false, false); |
| 769 |
| 770 EXPECT_TRUE(::ReleaseMutex(mutex)); |
| 771 EXPECT_TRUE(::CloseHandle(mutex)); |
| 772 } |
| 773 |
| 774 // This test validates that we CAN add an AppInit Dll to a target |
| 775 // WinProc if the MITIGATION_EXTENSION_POINT_DISABLE mitigation is not set. |
| 776 // |
| 777 // MANUAL testing only. |
| 778 // Must run this test as admin/elevated. |
| 779 TEST(ProcessMitigationsTest, DISABLED_CheckWin8ExtensionPoint_AppInit_Success) { |
| 780 if (base::win::GetVersion() < base::win::VERSION_WIN8) |
| 781 return; |
| 782 |
| 783 HANDLE mutex = ::CreateMutexW(NULL, FALSE, g_extension_point_test_mutex); |
| 784 EXPECT_TRUE(mutex != NULL && mutex != INVALID_HANDLE_VALUE); |
| 785 EXPECT_EQ(WAIT_OBJECT_0, |
| 786 ::WaitForSingleObject(mutex, g_test_mutex_max_wait_ms)); |
| 787 |
| 788 TestWin8ExtensionPointAppInitWrapper(true); |
| 789 |
| 790 EXPECT_TRUE(::ReleaseMutex(mutex)); |
| 791 EXPECT_TRUE(::CloseHandle(mutex)); |
| 792 } |
| 793 |
| 794 // This test validates that setting the MITIGATION_EXTENSION_POINT_DISABLE |
| 795 // mitigation prevents the loading of any AppInit Dll into our WinProc. |
| 796 // |
| 797 // MANUAL testing only. |
| 798 // Must run this test as admin/elevated. |
| 799 TEST(ProcessMitigationsTest, DISABLED_CheckWin8ExtensionPoint_AppInit_Failure) { |
| 800 if (base::win::GetVersion() < base::win::VERSION_WIN8) |
| 801 return; |
| 802 |
| 803 HANDLE mutex = ::CreateMutexW(NULL, FALSE, g_extension_point_test_mutex); |
| 804 EXPECT_TRUE(mutex != NULL && mutex != INVALID_HANDLE_VALUE); |
| 805 EXPECT_EQ(WAIT_OBJECT_0, |
| 806 ::WaitForSingleObject(mutex, g_test_mutex_max_wait_ms)); |
| 807 |
| 808 TestWin8ExtensionPointAppInitWrapper(false); |
| 809 |
| 810 EXPECT_TRUE(::ReleaseMutex(mutex)); |
| 811 EXPECT_TRUE(::CloseHandle(mutex)); |
| 812 } |
| 813 |
| 814 //------------------------------------------------------------------------------ |
417 // Disable non-system font loads (MITIGATION_NONSYSTEM_FONT_DISABLE) | 815 // Disable non-system font loads (MITIGATION_NONSYSTEM_FONT_DISABLE) |
418 // >= Win10 | 816 // >= Win10 |
419 //------------------------------------------------------------------------------ | 817 //------------------------------------------------------------------------------ |
420 | 818 |
421 SBOX_TESTS_COMMAND int CheckWin10FontLockDown(int argc, wchar_t** argv) { | 819 SBOX_TESTS_COMMAND int CheckWin10FontLockDown(int argc, wchar_t** argv) { |
422 get_process_mitigation_policy = | 820 get_process_mitigation_policy = |
423 reinterpret_cast<GetProcessMitigationPolicyFunction>(::GetProcAddress( | 821 reinterpret_cast<GetProcessMitigationPolicyFunction>(::GetProcAddress( |
424 ::GetModuleHandleW(L"kernel32.dll"), "GetProcessMitigationPolicy")); | 822 ::GetModuleHandleW(L"kernel32.dll"), "GetProcessMitigationPolicy")); |
425 if (!get_process_mitigation_policy) | 823 if (!get_process_mitigation_policy) |
426 return SBOX_TEST_NOT_FOUND; | 824 return SBOX_TEST_NOT_FOUND; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 policy->SetDelayedProcessMitigations(MITIGATION_IMAGE_LOAD_NO_REMOTE), | 969 policy->SetDelayedProcessMitigations(MITIGATION_IMAGE_LOAD_NO_REMOTE), |
572 SBOX_ALL_OK); | 970 SBOX_ALL_OK); |
573 EXPECT_EQ(SBOX_TEST_SUCCEEDED, | 971 EXPECT_EQ(SBOX_TEST_SUCCEEDED, |
574 runner.RunTest(L"CheckWin10ImageLoadNoRemote")); | 972 runner.RunTest(L"CheckWin10ImageLoadNoRemote")); |
575 } | 973 } |
576 | 974 |
577 // This test validates that we CAN create a new process from | 975 // This test validates that we CAN create a new process from |
578 // a remote UNC device, if the MITIGATION_IMAGE_LOAD_NO_REMOTE | 976 // a remote UNC device, if the MITIGATION_IMAGE_LOAD_NO_REMOTE |
579 // mitigation is NOT set. | 977 // mitigation is NOT set. |
580 // | 978 // |
581 // DISABLED for automated testing bots. Enable for manual testing. | 979 // MANUAL testing only. |
582 TEST(ProcessMitigationsTest, DISABLED_CheckWin10ImageLoadNoRemoteSuccess) { | 980 TEST(ProcessMitigationsTest, DISABLED_CheckWin10ImageLoadNoRemoteSuccess) { |
583 if (base::win::GetVersion() < base::win::VERSION_WIN10_TH2) | 981 if (base::win::GetVersion() < base::win::VERSION_WIN10_TH2) |
584 return; | 982 return; |
585 | 983 |
586 TestWin10ImageLoadRemote(true); | 984 TestWin10ImageLoadRemote(true); |
587 } | 985 } |
588 | 986 |
589 // This test validates that setting the MITIGATION_IMAGE_LOAD_NO_REMOTE | 987 // This test validates that setting the MITIGATION_IMAGE_LOAD_NO_REMOTE |
590 // mitigation prevents creating a new process from a remote | 988 // mitigation prevents creating a new process from a remote |
591 // UNC device. | 989 // UNC device. |
592 // | 990 // |
593 // DISABLED for automated testing bots. Enable for manual testing. | 991 // MANUAL testing only. |
594 TEST(ProcessMitigationsTest, DISABLED_CheckWin10ImageLoadNoRemoteFailure) { | 992 TEST(ProcessMitigationsTest, DISABLED_CheckWin10ImageLoadNoRemoteFailure) { |
595 if (base::win::GetVersion() < base::win::VERSION_WIN10_TH2) | 993 if (base::win::GetVersion() < base::win::VERSION_WIN10_TH2) |
596 return; | 994 return; |
597 | 995 |
598 TestWin10ImageLoadRemote(false); | 996 TestWin10ImageLoadRemote(false); |
599 } | 997 } |
600 | 998 |
601 //------------------------------------------------------------------------------ | 999 //------------------------------------------------------------------------------ |
602 // Disable image load when "mandatory low label" (integrity level). | 1000 // Disable image load when "mandatory low label" (integrity level). |
603 // (MITIGATION_IMAGE_LOAD_NO_LOW_LABEL) | 1001 // (MITIGATION_IMAGE_LOAD_NO_LOW_LABEL) |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 cmd = cmd.Append(L"calc.exe"); | 1123 cmd = cmd.Append(L"calc.exe"); |
726 | 1124 |
727 std::wstring test_command(base::StringPrintf(L"TestChildProcess %ls 0x%08X", | 1125 std::wstring test_command(base::StringPrintf(L"TestChildProcess %ls 0x%08X", |
728 cmd.value().c_str(), | 1126 cmd.value().c_str(), |
729 STATUS_ACCESS_VIOLATION)); | 1127 STATUS_ACCESS_VIOLATION)); |
730 | 1128 |
731 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(test_command.c_str())); | 1129 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(test_command.c_str())); |
732 } | 1130 } |
733 | 1131 |
734 } // namespace sandbox | 1132 } // namespace sandbox |
OLD | NEW |