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 bool 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 don't have to handle | |
133 // illegal 64-bit flags on 32-bit <= Win7. | |
134 size_t flags_size = sizeof(flags); | |
135 | |
136 if (!startup_info.InitializeProcThreadAttributeList(1) || | |
137 !startup_info.UpdateProcThreadAttribute( | |
138 PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY, &flags, flags_size)) { | |
139 EXPECT_TRUE(false); | |
robertshield
2016/04/14 03:57:29
Can you use ADD_FAILURE() here and below?
penny
2016/04/24 18:50:49
Done. TIL. Thanks for telling me about that!
| |
140 return false; | |
141 } | |
142 creation_flags = EXTENDED_STARTUPINFO_PRESENT; | |
143 } | |
144 | |
145 // Command line must be writable. | |
146 std::unique_ptr<wchar_t, base::FreeDeleter> cmd_writeable( | |
147 ::wcsdup(g_winproc_file)); | |
robertshield
2016/04/14 03:57:29
I think this works and is a bit cleaner:
base::st
penny
2016/04/24 18:50:48
Done. Good one, thanks! I usually just think of
| |
148 | |
149 if (!::CreateProcessW(NULL, cmd_writeable.get(), NULL, NULL, FALSE, | |
150 creation_flags, NULL, NULL, startup_info.startup_info(), | |
151 pi)) { | |
152 EXPECT_TRUE(false); | |
153 return false; | |
154 } | |
155 EXPECT_EQ(WAIT_OBJECT_0, | |
156 ::WaitForSingleObject(*event, g_winproc_event_max_wait_ms)); | |
157 | |
158 return true; | |
159 } | |
160 | |
161 //------------------------------------------------------------------------------ | |
162 // 1. Spawn a Windows process (with or without mitigation enabled). | |
163 // 2. Load the hook Dll locally. | |
164 // 3. Start the hook (for the specific WinProc or globally). | |
165 // 4. Send a keystroke event. | |
166 // 5. Ask the hook Dll if it received a hook callback. | |
167 // 6. Cleanup the hooking. | |
168 // 7. Signal the Windows process to shutdown. | |
169 // | |
170 // Do NOT use any ASSERTs in this function. Cleanup required. | |
171 //------------------------------------------------------------------------------ | |
172 void TestWin8ExtensionPointHookWrapper(bool is_success_test, bool global_hook) { | |
173 // 1. Spawn WinProc. | |
174 HANDLE event = ::CreateEventW(NULL, FALSE, FALSE, g_winproc_event); | |
175 if (event == NULL || event == INVALID_HANDLE_VALUE) { | |
176 EXPECT_TRUE(false); | |
177 return; | |
178 } | |
179 base::win::ScopedHandle scoped_event(event); | |
180 PROCESS_INFORMATION proc_info = {}; | |
181 if (!SpawnWinProc(&proc_info, is_success_test, &event)) | |
182 return; | |
183 | |
184 // From this point on, no return on failure. Cleanup required. | |
185 bool all_good = true; | |
186 | |
187 // 2. Load the hook DLL. | |
188 base::FilePath hook_dll_path(g_hook_dll_file); | |
189 base::ScopedNativeLibrary dll(hook_dll_path); | |
190 EXPECT_TRUE(dll.is_valid()); | |
191 | |
192 HOOKPROC hook_proc = | |
193 reinterpret_cast<HOOKPROC>(dll.GetFunctionPointer(g_hook_handler_func)); | |
194 WasHookCalledFunction was_hook_called = | |
195 reinterpret_cast<WasHookCalledFunction>( | |
196 dll.GetFunctionPointer(g_was_hook_called_func)); | |
197 SetHookFunction set_hook = reinterpret_cast<SetHookFunction>( | |
198 dll.GetFunctionPointer(g_set_hook_func)); | |
199 if (!hook_proc || !was_hook_called || !set_hook) { | |
200 EXPECT_TRUE(false); | |
201 all_good = false; | |
202 } | |
203 | |
204 // 3. Try installing the hook (either on a remote target thread, | |
205 // or globally). | |
206 HHOOK hook = nullptr; | |
207 if (all_good) { | |
208 DWORD target = 0; | |
209 if (!global_hook) | |
210 target = proc_info.dwThreadId; | |
211 hook = ::SetWindowsHookExW(WH_KEYBOARD, hook_proc, dll.get(), target); | |
212 if (!hook) { | |
213 EXPECT_TRUE(false); | |
214 all_good = false; | |
215 } else | |
216 set_hook(hook); | |
217 } | |
218 | |
219 // 4. Inject a keyboard event. | |
220 if (all_good) { | |
221 // Note: that PostThreadMessage and SendMessage APIs will not deliver | |
222 // a keystroke in such a way that triggers a "legitimate" hook. | |
223 // Have to use targetless SendInput or keybd_event. The latter is | |
224 // less code and easier to work with. | |
225 keybd_event(VkKeyScan(L'A'), 0, 0, 0); | |
226 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(500)); | |
227 | |
228 keybd_event(VkKeyScan(L'A'), 0, KEYEVENTF_KEYUP, 0); | |
229 // Give it a chance to hit the hook handler... | |
230 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1)); | |
robertshield
2016/04/14 03:57:29
Sleep() in tests is a common cause of flakiness: i
penny
2016/04/24 18:50:48
Done. <sigh> I know, I was being lazy because I k
| |
231 | |
232 // 5. Did the hook get hit? Was it expected to? | |
233 if (global_hook) | |
234 EXPECT_EQ((is_success_test ? true : false), was_hook_called()); | |
235 else | |
236 // ***IMPORTANT: when targeting a specific thread id, the | |
237 // PROCESS_CREATION_MITIGATION_POLICY_EXTENSION_POINT_DISABLE | |
238 // mitigation does NOT disable the hook API. It ONLY | |
239 // stops global hooks from running in a process. Hence, | |
240 // the hook will hit (TRUE) even in the "failure" | |
241 // case for a non-global/targetted hook. | |
robertshield
2016/04/14 03:57:29
s/targetted/targeted/
penny
2016/04/24 18:50:49
Done.
| |
242 EXPECT_EQ((is_success_test ? true : true), was_hook_called()); | |
243 } | |
244 | |
245 // 6. Disable hook. | |
246 if (hook) | |
247 EXPECT_TRUE(::UnhookWindowsHookEx(hook)); | |
248 | |
249 // 7. Trigger shutdown of WinProc. | |
250 if (proc_info.hProcess) { | |
251 if (::PostThreadMessageW(proc_info.dwThreadId, WM_QUIT, 0, 0)) { | |
252 // Note: The combination/perfect-storm of a Global Hook, in a | |
253 // WinProc that has the EXTENSION_POINT_DISABLE mitigation ON, and the | |
254 // use of the SendInput or keybd_event API to inject a keystroke, | |
255 // results in the target becoming unresponsive. If any one of these | |
256 // states | |
robertshield
2016/04/14 03:57:29
nit: wrap
penny
2016/04/24 18:50:48
Done.
| |
257 // are changed, the problem does not occur. | |
258 // This means the WM_QUIT message is not handled and the call to | |
259 // WaitForSingleObject times out. Therefore not checking the return val. | |
260 ::WaitForSingleObject(event, g_winproc_event_max_wait_ms); | |
261 } else { | |
262 // Ensure no strays. | |
263 ::TerminateProcess(proc_info.hProcess, 0); | |
264 EXPECT_TRUE(false); | |
265 } | |
266 EXPECT_TRUE(::CloseHandle(proc_info.hThread)); | |
267 EXPECT_TRUE(::CloseHandle(proc_info.hProcess)); | |
268 } | |
269 } | |
270 | |
271 //------------------------------------------------------------------------------ | |
272 // 1. Set up the AppInit Dll in registry settings. (Enable) | |
273 // 2. Spawn a Windows process (with or without mitigation enabled). | |
274 // 3. Check if the AppInit Dll got loaded in the Windows process or not. | |
275 // 4. Signal the Windows process to shutdown. | |
276 // 5. Restore original reg settings. | |
277 // | |
278 // Do NOT use any ASSERTs in this function. Cleanup required. | |
279 //------------------------------------------------------------------------------ | |
280 void TestWin8ExtensionPointAppInitWrapper(bool is_success_test) { | |
281 // 0.5 Get path of current module. The appropriate build of the | |
282 // AppInit DLL will be in the same directory (and the | |
283 // full path is needed for reg). | |
284 wchar_t path[MAX_PATH]; | |
285 if (!::GetModuleFileNameW(NULL, path, MAX_PATH)) { | |
286 EXPECT_TRUE(false); | |
287 return; | |
288 } | |
289 // Only want the directory. Switch file name for the AppInit DLL. | |
290 base::FilePath full_dll_path(path); | |
291 full_dll_path = full_dll_path.DirName(); | |
292 full_dll_path = full_dll_path.Append(g_hook_dll_file); | |
293 wchar_t* non_const = const_cast<wchar_t*>(full_dll_path.value().c_str()); | |
294 // Now make sure the path is in "short-name" form for registry. | |
295 DWORD length = ::GetShortPathNameW(non_const, NULL, 0); | |
296 std::vector<wchar_t> short_name(length); | |
297 if (!::GetShortPathNameW(non_const, &short_name[0], length)) { | |
298 EXPECT_TRUE(false); | |
299 return; | |
300 } | |
301 | |
302 // 1. Reg setup. | |
303 wchar_t* app_init_reg_path = | |
304 L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Windows"; | |
305 wchar_t* dlls_value_name = L"AppInit_DLLs"; | |
306 wchar_t* enabled_value_name = L"LoadAppInit_DLLs"; | |
307 wchar_t* signing_value_name = L"RequireSignedAppInit_DLLs"; | |
308 std::wstring orig_dlls; | |
309 std::wstring new_dlls; | |
310 DWORD orig_enabled_value = 0; | |
311 DWORD orig_signing_value = 0; | |
312 base::win::RegKey app_init_key(HKEY_LOCAL_MACHINE, app_init_reg_path, | |
313 KEY_QUERY_VALUE | KEY_SET_VALUE); | |
314 // Backup the existing settings. | |
315 if (!app_init_key.Valid() || !app_init_key.HasValue(dlls_value_name) || | |
316 !app_init_key.HasValue(enabled_value_name) || | |
317 ERROR_SUCCESS != app_init_key.ReadValue(dlls_value_name, &orig_dlls) || | |
318 ERROR_SUCCESS != | |
319 app_init_key.ReadValueDW(enabled_value_name, &orig_enabled_value)) { | |
320 EXPECT_TRUE(false); | |
321 return; | |
322 } | |
323 if (app_init_key.HasValue(signing_value_name)) { | |
324 if (ERROR_SUCCESS != | |
325 app_init_key.ReadValueDW(signing_value_name, &orig_signing_value)) { | |
326 EXPECT_TRUE(false); | |
327 return; | |
328 } | |
329 } | |
330 | |
331 // Set the new settings (obviously requires local admin privileges). | |
332 new_dlls = orig_dlls; | |
333 if (0 != orig_dlls.compare(L"")) | |
robertshield
2016/04/14 03:57:29
!orig_dlls.empty()
penny
2016/04/24 18:50:49
Done.
| |
334 new_dlls.append(L","); | |
335 new_dlls.append(short_name.data()); | |
336 | |
337 // From this point on, no return on failure. Cleanup required. | |
338 bool all_good = true; | |
339 | |
340 if (app_init_key.HasValue(signing_value_name)) { | |
341 if (ERROR_SUCCESS != | |
342 app_init_key.WriteValue(signing_value_name, static_cast<DWORD>(0))) { | |
343 EXPECT_TRUE(false); | |
344 all_good = false; | |
345 } | |
346 } | |
347 if (ERROR_SUCCESS != | |
348 app_init_key.WriteValue(dlls_value_name, new_dlls.c_str()) || | |
349 ERROR_SUCCESS != | |
350 app_init_key.WriteValue(enabled_value_name, static_cast<DWORD>(1))) { | |
351 EXPECT_TRUE(false); | |
352 all_good = false; | |
353 } | |
354 | |
355 // 2. Spawn WinProc. | |
356 HANDLE event = INVALID_HANDLE_VALUE; | |
357 base::win::ScopedHandle scoped_event; | |
358 PROCESS_INFORMATION proc_info = {}; | |
359 if (all_good) { | |
360 event = ::CreateEventW(NULL, FALSE, FALSE, g_winproc_event); | |
361 if (event == NULL || event == INVALID_HANDLE_VALUE) { | |
362 EXPECT_TRUE(false); | |
363 all_good = false; | |
364 } else { | |
365 scoped_event.Set(event); | |
366 if (!SpawnWinProc(&proc_info, is_success_test, &event)) | |
367 all_good = false; | |
368 } | |
369 } | |
370 | |
371 // 3. Check loaded modules in WinProc to see if the AppInit dll is loaded. | |
372 bool dll_loaded = false; | |
373 if (all_good) { | |
374 std::vector<HMODULE>(modules); | |
375 if (!base::win::GetLoadedModulesSnapshot(proc_info.hProcess, &modules)) { | |
376 EXPECT_TRUE(false); | |
377 all_good = false; | |
378 } else { | |
379 for (auto module : modules) { | |
380 wchar_t name[MAX_PATH]; | |
robertshield
2016/04/14 03:57:29
= {}
penny
2016/04/24 18:50:48
Done.
| |
381 if (::GetModuleFileNameExW(proc_info.hProcess, module, name, | |
382 MAX_PATH) && | |
383 ::wcsstr(name, g_hook_dll_file)) { | |
384 // Found it. | |
385 dll_loaded = true; | |
386 break; | |
387 } | |
388 } | |
389 } | |
390 } | |
391 | |
392 // Was the test result as expected? | |
393 if (all_good) | |
394 EXPECT_EQ((is_success_test ? true : false), dll_loaded); | |
395 | |
396 // 4. Trigger shutdown of WinProc. | |
397 if (proc_info.hProcess) { | |
398 if (::PostThreadMessageW(proc_info.dwThreadId, WM_QUIT, 0, 0)) { | |
399 ::WaitForSingleObject(event, g_winproc_event_max_wait_ms); | |
400 } else { | |
401 // Ensure no strays. | |
402 ::TerminateProcess(proc_info.hProcess, 0); | |
403 EXPECT_TRUE(false); | |
404 } | |
405 EXPECT_TRUE(::CloseHandle(proc_info.hThread)); | |
406 EXPECT_TRUE(::CloseHandle(proc_info.hProcess)); | |
407 } | |
408 | |
409 // 5. Reg Restore | |
410 EXPECT_EQ(ERROR_SUCCESS, | |
411 app_init_key.WriteValue(enabled_value_name, orig_enabled_value)); | |
412 if (app_init_key.HasValue(signing_value_name)) | |
413 EXPECT_EQ(ERROR_SUCCESS, | |
414 app_init_key.WriteValue(signing_value_name, orig_signing_value)); | |
415 EXPECT_EQ(ERROR_SUCCESS, | |
416 app_init_key.WriteValue(dlls_value_name, orig_dlls.c_str())); | |
417 } | |
418 | |
108 void TestWin10ImageLoadRemote(bool is_success_test) { | 419 void TestWin10ImageLoadRemote(bool is_success_test) { |
109 // ***Insert your manual testing share UNC path here! | 420 // ***Insert a manual testing share UNC path here! |
110 // E.g.: \\\\hostname\\sharename\\calc.exe | 421 // E.g.: \\\\hostname\\sharename\\calc.exe |
111 std::wstring unc = L"\"\\\\hostname\\sharename\\calc.exe\""; | 422 std::wstring unc = L"\"\\\\hostname\\sharename\\calc.exe\""; |
112 | 423 |
113 sandbox::TestRunner runner; | 424 sandbox::TestRunner runner; |
114 sandbox::TargetPolicy* policy = runner.GetPolicy(); | 425 sandbox::TargetPolicy* policy = runner.GetPolicy(); |
115 | 426 |
116 // Set a policy that would normally allow for process creation. | 427 // Set a policy that would normally allow for process creation. |
117 policy->SetJobLevel(sandbox::JOB_NONE, 0); | 428 policy->SetJobLevel(sandbox::JOB_NONE, 0); |
118 policy->SetTokenLevel(sandbox::USER_UNPROTECTED, sandbox::USER_UNPROTECTED); | 429 policy->SetTokenLevel(sandbox::USER_UNPROTECTED, sandbox::USER_UNPROTECTED); |
119 runner.SetDisableCsrss(false); | 430 runner.SetDisableCsrss(false); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 setup_proc.Terminate(desired_exit_code, false); | 541 setup_proc.Terminate(desired_exit_code, false); |
231 return SBOX_TEST_SUCCEEDED; | 542 return SBOX_TEST_SUCCEEDED; |
232 } | 543 } |
233 // Note: GetLastError from CreateProcess returns 5, "ERROR_ACCESS_DENIED". | 544 // Note: GetLastError from CreateProcess returns 5, "ERROR_ACCESS_DENIED". |
234 return SBOX_TEST_FAILED; | 545 return SBOX_TEST_FAILED; |
235 } | 546 } |
236 | 547 |
237 //------------------------------------------------------------------------------ | 548 //------------------------------------------------------------------------------ |
238 // Win8 Checks: | 549 // Win8 Checks: |
239 // MITIGATION_DEP(_NO_ATL_THUNK) | 550 // MITIGATION_DEP(_NO_ATL_THUNK) |
240 // MITIGATION_EXTENSION_DLL_DISABLE | |
241 // MITIGATION_RELOCATE_IMAGE(_REQUIRED) - ASLR, release only | 551 // MITIGATION_RELOCATE_IMAGE(_REQUIRED) - ASLR, release only |
242 // MITIGATION_STRICT_HANDLE_CHECKS | 552 // MITIGATION_STRICT_HANDLE_CHECKS |
243 // >= Win8 | 553 // >= Win8 |
244 //------------------------------------------------------------------------------ | 554 //------------------------------------------------------------------------------ |
245 | 555 |
246 SBOX_TESTS_COMMAND int CheckWin8(int argc, wchar_t **argv) { | 556 SBOX_TESTS_COMMAND int CheckWin8(int argc, wchar_t** argv) { |
247 get_process_mitigation_policy = | 557 get_process_mitigation_policy = |
248 reinterpret_cast<GetProcessMitigationPolicyFunction>( | 558 reinterpret_cast<GetProcessMitigationPolicyFunction>(::GetProcAddress( |
249 ::GetProcAddress(::GetModuleHandleW(L"kernel32.dll"), | 559 ::GetModuleHandleW(L"kernel32.dll"), "GetProcessMitigationPolicy")); |
250 "GetProcessMitigationPolicy")); | |
251 if (!get_process_mitigation_policy) | 560 if (!get_process_mitigation_policy) |
252 return SBOX_TEST_NOT_FOUND; | 561 return SBOX_TEST_NOT_FOUND; |
253 | 562 |
254 #if !defined(_WIN64) // DEP is always enabled on 64-bit. | 563 #if !defined(_WIN64) // DEP is always enabled on 64-bit. |
255 if (!CheckWin8DepPolicy()) | 564 if (!CheckWin8DepPolicy()) |
256 return SBOX_TEST_FIRST_ERROR; | 565 return SBOX_TEST_FIRST_ERROR; |
257 #endif | 566 #endif |
258 | 567 |
259 #if defined(NDEBUG) // ASLR cannot be forced in debug builds. | 568 #if defined(NDEBUG) // ASLR cannot be forced in debug builds. |
260 if (!CheckWin8AslrPolicy()) | 569 if (!CheckWin8AslrPolicy()) |
261 return SBOX_TEST_SECOND_ERROR; | 570 return SBOX_TEST_SECOND_ERROR; |
262 #endif | 571 #endif |
263 | 572 |
264 if (!CheckWin8StrictHandlePolicy()) | 573 if (!CheckWin8StrictHandlePolicy()) |
265 return SBOX_TEST_THIRD_ERROR; | 574 return SBOX_TEST_THIRD_ERROR; |
266 | 575 |
267 if (!CheckWin8DllExtensionPolicy()) | |
268 return SBOX_TEST_FIFTH_ERROR; | |
269 | |
270 return SBOX_TEST_SUCCEEDED; | 576 return SBOX_TEST_SUCCEEDED; |
271 } | 577 } |
272 | 578 |
273 TEST(ProcessMitigationsTest, CheckWin8) { | 579 TEST(ProcessMitigationsTest, CheckWin8) { |
274 if (base::win::GetVersion() < base::win::VERSION_WIN8) | 580 if (base::win::GetVersion() < base::win::VERSION_WIN8) |
275 return; | 581 return; |
276 | 582 |
277 TestRunner runner; | 583 TestRunner runner; |
278 sandbox::TargetPolicy* policy = runner.GetPolicy(); | 584 sandbox::TargetPolicy* policy = runner.GetPolicy(); |
279 | 585 |
280 sandbox::MitigationFlags mitigations = MITIGATION_DEP | | 586 sandbox::MitigationFlags mitigations = |
281 MITIGATION_DEP_NO_ATL_THUNK | | 587 MITIGATION_DEP | MITIGATION_DEP_NO_ATL_THUNK; |
282 MITIGATION_EXTENSION_DLL_DISABLE; | |
283 #if defined(NDEBUG) // ASLR cannot be forced in debug builds. | 588 #if defined(NDEBUG) // ASLR cannot be forced in debug builds. |
284 mitigations |= MITIGATION_RELOCATE_IMAGE | | 589 mitigations |= MITIGATION_RELOCATE_IMAGE | MITIGATION_RELOCATE_IMAGE_REQUIRED; |
285 MITIGATION_RELOCATE_IMAGE_REQUIRED; | |
286 #endif | 590 #endif |
287 | 591 |
288 EXPECT_EQ(policy->SetProcessMitigations(mitigations), SBOX_ALL_OK); | 592 EXPECT_EQ(policy->SetProcessMitigations(mitigations), SBOX_ALL_OK); |
289 | 593 |
290 mitigations |= MITIGATION_STRICT_HANDLE_CHECKS; | 594 mitigations |= MITIGATION_STRICT_HANDLE_CHECKS; |
291 | 595 |
292 EXPECT_EQ(policy->SetDelayedProcessMitigations(mitigations), SBOX_ALL_OK); | 596 EXPECT_EQ(policy->SetDelayedProcessMitigations(mitigations), SBOX_ALL_OK); |
293 | 597 |
294 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckWin8")); | 598 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckWin8")); |
295 } | 599 } |
296 | 600 |
297 //------------------------------------------------------------------------------ | 601 //------------------------------------------------------------------------------ |
298 // DEP (MITIGATION_DEP) | 602 // DEP (MITIGATION_DEP) |
299 // < Win8 x86 | 603 // < Win8 x86 |
300 //------------------------------------------------------------------------------ | 604 //------------------------------------------------------------------------------ |
301 | 605 |
302 SBOX_TESTS_COMMAND int CheckDep(int argc, wchar_t **argv) { | 606 SBOX_TESTS_COMMAND int CheckDep(int argc, wchar_t** argv) { |
303 GetProcessDEPPolicyFunction get_process_dep_policy = | 607 GetProcessDEPPolicyFunction get_process_dep_policy = |
304 reinterpret_cast<GetProcessDEPPolicyFunction>( | 608 reinterpret_cast<GetProcessDEPPolicyFunction>(::GetProcAddress( |
305 ::GetProcAddress(::GetModuleHandleW(L"kernel32.dll"), | 609 ::GetModuleHandleW(L"kernel32.dll"), "GetProcessDEPPolicy")); |
306 "GetProcessDEPPolicy")); | |
307 if (get_process_dep_policy) { | 610 if (get_process_dep_policy) { |
308 BOOL is_permanent = FALSE; | 611 BOOL is_permanent = FALSE; |
309 DWORD dep_flags = 0; | 612 DWORD dep_flags = 0; |
310 | 613 |
311 if (!get_process_dep_policy(::GetCurrentProcess(), &dep_flags, | 614 if (!get_process_dep_policy(::GetCurrentProcess(), &dep_flags, |
312 &is_permanent)) { | 615 &is_permanent)) { |
313 return SBOX_TEST_FIRST_ERROR; | 616 return SBOX_TEST_FIRST_ERROR; |
314 } | 617 } |
315 | 618 |
316 if (!(dep_flags & PROCESS_DEP_ENABLE) || !is_permanent) | 619 if (!(dep_flags & PROCESS_DEP_ENABLE) || !is_permanent) |
317 return SBOX_TEST_SECOND_ERROR; | 620 return SBOX_TEST_SECOND_ERROR; |
318 | 621 |
319 } else { | 622 } else { |
320 NtQueryInformationProcessFunction query_information_process = NULL; | 623 NtQueryInformationProcessFunction query_information_process = NULL; |
321 ResolveNTFunctionPtr("NtQueryInformationProcess", | 624 ResolveNTFunctionPtr("NtQueryInformationProcess", |
322 &query_information_process); | 625 &query_information_process); |
323 if (!query_information_process) | 626 if (!query_information_process) |
324 return SBOX_TEST_NOT_FOUND; | 627 return SBOX_TEST_NOT_FOUND; |
325 | 628 |
326 ULONG size = 0; | 629 ULONG size = 0; |
327 ULONG dep_flags = 0; | 630 ULONG dep_flags = 0; |
328 if (!SUCCEEDED(query_information_process(::GetCurrentProcess(), | 631 if (!SUCCEEDED(query_information_process(::GetCurrentProcess(), |
329 ProcessExecuteFlags, &dep_flags, | 632 ProcessExecuteFlags, &dep_flags, |
330 sizeof(dep_flags), &size))) { | 633 sizeof(dep_flags), &size))) { |
331 return SBOX_TEST_THIRD_ERROR; | 634 return SBOX_TEST_THIRD_ERROR; |
332 } | 635 } |
333 | 636 |
334 static const int MEM_EXECUTE_OPTION_DISABLE = 2; | 637 static const int MEM_EXECUTE_OPTION_DISABLE = 2; |
335 static const int MEM_EXECUTE_OPTION_PERMANENT = 8; | 638 static const int MEM_EXECUTE_OPTION_PERMANENT = 8; |
336 dep_flags &= 0xff; | 639 dep_flags &= 0xff; |
337 | 640 |
338 if (dep_flags != (MEM_EXECUTE_OPTION_DISABLE | | 641 if (dep_flags != |
339 MEM_EXECUTE_OPTION_PERMANENT)) { | 642 (MEM_EXECUTE_OPTION_DISABLE | MEM_EXECUTE_OPTION_PERMANENT)) { |
340 return SBOX_TEST_FOURTH_ERROR; | 643 return SBOX_TEST_FOURTH_ERROR; |
341 } | 644 } |
342 } | 645 } |
343 | 646 |
344 return SBOX_TEST_SUCCEEDED; | 647 return SBOX_TEST_SUCCEEDED; |
345 } | 648 } |
346 | 649 |
347 #if !defined(_WIN64) // DEP is always enabled on 64-bit. | 650 #if !defined(_WIN64) // DEP is always enabled on 64-bit. |
348 TEST(ProcessMitigationsTest, CheckDep) { | 651 TEST(ProcessMitigationsTest, CheckDep) { |
349 if (base::win::GetVersion() > base::win::VERSION_WIN7) | 652 if (base::win::GetVersion() > base::win::VERSION_WIN7) |
350 return; | 653 return; |
351 | 654 |
352 TestRunner runner; | 655 TestRunner runner; |
353 sandbox::TargetPolicy* policy = runner.GetPolicy(); | 656 sandbox::TargetPolicy* policy = runner.GetPolicy(); |
354 | 657 |
355 EXPECT_EQ(policy->SetProcessMitigations( | 658 EXPECT_EQ(policy->SetProcessMitigations(MITIGATION_DEP | |
356 MITIGATION_DEP | | 659 MITIGATION_DEP_NO_ATL_THUNK | |
357 MITIGATION_DEP_NO_ATL_THUNK | | 660 MITIGATION_SEHOP), |
358 MITIGATION_SEHOP), | |
359 SBOX_ALL_OK); | 661 SBOX_ALL_OK); |
360 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckDep")); | 662 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckDep")); |
361 } | 663 } |
362 #endif | 664 #endif |
363 | 665 |
364 //------------------------------------------------------------------------------ | 666 //------------------------------------------------------------------------------ |
365 // Win32k Lockdown (MITIGATION_WIN32K_DISABLE) | 667 // Win32k Lockdown (MITIGATION_WIN32K_DISABLE) |
366 // >= Win8 | 668 // >= Win8 |
367 //------------------------------------------------------------------------------ | 669 //------------------------------------------------------------------------------ |
368 | 670 |
369 SBOX_TESTS_COMMAND int CheckWin8Lockdown(int argc, wchar_t **argv) { | 671 SBOX_TESTS_COMMAND int CheckWin8Lockdown(int argc, wchar_t** argv) { |
370 get_process_mitigation_policy = | 672 get_process_mitigation_policy = |
371 reinterpret_cast<GetProcessMitigationPolicyFunction>( | 673 reinterpret_cast<GetProcessMitigationPolicyFunction>(::GetProcAddress( |
372 ::GetProcAddress(::GetModuleHandleW(L"kernel32.dll"), | 674 ::GetModuleHandleW(L"kernel32.dll"), "GetProcessMitigationPolicy")); |
373 "GetProcessMitigationPolicy")); | |
374 if (!get_process_mitigation_policy) | 675 if (!get_process_mitigation_policy) |
375 return SBOX_TEST_NOT_FOUND; | 676 return SBOX_TEST_NOT_FOUND; |
376 | 677 |
377 if (!CheckWin8Win32CallPolicy()) | 678 if (!CheckWin8Win32CallPolicy()) |
378 return SBOX_TEST_FIRST_ERROR; | 679 return SBOX_TEST_FIRST_ERROR; |
379 return SBOX_TEST_SUCCEEDED; | 680 return SBOX_TEST_SUCCEEDED; |
380 } | 681 } |
381 | 682 |
382 // This test validates that setting the MITIGATION_WIN32K_DISABLE mitigation on | 683 // This test validates that setting the MITIGATION_WIN32K_DISABLE mitigation on |
383 // the target process causes the launch to fail in process initialization. | 684 // the target process causes the launch to fail in process initialization. |
(...skipping 23 matching lines...) Expand all Loading... | |
407 | 708 |
408 EXPECT_EQ(policy->SetProcessMitigations(MITIGATION_WIN32K_DISABLE), | 709 EXPECT_EQ(policy->SetProcessMitigations(MITIGATION_WIN32K_DISABLE), |
409 SBOX_ALL_OK); | 710 SBOX_ALL_OK); |
410 EXPECT_EQ(policy->AddRule(sandbox::TargetPolicy::SUBSYS_WIN32K_LOCKDOWN, | 711 EXPECT_EQ(policy->AddRule(sandbox::TargetPolicy::SUBSYS_WIN32K_LOCKDOWN, |
411 sandbox::TargetPolicy::FAKE_USER_GDI_INIT, NULL), | 712 sandbox::TargetPolicy::FAKE_USER_GDI_INIT, NULL), |
412 sandbox::SBOX_ALL_OK); | 713 sandbox::SBOX_ALL_OK); |
413 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckWin8Lockdown")); | 714 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckWin8Lockdown")); |
414 } | 715 } |
415 | 716 |
416 //------------------------------------------------------------------------------ | 717 //------------------------------------------------------------------------------ |
718 // Disable extension points (MITIGATION_EXTENSION_POINT_DISABLE). | |
719 // >= Win8 | |
720 //------------------------------------------------------------------------------ | |
721 SBOX_TESTS_COMMAND int CheckWin8ExtensionPointSetting(int argc, | |
722 wchar_t** argv) { | |
723 get_process_mitigation_policy = | |
724 reinterpret_cast<GetProcessMitigationPolicyFunction>(::GetProcAddress( | |
725 ::GetModuleHandleW(L"kernel32.dll"), "GetProcessMitigationPolicy")); | |
726 if (!get_process_mitigation_policy) | |
727 return SBOX_TEST_NOT_FOUND; | |
728 | |
729 if (!CheckWin8ExtensionPointPolicy()) | |
730 return SBOX_TEST_FIRST_ERROR; | |
731 return SBOX_TEST_SUCCEEDED; | |
732 } | |
733 | |
734 // This test validates that setting the MITIGATION_EXTENSION_POINT_DISABLE | |
735 // mitigation enables the setting on a process. | |
736 TEST(ProcessMitigationsTest, CheckWin8ExtensionPointPolicySuccess) { | |
737 if (base::win::GetVersion() < base::win::VERSION_WIN8) | |
738 return; | |
739 | |
740 TestRunner runner; | |
741 sandbox::TargetPolicy* policy = runner.GetPolicy(); | |
742 | |
743 EXPECT_EQ(policy->SetProcessMitigations(MITIGATION_EXTENSION_POINT_DISABLE), | |
744 SBOX_ALL_OK); | |
745 EXPECT_EQ(SBOX_TEST_SUCCEEDED, | |
746 runner.RunTest(L"CheckWin8ExtensionPointSetting")); | |
747 } | |
748 | |
749 // This test validates that a "legitimate" global hook CAN be set on the | |
750 // sandboxed proc/thread if the MITIGATION_EXTENSION_POINT_DISABLE | |
751 // mitigation is not set. | |
752 // | |
753 // MANUAL testing only. | |
754 TEST(ProcessMitigationsTest, | |
755 DISABLED_CheckWin8ExtensionPoint_GlobalHook_Success) { | |
robertshield
2016/04/14 03:57:29
double checking: is it intended that these tests a
penny
2016/04/24 18:50:49
Yes. Unfortunately, these extension point tests m
| |
756 if (base::win::GetVersion() < base::win::VERSION_WIN8) | |
757 return; | |
758 | |
759 HANDLE mutex = ::CreateMutexW(NULL, FALSE, g_extension_point_test_mutex); | |
760 EXPECT_TRUE(mutex != NULL && mutex != INVALID_HANDLE_VALUE); | |
761 EXPECT_EQ(WAIT_OBJECT_0, | |
762 ::WaitForSingleObject(mutex, g_test_mutex_max_wait_ms)); | |
763 | |
764 // (is_success_test, global_hook) | |
765 TestWin8ExtensionPointHookWrapper(true, true); | |
766 | |
767 EXPECT_TRUE(::ReleaseMutex(mutex)); | |
768 EXPECT_TRUE(::CloseHandle(mutex)); | |
769 } | |
770 | |
771 // This test validates that setting the MITIGATION_EXTENSION_POINT_DISABLE | |
772 // mitigation prevents a global hook on WinProc. | |
773 // | |
774 // MANUAL testing only. | |
775 TEST(ProcessMitigationsTest, | |
776 DISABLED_CheckWin8ExtensionPoint_GlobalHook_Failure) { | |
777 if (base::win::GetVersion() < base::win::VERSION_WIN8) | |
778 return; | |
779 | |
780 HANDLE mutex = ::CreateMutexW(NULL, FALSE, g_extension_point_test_mutex); | |
781 EXPECT_TRUE(mutex != NULL && mutex != INVALID_HANDLE_VALUE); | |
782 EXPECT_EQ(WAIT_OBJECT_0, | |
783 ::WaitForSingleObject(mutex, g_test_mutex_max_wait_ms)); | |
784 | |
785 // (is_success_test, global_hook) | |
786 TestWin8ExtensionPointHookWrapper(false, true); | |
787 | |
788 EXPECT_TRUE(::ReleaseMutex(mutex)); | |
789 EXPECT_TRUE(::CloseHandle(mutex)); | |
790 } | |
791 | |
792 // This test validates that a "legitimate" hook CAN be set on the sandboxed | |
793 // proc/thread if the MITIGATION_EXTENSION_POINT_DISABLE mitigation is not set. | |
794 // | |
795 // MANUAL testing only. | |
796 TEST(ProcessMitigationsTest, DISABLED_CheckWin8ExtensionPoint_Hook_Success) { | |
797 if (base::win::GetVersion() < base::win::VERSION_WIN8) | |
798 return; | |
799 | |
800 HANDLE mutex = ::CreateMutexW(NULL, FALSE, g_extension_point_test_mutex); | |
801 EXPECT_TRUE(mutex != NULL && mutex != INVALID_HANDLE_VALUE); | |
802 EXPECT_EQ(WAIT_OBJECT_0, | |
803 ::WaitForSingleObject(mutex, g_test_mutex_max_wait_ms)); | |
804 | |
805 // (is_success_test, global_hook) | |
806 TestWin8ExtensionPointHookWrapper(true, false); | |
807 | |
808 EXPECT_TRUE(::ReleaseMutex(mutex)); | |
809 EXPECT_TRUE(::CloseHandle(mutex)); | |
810 } | |
811 | |
812 // *** Important: MITIGATION_EXTENSION_POINT_DISABLE does NOT prevent | |
813 // hooks targetted at a specific thread id. It only prevents | |
814 // global hooks. So this test does NOT actually expect the hook | |
815 // to fail (see TestWin8ExtensionPointHookWrapper function) even | |
816 // with the mitigation on. | |
817 // | |
818 // MANUAL testing only. | |
819 TEST(ProcessMitigationsTest, DISABLED_CheckWin8ExtensionPoint_Hook_Failure) { | |
820 if (base::win::GetVersion() < base::win::VERSION_WIN8) | |
821 return; | |
822 | |
823 HANDLE mutex = ::CreateMutexW(NULL, FALSE, g_extension_point_test_mutex); | |
824 EXPECT_TRUE(mutex != NULL && mutex != INVALID_HANDLE_VALUE); | |
825 EXPECT_EQ(WAIT_OBJECT_0, | |
826 ::WaitForSingleObject(mutex, g_test_mutex_max_wait_ms)); | |
827 | |
828 // (is_success_test, global_hook) | |
829 TestWin8ExtensionPointHookWrapper(false, false); | |
830 | |
831 EXPECT_TRUE(::ReleaseMutex(mutex)); | |
832 EXPECT_TRUE(::CloseHandle(mutex)); | |
833 } | |
834 | |
835 // This test validates that an AppInit Dll CAN be added to a target | |
836 // WinProc if the MITIGATION_EXTENSION_POINT_DISABLE mitigation is not set. | |
837 // | |
838 // MANUAL testing only. | |
839 // Must run this test as admin/elevated. | |
840 TEST(ProcessMitigationsTest, DISABLED_CheckWin8ExtensionPoint_AppInit_Success) { | |
841 if (base::win::GetVersion() < base::win::VERSION_WIN8) | |
842 return; | |
843 | |
844 HANDLE mutex = ::CreateMutexW(NULL, FALSE, g_extension_point_test_mutex); | |
845 EXPECT_TRUE(mutex != NULL && mutex != INVALID_HANDLE_VALUE); | |
846 EXPECT_EQ(WAIT_OBJECT_0, | |
847 ::WaitForSingleObject(mutex, g_test_mutex_max_wait_ms)); | |
848 | |
849 TestWin8ExtensionPointAppInitWrapper(true); | |
850 | |
851 EXPECT_TRUE(::ReleaseMutex(mutex)); | |
852 EXPECT_TRUE(::CloseHandle(mutex)); | |
853 } | |
854 | |
855 // This test validates that setting the MITIGATION_EXTENSION_POINT_DISABLE | |
856 // mitigation prevents the loading of any AppInit Dll into WinProc. | |
857 // | |
858 // MANUAL testing only. | |
859 // Must run this test as admin/elevated. | |
860 TEST(ProcessMitigationsTest, DISABLED_CheckWin8ExtensionPoint_AppInit_Failure) { | |
861 if (base::win::GetVersion() < base::win::VERSION_WIN8) | |
862 return; | |
863 | |
864 HANDLE mutex = ::CreateMutexW(NULL, FALSE, g_extension_point_test_mutex); | |
865 EXPECT_TRUE(mutex != NULL && mutex != INVALID_HANDLE_VALUE); | |
866 EXPECT_EQ(WAIT_OBJECT_0, | |
867 ::WaitForSingleObject(mutex, g_test_mutex_max_wait_ms)); | |
868 | |
869 TestWin8ExtensionPointAppInitWrapper(false); | |
870 | |
871 EXPECT_TRUE(::ReleaseMutex(mutex)); | |
872 EXPECT_TRUE(::CloseHandle(mutex)); | |
873 } | |
874 | |
875 //------------------------------------------------------------------------------ | |
417 // Disable non-system font loads (MITIGATION_NONSYSTEM_FONT_DISABLE) | 876 // Disable non-system font loads (MITIGATION_NONSYSTEM_FONT_DISABLE) |
418 // >= Win10 | 877 // >= Win10 |
419 //------------------------------------------------------------------------------ | 878 //------------------------------------------------------------------------------ |
420 | 879 |
421 SBOX_TESTS_COMMAND int CheckWin10FontLockDown(int argc, wchar_t** argv) { | 880 SBOX_TESTS_COMMAND int CheckWin10FontLockDown(int argc, wchar_t** argv) { |
422 get_process_mitigation_policy = | 881 get_process_mitigation_policy = |
423 reinterpret_cast<GetProcessMitigationPolicyFunction>(::GetProcAddress( | 882 reinterpret_cast<GetProcessMitigationPolicyFunction>(::GetProcAddress( |
424 ::GetModuleHandleW(L"kernel32.dll"), "GetProcessMitigationPolicy")); | 883 ::GetModuleHandleW(L"kernel32.dll"), "GetProcessMitigationPolicy")); |
425 if (!get_process_mitigation_policy) | 884 if (!get_process_mitigation_policy) |
426 return SBOX_TEST_NOT_FOUND; | 885 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), | 1030 policy->SetDelayedProcessMitigations(MITIGATION_IMAGE_LOAD_NO_REMOTE), |
572 SBOX_ALL_OK); | 1031 SBOX_ALL_OK); |
573 EXPECT_EQ(SBOX_TEST_SUCCEEDED, | 1032 EXPECT_EQ(SBOX_TEST_SUCCEEDED, |
574 runner.RunTest(L"CheckWin10ImageLoadNoRemote")); | 1033 runner.RunTest(L"CheckWin10ImageLoadNoRemote")); |
575 } | 1034 } |
576 | 1035 |
577 // This test validates that we CAN create a new process from | 1036 // This test validates that we CAN create a new process from |
578 // a remote UNC device, if the MITIGATION_IMAGE_LOAD_NO_REMOTE | 1037 // a remote UNC device, if the MITIGATION_IMAGE_LOAD_NO_REMOTE |
579 // mitigation is NOT set. | 1038 // mitigation is NOT set. |
580 // | 1039 // |
581 // DISABLED for automated testing bots. Enable for manual testing. | 1040 // MANUAL testing only. |
582 TEST(ProcessMitigationsTest, DISABLED_CheckWin10ImageLoadNoRemoteSuccess) { | 1041 TEST(ProcessMitigationsTest, DISABLED_CheckWin10ImageLoadNoRemoteSuccess) { |
583 if (base::win::GetVersion() < base::win::VERSION_WIN10_TH2) | 1042 if (base::win::GetVersion() < base::win::VERSION_WIN10_TH2) |
584 return; | 1043 return; |
585 | 1044 |
586 TestWin10ImageLoadRemote(true); | 1045 TestWin10ImageLoadRemote(true); |
587 } | 1046 } |
588 | 1047 |
589 // This test validates that setting the MITIGATION_IMAGE_LOAD_NO_REMOTE | 1048 // This test validates that setting the MITIGATION_IMAGE_LOAD_NO_REMOTE |
590 // mitigation prevents creating a new process from a remote | 1049 // mitigation prevents creating a new process from a remote |
591 // UNC device. | 1050 // UNC device. |
592 // | 1051 // |
593 // DISABLED for automated testing bots. Enable for manual testing. | 1052 // MANUAL testing only. |
594 TEST(ProcessMitigationsTest, DISABLED_CheckWin10ImageLoadNoRemoteFailure) { | 1053 TEST(ProcessMitigationsTest, DISABLED_CheckWin10ImageLoadNoRemoteFailure) { |
595 if (base::win::GetVersion() < base::win::VERSION_WIN10_TH2) | 1054 if (base::win::GetVersion() < base::win::VERSION_WIN10_TH2) |
596 return; | 1055 return; |
597 | 1056 |
598 TestWin10ImageLoadRemote(false); | 1057 TestWin10ImageLoadRemote(false); |
599 } | 1058 } |
600 | 1059 |
601 //------------------------------------------------------------------------------ | 1060 //------------------------------------------------------------------------------ |
602 // Disable image load when "mandatory low label" (integrity level). | 1061 // Disable image load when "mandatory low label" (integrity level). |
603 // (MITIGATION_IMAGE_LOAD_NO_LOW_LABEL) | 1062 // (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"); | 1184 cmd = cmd.Append(L"calc.exe"); |
726 | 1185 |
727 std::wstring test_command(base::StringPrintf(L"TestChildProcess %ls 0x%08X", | 1186 std::wstring test_command(base::StringPrintf(L"TestChildProcess %ls 0x%08X", |
728 cmd.value().c_str(), | 1187 cmd.value().c_str(), |
729 STATUS_ACCESS_VIOLATION)); | 1188 STATUS_ACCESS_VIOLATION)); |
730 | 1189 |
731 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(test_command.c_str())); | 1190 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(test_command.c_str())); |
732 } | 1191 } |
733 | 1192 |
734 } // namespace sandbox | 1193 } // namespace sandbox |
OLD | NEW |