Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: sandbox/win/src/process_mitigations_test.cc

Issue 1835003003: [Windows Sandbox] MITIGATION_EXTENSION_POINT_DISABLE support for children. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Final fixes and nits. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sandbox/win/src/process_mitigations.cc ('k') | sandbox/win/src/security_level.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <d3d9.h>
5 #include <initguid.h> 8 #include <initguid.h>
6 #include <d3d9.h> 9 #include <opmapi.h>
7 #include <Opmapi.h> 10 #include <psapi.h>
8 #include <windows.h> 11 #include <windows.h>
9 12
10 #include <map> 13 #include <map>
11 #include <string> 14 #include <string>
12 15
16 #include "base/command_line.h"
13 #include "base/files/file_util.h" 17 #include "base/files/file_util.h"
14 #include "base/files/scoped_temp_dir.h" 18 #include "base/files/scoped_temp_dir.h"
15 #include "base/memory/ref_counted.h" 19 #include "base/memory/ref_counted.h"
16 #include "base/path_service.h" 20 #include "base/path_service.h"
17 #include "base/process/launch.h" 21 #include "base/process/launch.h"
22 #include "base/scoped_native_library.h"
18 #include "base/strings/stringprintf.h" 23 #include "base/strings/stringprintf.h"
19 #include "base/strings/utf_string_conversions.h" 24 #include "base/strings/utf_string_conversions.h"
25 #include "base/test/test_timeouts.h"
26 #include "base/win/registry.h"
20 #include "base/win/scoped_handle.h" 27 #include "base/win/scoped_handle.h"
28 #include "base/win/startup_information.h"
29 #include "base/win/win_util.h"
21 #include "base/win/windows_version.h" 30 #include "base/win/windows_version.h"
22 #include "sandbox/win/src/nt_internals.h" 31 #include "sandbox/win/src/nt_internals.h"
23 #include "sandbox/win/src/process_mitigations.h"
24 #include "sandbox/win/src/process_mitigations_win32k_policy.h" 32 #include "sandbox/win/src/process_mitigations_win32k_policy.h"
25 #include "sandbox/win/src/sandbox.h" 33 #include "sandbox/win/src/sandbox.h"
26 #include "sandbox/win/src/sandbox_factory.h" 34 #include "sandbox/win/src/sandbox_factory.h"
27 #include "sandbox/win/src/target_services.h" 35 #include "sandbox/win/src/target_services.h"
28 #include "sandbox/win/src/win_utils.h"
29 #include "sandbox/win/tests/common/controller.h" 36 #include "sandbox/win/tests/common/controller.h"
37 #include "sandbox/win/tests/integration_tests/integration_tests_common.h"
30 #include "testing/gtest/include/gtest/gtest.h" 38 #include "testing/gtest/include/gtest/gtest.h"
31 39
32 namespace { 40 namespace {
33 41
42 // Timeouts for synchronization.
43 #define event_timeout \
44 static_cast<DWORD>((TestTimeouts::action_timeout()).InMillisecondsRoundedUp())
45
34 // API defined in winbase.h. 46 // API defined in winbase.h.
35 typedef decltype(GetProcessDEPPolicy)* GetProcessDEPPolicyFunction; 47 typedef decltype(GetProcessDEPPolicy)* GetProcessDEPPolicyFunction;
36 48
37 // API defined in processthreadsapi.h. 49 // API defined in processthreadsapi.h.
38 typedef decltype( 50 typedef decltype(
39 GetProcessMitigationPolicy)* GetProcessMitigationPolicyFunction; 51 GetProcessMitigationPolicy)* GetProcessMitigationPolicyFunction;
40 GetProcessMitigationPolicyFunction get_process_mitigation_policy; 52 GetProcessMitigationPolicyFunction get_process_mitigation_policy;
41 53
42 // APIs defined in wingdi.h. 54 // APIs defined in wingdi.h.
43 typedef decltype(AddFontMemResourceEx)* AddFontMemResourceExFunction; 55 typedef decltype(AddFontMemResourceEx)* AddFontMemResourceExFunction;
44 typedef decltype(RemoveFontMemResourceEx)* RemoveFontMemResourceExFunction; 56 typedef decltype(RemoveFontMemResourceEx)* RemoveFontMemResourceExFunction;
45 57
58 // APIs defined in integration_tests_common.h
59 typedef decltype(WasHookCalled)* WasHookCalledFunction;
60 typedef decltype(SetHook)* SetHookFunction;
61
46 #if !defined(_WIN64) 62 #if !defined(_WIN64)
47 bool CheckWin8DepPolicy() { 63 bool CheckWin8DepPolicy() {
48 PROCESS_MITIGATION_DEP_POLICY policy = {}; 64 PROCESS_MITIGATION_DEP_POLICY policy = {};
49 if (!get_process_mitigation_policy(::GetCurrentProcess(), ProcessDEPPolicy, 65 if (!get_process_mitigation_policy(::GetCurrentProcess(), ProcessDEPPolicy,
50 &policy, sizeof(policy))) { 66 &policy, sizeof(policy))) {
51 return false; 67 return false;
52 } 68 }
53 return policy.Enable && policy.Permanent; 69 return policy.Enable && policy.Permanent;
54 } 70 }
55 #endif // !defined(_WIN64) 71 #endif // !defined(_WIN64)
56 72
57 #if defined(NDEBUG) 73 #if defined(NDEBUG)
58 bool CheckWin8AslrPolicy() { 74 bool CheckWin8AslrPolicy() {
59 PROCESS_MITIGATION_ASLR_POLICY policy = {}; 75 PROCESS_MITIGATION_ASLR_POLICY policy = {};
60 if (!get_process_mitigation_policy(::GetCurrentProcess(), ProcessASLRPolicy, 76 if (!get_process_mitigation_policy(::GetCurrentProcess(), ProcessASLRPolicy,
61 &policy, sizeof(policy))) { 77 &policy, sizeof(policy))) {
62 return false; 78 return false;
63 } 79 }
64 return policy.EnableForceRelocateImages && policy.DisallowStrippedImages; 80 return policy.EnableForceRelocateImages && policy.DisallowStrippedImages;
65 } 81 }
66 #endif // defined(NDEBUG) 82 #endif // defined(NDEBUG)
67 83
68 bool CheckWin8StrictHandlePolicy() { 84 bool CheckWin8StrictHandlePolicy() {
69 PROCESS_MITIGATION_STRICT_HANDLE_CHECK_POLICY policy = {}; 85 PROCESS_MITIGATION_STRICT_HANDLE_CHECK_POLICY policy = {};
70 if (!get_process_mitigation_policy(::GetCurrentProcess(), 86 if (!get_process_mitigation_policy(::GetCurrentProcess(),
71 ProcessStrictHandleCheckPolicy, 87 ProcessStrictHandleCheckPolicy, &policy,
72 &policy, sizeof(policy))) { 88 sizeof(policy))) {
73 return false; 89 return false;
74 } 90 }
75 return policy.RaiseExceptionOnInvalidHandleReference && 91 return policy.RaiseExceptionOnInvalidHandleReference &&
76 policy.HandleExceptionsPermanentlyEnabled; 92 policy.HandleExceptionsPermanentlyEnabled;
77 } 93 }
78 94
79 bool CheckWin8Win32CallPolicy() { 95 bool CheckWin8Win32CallPolicy() {
80 PROCESS_MITIGATION_SYSTEM_CALL_DISABLE_POLICY policy = {}; 96 PROCESS_MITIGATION_SYSTEM_CALL_DISABLE_POLICY policy = {};
81 if (!get_process_mitigation_policy(::GetCurrentProcess(), 97 if (!get_process_mitigation_policy(::GetCurrentProcess(),
82 ProcessSystemCallDisablePolicy, 98 ProcessSystemCallDisablePolicy, &policy,
83 &policy, sizeof(policy))) { 99 sizeof(policy))) {
84 return false; 100 return false;
85 } 101 }
86 return policy.DisallowWin32kSystemCalls; 102 return policy.DisallowWin32kSystemCalls;
87 } 103 }
88 104
89 bool CheckWin8DllExtensionPolicy() { 105 bool CheckWin8ExtensionPointPolicy() {
90 PROCESS_MITIGATION_EXTENSION_POINT_DISABLE_POLICY policy = {}; 106 PROCESS_MITIGATION_EXTENSION_POINT_DISABLE_POLICY policy = {};
91 if (!get_process_mitigation_policy(::GetCurrentProcess(), 107 if (!get_process_mitigation_policy(::GetCurrentProcess(),
92 ProcessExtensionPointDisablePolicy, 108 ProcessExtensionPointDisablePolicy,
93 &policy, sizeof(policy))) { 109 &policy, sizeof(policy))) {
94 return false; 110 return false;
95 } 111 }
96 return policy.DisableExtensionPoints; 112 return policy.DisableExtensionPoints;
97 } 113 }
98 114
99 bool CheckWin10FontPolicy() { 115 bool CheckWin10FontPolicy() {
100 PROCESS_MITIGATION_FONT_DISABLE_POLICY policy = {}; 116 PROCESS_MITIGATION_FONT_DISABLE_POLICY policy = {};
101 if (!get_process_mitigation_policy(::GetCurrentProcess(), 117 if (!get_process_mitigation_policy(::GetCurrentProcess(),
102 ProcessFontDisablePolicy, &policy, 118 ProcessFontDisablePolicy, &policy,
103 sizeof(policy))) { 119 sizeof(policy))) {
104 return false; 120 return false;
105 } 121 }
106 return policy.DisableNonSystemFonts; 122 return policy.DisableNonSystemFonts;
107 } 123 }
108 124
109 bool CheckWin10ImageLoadNoRemotePolicy() { 125 bool CheckWin10ImageLoadNoRemotePolicy() {
110 PROCESS_MITIGATION_IMAGE_LOAD_POLICY policy = {}; 126 PROCESS_MITIGATION_IMAGE_LOAD_POLICY policy = {};
111 if (!get_process_mitigation_policy(::GetCurrentProcess(), 127 if (!get_process_mitigation_policy(::GetCurrentProcess(),
112 ProcessImageLoadPolicy, &policy, 128 ProcessImageLoadPolicy, &policy,
113 sizeof(policy))) { 129 sizeof(policy))) {
114 return false; 130 return false;
115 } 131 }
116 return policy.NoRemoteImages; 132 return policy.NoRemoteImages;
117 } 133 }
118 134
135 // Spawn Windows process (with or without mitigation enabled).
136 bool SpawnWinProc(PROCESS_INFORMATION* pi, bool success_test, HANDLE* event) {
137 base::win::StartupInformation startup_info;
138 DWORD creation_flags = 0;
139
140 if (!success_test) {
141 DWORD64 flags =
142 PROCESS_CREATION_MITIGATION_POLICY_EXTENSION_POINT_DISABLE_ALWAYS_ON;
143 // This test only runs on >= Win8, so don't have to handle
144 // illegal 64-bit flags on 32-bit <= Win7.
145 size_t flags_size = sizeof(flags);
146
147 if (!startup_info.InitializeProcThreadAttributeList(1) ||
148 !startup_info.UpdateProcThreadAttribute(
149 PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY, &flags, flags_size)) {
150 ADD_FAILURE();
151 return false;
152 }
153 creation_flags = EXTENDED_STARTUPINFO_PRESENT;
154 }
155
156 // Command line must be writable.
157 base::string16 cmd_writeable(g_winproc_file);
158
159 if (!::CreateProcessW(NULL, &cmd_writeable[0], NULL, NULL, FALSE,
160 creation_flags, NULL, NULL, startup_info.startup_info(),
161 pi)) {
162 ADD_FAILURE();
163 return false;
164 }
165 EXPECT_EQ(WAIT_OBJECT_0, ::WaitForSingleObject(*event, event_timeout));
166
167 return true;
168 }
169
170 //------------------------------------------------------------------------------
171 // 1. Spawn a Windows process (with or without mitigation enabled).
172 // 2. Load the hook Dll locally.
173 // 3. Create a global named event for the hook to trigger.
174 // 4. Start the hook (for the specific WinProc or globally).
175 // 5. Send a keystroke event.
176 // 6. Ask the hook Dll if it received a hook callback.
177 // 7. Cleanup the hooking.
178 // 8. Signal the Windows process to shutdown.
179 //
180 // Do NOT use any ASSERTs in this function. Cleanup required.
181 //------------------------------------------------------------------------------
182 void TestWin8ExtensionPointHookWrapper(bool is_success_test, bool global_hook) {
183 // Set up a couple global events that this test will use.
184 HANDLE winproc_event = ::CreateEventW(NULL, FALSE, FALSE, g_winproc_event);
185 if (winproc_event == NULL || winproc_event == INVALID_HANDLE_VALUE) {
186 ADD_FAILURE();
187 return;
188 }
189 base::win::ScopedHandle scoped_winproc_event(winproc_event);
190
191 HANDLE hook_event = ::CreateEventW(NULL, FALSE, FALSE, g_hook_event);
192 if (hook_event == NULL || hook_event == INVALID_HANDLE_VALUE) {
193 ADD_FAILURE();
194 return;
195 }
196 base::win::ScopedHandle scoped_hook_event(hook_event);
197
198 // 1. Spawn WinProc.
199 PROCESS_INFORMATION proc_info = {};
200 if (!SpawnWinProc(&proc_info, is_success_test, &winproc_event))
201 return;
202
203 // From this point on, no return on failure. Cleanup required.
204 bool all_good = true;
205
206 // 2. Load the hook DLL.
207 base::FilePath hook_dll_path(g_hook_dll_file);
208 base::ScopedNativeLibrary dll(hook_dll_path);
209 EXPECT_TRUE(dll.is_valid());
210
211 HOOKPROC hook_proc =
212 reinterpret_cast<HOOKPROC>(dll.GetFunctionPointer(g_hook_handler_func));
213 WasHookCalledFunction was_hook_called =
214 reinterpret_cast<WasHookCalledFunction>(
215 dll.GetFunctionPointer(g_was_hook_called_func));
216 SetHookFunction set_hook = reinterpret_cast<SetHookFunction>(
217 dll.GetFunctionPointer(g_set_hook_func));
218 if (!hook_proc || !was_hook_called || !set_hook) {
219 ADD_FAILURE();
220 all_good = false;
221 }
222
223 // 3. Try installing the hook (either on a remote target thread,
224 // or globally).
225 HHOOK hook = nullptr;
226 if (all_good) {
227 DWORD target = 0;
228 if (!global_hook)
229 target = proc_info.dwThreadId;
230 hook = ::SetWindowsHookExW(WH_KEYBOARD, hook_proc, dll.get(), target);
231 if (!hook) {
232 ADD_FAILURE();
233 all_good = false;
234 } else
235 // Pass the hook DLL the hook handle.
236 set_hook(hook);
237 }
238
239 // 4. Inject a keyboard event.
240 if (all_good) {
241 // Note: that PostThreadMessage and SendMessage APIs will not deliver
242 // a keystroke in such a way that triggers a "legitimate" hook.
243 // Have to use targetless SendInput or keybd_event. The latter is
244 // less code and easier to work with.
245 keybd_event(VkKeyScan(L'A'), 0, 0, 0);
246 keybd_event(VkKeyScan(L'A'), 0, KEYEVENTF_KEYUP, 0);
247 // Give it a chance to hit the hook handler...
248 ::WaitForSingleObject(hook_event, event_timeout);
249
250 // 5. Did the hook get hit? Was it expected to?
251 if (global_hook)
252 EXPECT_EQ((is_success_test ? true : false), was_hook_called());
253 else
254 // ***IMPORTANT: when targeting a specific thread id, the
255 // PROCESS_CREATION_MITIGATION_POLICY_EXTENSION_POINT_DISABLE
256 // mitigation does NOT disable the hook API. It ONLY
257 // stops global hooks from running in a process. Hence,
258 // the hook will hit (TRUE) even in the "failure"
259 // case for a non-global/targeted hook.
260 EXPECT_EQ((is_success_test ? true : true), was_hook_called());
261 }
262
263 // 6. Disable hook.
264 if (hook)
265 EXPECT_TRUE(::UnhookWindowsHookEx(hook));
266
267 // 7. Trigger shutdown of WinProc.
268 if (proc_info.hProcess) {
269 if (::PostThreadMessageW(proc_info.dwThreadId, WM_QUIT, 0, 0)) {
270 // Note: The combination/perfect-storm of a Global Hook, in a
271 // WinProc that has the EXTENSION_POINT_DISABLE mitigation ON, and the
272 // use of the SendInput or keybd_event API to inject a keystroke,
273 // results in the target becoming unresponsive. If any one of these
274 // states are changed, the problem does not occur. This means the WM_QUIT
275 // message is not handled and the call to WaitForSingleObject times out.
276 // Therefore not checking the return val.
277 ::WaitForSingleObject(winproc_event, event_timeout);
278 } else {
279 // Ensure no strays.
280 ::TerminateProcess(proc_info.hProcess, 0);
281 ADD_FAILURE();
282 }
283 EXPECT_TRUE(::CloseHandle(proc_info.hThread));
284 EXPECT_TRUE(::CloseHandle(proc_info.hProcess));
285 }
286 }
287
288 //------------------------------------------------------------------------------
289 // 1. Set up the AppInit Dll in registry settings. (Enable)
290 // 2. Spawn a Windows process (with or without mitigation enabled).
291 // 3. Check if the AppInit Dll got loaded in the Windows process or not.
292 // 4. Signal the Windows process to shutdown.
293 // 5. Restore original reg settings.
294 //
295 // Do NOT use any ASSERTs in this function. Cleanup required.
296 //------------------------------------------------------------------------------
297 void TestWin8ExtensionPointAppInitWrapper(bool is_success_test) {
298 // 0.5 Get path of current module. The appropriate build of the
299 // AppInit DLL will be in the same directory (and the
300 // full path is needed for reg).
301 wchar_t path[MAX_PATH];
302 if (!::GetModuleFileNameW(NULL, path, MAX_PATH)) {
303 ADD_FAILURE();
304 return;
305 }
306 // Only want the directory. Switch file name for the AppInit DLL.
307 base::FilePath full_dll_path(path);
308 full_dll_path = full_dll_path.DirName();
309 full_dll_path = full_dll_path.Append(g_hook_dll_file);
310 wchar_t* non_const = const_cast<wchar_t*>(full_dll_path.value().c_str());
311 // Now make sure the path is in "short-name" form for registry.
312 DWORD length = ::GetShortPathNameW(non_const, NULL, 0);
313 std::vector<wchar_t> short_name(length);
314 if (!::GetShortPathNameW(non_const, &short_name[0], length)) {
315 ADD_FAILURE();
316 return;
317 }
318
319 // 1. Reg setup.
320 const wchar_t* app_init_reg_path =
321 L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Windows";
322 const wchar_t* dlls_value_name = L"AppInit_DLLs";
323 const wchar_t* enabled_value_name = L"LoadAppInit_DLLs";
324 const wchar_t* signing_value_name = L"RequireSignedAppInit_DLLs";
325 std::wstring orig_dlls;
326 std::wstring new_dlls;
327 DWORD orig_enabled_value = 0;
328 DWORD orig_signing_value = 0;
329 base::win::RegKey app_init_key(HKEY_LOCAL_MACHINE, app_init_reg_path,
330 KEY_QUERY_VALUE | KEY_SET_VALUE);
331 // Backup the existing settings.
332 if (!app_init_key.Valid() || !app_init_key.HasValue(dlls_value_name) ||
333 !app_init_key.HasValue(enabled_value_name) ||
334 ERROR_SUCCESS != app_init_key.ReadValue(dlls_value_name, &orig_dlls) ||
335 ERROR_SUCCESS !=
336 app_init_key.ReadValueDW(enabled_value_name, &orig_enabled_value)) {
337 ADD_FAILURE();
338 return;
339 }
340 if (app_init_key.HasValue(signing_value_name)) {
341 if (ERROR_SUCCESS !=
342 app_init_key.ReadValueDW(signing_value_name, &orig_signing_value)) {
343 ADD_FAILURE();
344 return;
345 }
346 }
347
348 // Set the new settings (obviously requires local admin privileges).
349 new_dlls = orig_dlls;
350 if (!orig_dlls.empty())
351 new_dlls.append(L",");
352 new_dlls.append(short_name.data());
353
354 // From this point on, no return on failure. Cleanup required.
355 bool all_good = true;
356
357 if (app_init_key.HasValue(signing_value_name)) {
358 if (ERROR_SUCCESS !=
359 app_init_key.WriteValue(signing_value_name, static_cast<DWORD>(0))) {
360 ADD_FAILURE();
361 all_good = false;
362 }
363 }
364 if (ERROR_SUCCESS !=
365 app_init_key.WriteValue(dlls_value_name, new_dlls.c_str()) ||
366 ERROR_SUCCESS !=
367 app_init_key.WriteValue(enabled_value_name, static_cast<DWORD>(1))) {
368 ADD_FAILURE();
369 all_good = false;
370 }
371
372 // 2. Spawn WinProc.
373 HANDLE winproc_event = INVALID_HANDLE_VALUE;
374 base::win::ScopedHandle scoped_event;
375 PROCESS_INFORMATION proc_info = {};
376 if (all_good) {
377 winproc_event = ::CreateEventW(NULL, FALSE, FALSE, g_winproc_event);
378 if (winproc_event == NULL || winproc_event == INVALID_HANDLE_VALUE) {
379 ADD_FAILURE();
380 all_good = false;
381 } else {
382 scoped_event.Set(winproc_event);
383 if (!SpawnWinProc(&proc_info, is_success_test, &winproc_event))
384 all_good = false;
385 }
386 }
387
388 // 3. Check loaded modules in WinProc to see if the AppInit dll is loaded.
389 bool dll_loaded = false;
390 if (all_good) {
391 std::vector<HMODULE>(modules);
392 if (!base::win::GetLoadedModulesSnapshot(proc_info.hProcess, &modules)) {
393 ADD_FAILURE();
394 all_good = false;
395 } else {
396 for (auto module : modules) {
397 wchar_t name[MAX_PATH] = {};
398 if (::GetModuleFileNameExW(proc_info.hProcess, module, name,
399 MAX_PATH) &&
400 ::wcsstr(name, g_hook_dll_file)) {
401 // Found it.
402 dll_loaded = true;
403 break;
404 }
405 }
406 }
407 }
408
409 // Was the test result as expected?
410 if (all_good)
411 EXPECT_EQ((is_success_test ? true : false), dll_loaded);
412
413 // 4. Trigger shutdown of WinProc.
414 if (proc_info.hProcess) {
415 if (::PostThreadMessageW(proc_info.dwThreadId, WM_QUIT, 0, 0)) {
416 ::WaitForSingleObject(winproc_event, event_timeout);
417 } else {
418 // Ensure no strays.
419 ::TerminateProcess(proc_info.hProcess, 0);
420 ADD_FAILURE();
421 }
422 EXPECT_TRUE(::CloseHandle(proc_info.hThread));
423 EXPECT_TRUE(::CloseHandle(proc_info.hProcess));
424 }
425
426 // 5. Reg Restore
427 EXPECT_EQ(ERROR_SUCCESS,
428 app_init_key.WriteValue(enabled_value_name, orig_enabled_value));
429 if (app_init_key.HasValue(signing_value_name))
430 EXPECT_EQ(ERROR_SUCCESS,
431 app_init_key.WriteValue(signing_value_name, orig_signing_value));
432 EXPECT_EQ(ERROR_SUCCESS,
433 app_init_key.WriteValue(dlls_value_name, orig_dlls.c_str()));
434 }
435
119 void TestWin10ImageLoadRemote(bool is_success_test) { 436 void TestWin10ImageLoadRemote(bool is_success_test) {
120 // ***Insert your manual testing share UNC path here! 437 // ***Insert a manual testing share UNC path here!
121 // E.g.: \\\\hostname\\sharename\\calc.exe 438 // E.g.: \\\\hostname\\sharename\\calc.exe
122 std::wstring unc = L"\"\\\\hostname\\sharename\\calc.exe\""; 439 std::wstring unc = L"\"\\\\hostname\\sharename\\calc.exe\"";
123 440
124 sandbox::TestRunner runner; 441 sandbox::TestRunner runner;
125 sandbox::TargetPolicy* policy = runner.GetPolicy(); 442 sandbox::TargetPolicy* policy = runner.GetPolicy();
126 443
127 // Set a policy that would normally allow for process creation. 444 // Set a policy that would normally allow for process creation.
128 policy->SetJobLevel(sandbox::JOB_NONE, 0); 445 policy->SetJobLevel(sandbox::JOB_NONE, 0);
129 policy->SetTokenLevel(sandbox::USER_UNPROTECTED, sandbox::USER_UNPROTECTED); 446 policy->SetTokenLevel(sandbox::USER_UNPROTECTED, sandbox::USER_UNPROTECTED);
130 runner.SetDisableCsrss(false); 447 runner.SetDisableCsrss(false);
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 setup_proc.Terminate(desired_exit_code, false); 836 setup_proc.Terminate(desired_exit_code, false);
520 return SBOX_TEST_SUCCEEDED; 837 return SBOX_TEST_SUCCEEDED;
521 } 838 }
522 // Note: GetLastError from CreateProcess returns 5, "ERROR_ACCESS_DENIED". 839 // Note: GetLastError from CreateProcess returns 5, "ERROR_ACCESS_DENIED".
523 return SBOX_TEST_FAILED; 840 return SBOX_TEST_FAILED;
524 } 841 }
525 842
526 //------------------------------------------------------------------------------ 843 //------------------------------------------------------------------------------
527 // Win8 Checks: 844 // Win8 Checks:
528 // MITIGATION_DEP(_NO_ATL_THUNK) 845 // MITIGATION_DEP(_NO_ATL_THUNK)
529 // MITIGATION_EXTENSION_DLL_DISABLE
530 // MITIGATION_RELOCATE_IMAGE(_REQUIRED) - ASLR, release only 846 // MITIGATION_RELOCATE_IMAGE(_REQUIRED) - ASLR, release only
531 // MITIGATION_STRICT_HANDLE_CHECKS 847 // MITIGATION_STRICT_HANDLE_CHECKS
532 // >= Win8 848 // >= Win8
533 //------------------------------------------------------------------------------ 849 //------------------------------------------------------------------------------
534 850
535 SBOX_TESTS_COMMAND int CheckWin8(int argc, wchar_t **argv) { 851 SBOX_TESTS_COMMAND int CheckWin8(int argc, wchar_t** argv) {
536 get_process_mitigation_policy = 852 get_process_mitigation_policy =
537 reinterpret_cast<GetProcessMitigationPolicyFunction>( 853 reinterpret_cast<GetProcessMitigationPolicyFunction>(::GetProcAddress(
538 ::GetProcAddress(::GetModuleHandleW(L"kernel32.dll"), 854 ::GetModuleHandleW(L"kernel32.dll"), "GetProcessMitigationPolicy"));
539 "GetProcessMitigationPolicy"));
540 if (!get_process_mitigation_policy) 855 if (!get_process_mitigation_policy)
541 return SBOX_TEST_NOT_FOUND; 856 return SBOX_TEST_NOT_FOUND;
542 857
543 #if !defined(_WIN64) // DEP is always enabled on 64-bit. 858 #if !defined(_WIN64) // DEP is always enabled on 64-bit.
544 if (!CheckWin8DepPolicy()) 859 if (!CheckWin8DepPolicy())
545 return SBOX_TEST_FIRST_ERROR; 860 return SBOX_TEST_FIRST_ERROR;
546 #endif 861 #endif
547 862
548 #if defined(NDEBUG) // ASLR cannot be forced in debug builds. 863 #if defined(NDEBUG) // ASLR cannot be forced in debug builds.
549 if (!CheckWin8AslrPolicy()) 864 if (!CheckWin8AslrPolicy())
550 return SBOX_TEST_SECOND_ERROR; 865 return SBOX_TEST_SECOND_ERROR;
551 #endif 866 #endif
552 867
553 if (!CheckWin8StrictHandlePolicy()) 868 if (!CheckWin8StrictHandlePolicy())
554 return SBOX_TEST_THIRD_ERROR; 869 return SBOX_TEST_THIRD_ERROR;
555 870
556 if (!CheckWin8DllExtensionPolicy())
557 return SBOX_TEST_FIFTH_ERROR;
558
559 return SBOX_TEST_SUCCEEDED; 871 return SBOX_TEST_SUCCEEDED;
560 } 872 }
561 873
562 TEST(ProcessMitigationsTest, CheckWin8) { 874 TEST(ProcessMitigationsTest, CheckWin8) {
563 if (base::win::GetVersion() < base::win::VERSION_WIN8) 875 if (base::win::GetVersion() < base::win::VERSION_WIN8)
564 return; 876 return;
565 877
566 TestRunner runner; 878 TestRunner runner;
567 sandbox::TargetPolicy* policy = runner.GetPolicy(); 879 sandbox::TargetPolicy* policy = runner.GetPolicy();
568 880
569 sandbox::MitigationFlags mitigations = MITIGATION_DEP | 881 sandbox::MitigationFlags mitigations =
570 MITIGATION_DEP_NO_ATL_THUNK | 882 MITIGATION_DEP | MITIGATION_DEP_NO_ATL_THUNK;
571 MITIGATION_EXTENSION_DLL_DISABLE;
572 #if defined(NDEBUG) // ASLR cannot be forced in debug builds. 883 #if defined(NDEBUG) // ASLR cannot be forced in debug builds.
573 mitigations |= MITIGATION_RELOCATE_IMAGE | 884 mitigations |= MITIGATION_RELOCATE_IMAGE | MITIGATION_RELOCATE_IMAGE_REQUIRED;
574 MITIGATION_RELOCATE_IMAGE_REQUIRED;
575 #endif 885 #endif
576 886
577 EXPECT_EQ(policy->SetProcessMitigations(mitigations), SBOX_ALL_OK); 887 EXPECT_EQ(policy->SetProcessMitigations(mitigations), SBOX_ALL_OK);
578 888
579 mitigations |= MITIGATION_STRICT_HANDLE_CHECKS; 889 mitigations |= MITIGATION_STRICT_HANDLE_CHECKS;
580 890
581 EXPECT_EQ(policy->SetDelayedProcessMitigations(mitigations), SBOX_ALL_OK); 891 EXPECT_EQ(policy->SetDelayedProcessMitigations(mitigations), SBOX_ALL_OK);
582 892
583 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckWin8")); 893 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckWin8"));
584 } 894 }
585 895
586 //------------------------------------------------------------------------------ 896 //------------------------------------------------------------------------------
587 // DEP (MITIGATION_DEP) 897 // DEP (MITIGATION_DEP)
588 // < Win8 x86 898 // < Win8 x86
589 //------------------------------------------------------------------------------ 899 //------------------------------------------------------------------------------
590 900
591 SBOX_TESTS_COMMAND int CheckDep(int argc, wchar_t **argv) { 901 SBOX_TESTS_COMMAND int CheckDep(int argc, wchar_t** argv) {
592 GetProcessDEPPolicyFunction get_process_dep_policy = 902 GetProcessDEPPolicyFunction get_process_dep_policy =
593 reinterpret_cast<GetProcessDEPPolicyFunction>( 903 reinterpret_cast<GetProcessDEPPolicyFunction>(::GetProcAddress(
594 ::GetProcAddress(::GetModuleHandleW(L"kernel32.dll"), 904 ::GetModuleHandleW(L"kernel32.dll"), "GetProcessDEPPolicy"));
595 "GetProcessDEPPolicy"));
596 if (get_process_dep_policy) { 905 if (get_process_dep_policy) {
597 BOOL is_permanent = FALSE; 906 BOOL is_permanent = FALSE;
598 DWORD dep_flags = 0; 907 DWORD dep_flags = 0;
599 908
600 if (!get_process_dep_policy(::GetCurrentProcess(), &dep_flags, 909 if (!get_process_dep_policy(::GetCurrentProcess(), &dep_flags,
601 &is_permanent)) { 910 &is_permanent)) {
602 return SBOX_TEST_FIRST_ERROR; 911 return SBOX_TEST_FIRST_ERROR;
603 } 912 }
604 913
605 if (!(dep_flags & PROCESS_DEP_ENABLE) || !is_permanent) 914 if (!(dep_flags & PROCESS_DEP_ENABLE) || !is_permanent)
606 return SBOX_TEST_SECOND_ERROR; 915 return SBOX_TEST_SECOND_ERROR;
607 916
608 } else { 917 } else {
609 NtQueryInformationProcessFunction query_information_process = NULL; 918 NtQueryInformationProcessFunction query_information_process = NULL;
610 ResolveNTFunctionPtr("NtQueryInformationProcess", 919 ResolveNTFunctionPtr("NtQueryInformationProcess",
611 &query_information_process); 920 &query_information_process);
612 if (!query_information_process) 921 if (!query_information_process)
613 return SBOX_TEST_NOT_FOUND; 922 return SBOX_TEST_NOT_FOUND;
614 923
615 ULONG size = 0; 924 ULONG size = 0;
616 ULONG dep_flags = 0; 925 ULONG dep_flags = 0;
617 if (!SUCCEEDED(query_information_process(::GetCurrentProcess(), 926 if (!SUCCEEDED(query_information_process(::GetCurrentProcess(),
618 ProcessExecuteFlags, &dep_flags, 927 ProcessExecuteFlags, &dep_flags,
619 sizeof(dep_flags), &size))) { 928 sizeof(dep_flags), &size))) {
620 return SBOX_TEST_THIRD_ERROR; 929 return SBOX_TEST_THIRD_ERROR;
621 } 930 }
622 931
623 static const int MEM_EXECUTE_OPTION_DISABLE = 2; 932 static const int MEM_EXECUTE_OPTION_DISABLE = 2;
624 static const int MEM_EXECUTE_OPTION_PERMANENT = 8; 933 static const int MEM_EXECUTE_OPTION_PERMANENT = 8;
625 dep_flags &= 0xff; 934 dep_flags &= 0xff;
626 935
627 if (dep_flags != (MEM_EXECUTE_OPTION_DISABLE | 936 if (dep_flags !=
628 MEM_EXECUTE_OPTION_PERMANENT)) { 937 (MEM_EXECUTE_OPTION_DISABLE | MEM_EXECUTE_OPTION_PERMANENT)) {
629 return SBOX_TEST_FOURTH_ERROR; 938 return SBOX_TEST_FOURTH_ERROR;
630 } 939 }
631 } 940 }
632 941
633 return SBOX_TEST_SUCCEEDED; 942 return SBOX_TEST_SUCCEEDED;
634 } 943 }
635 944
636 #if !defined(_WIN64) // DEP is always enabled on 64-bit. 945 #if !defined(_WIN64) // DEP is always enabled on 64-bit.
637 TEST(ProcessMitigationsTest, CheckDep) { 946 TEST(ProcessMitigationsTest, CheckDep) {
638 if (base::win::GetVersion() > base::win::VERSION_WIN7) 947 if (base::win::GetVersion() > base::win::VERSION_WIN7)
639 return; 948 return;
640 949
641 TestRunner runner; 950 TestRunner runner;
642 sandbox::TargetPolicy* policy = runner.GetPolicy(); 951 sandbox::TargetPolicy* policy = runner.GetPolicy();
643 952
644 EXPECT_EQ(policy->SetProcessMitigations( 953 EXPECT_EQ(policy->SetProcessMitigations(MITIGATION_DEP |
645 MITIGATION_DEP | 954 MITIGATION_DEP_NO_ATL_THUNK |
646 MITIGATION_DEP_NO_ATL_THUNK | 955 MITIGATION_SEHOP),
647 MITIGATION_SEHOP),
648 SBOX_ALL_OK); 956 SBOX_ALL_OK);
649 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckDep")); 957 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckDep"));
650 } 958 }
651 #endif 959 #endif
652 960
653 //------------------------------------------------------------------------------ 961 //------------------------------------------------------------------------------
654 // Win32k Lockdown (MITIGATION_WIN32K_DISABLE) 962 // Win32k Lockdown (MITIGATION_WIN32K_DISABLE)
655 // >= Win8 963 // >= Win8
656 //------------------------------------------------------------------------------ 964 //------------------------------------------------------------------------------
657 965
658 SBOX_TESTS_COMMAND int CheckWin8Lockdown(int argc, wchar_t **argv) { 966 SBOX_TESTS_COMMAND int CheckWin8Lockdown(int argc, wchar_t** argv) {
659 get_process_mitigation_policy = 967 get_process_mitigation_policy =
660 reinterpret_cast<GetProcessMitigationPolicyFunction>( 968 reinterpret_cast<GetProcessMitigationPolicyFunction>(::GetProcAddress(
661 ::GetProcAddress(::GetModuleHandleW(L"kernel32.dll"), 969 ::GetModuleHandleW(L"kernel32.dll"), "GetProcessMitigationPolicy"));
662 "GetProcessMitigationPolicy"));
663 if (!get_process_mitigation_policy) 970 if (!get_process_mitigation_policy)
664 return SBOX_TEST_NOT_FOUND; 971 return SBOX_TEST_NOT_FOUND;
665 972
666 if (!CheckWin8Win32CallPolicy()) 973 if (!CheckWin8Win32CallPolicy())
667 return SBOX_TEST_FIRST_ERROR; 974 return SBOX_TEST_FIRST_ERROR;
668 return SBOX_TEST_SUCCEEDED; 975 return SBOX_TEST_SUCCEEDED;
669 } 976 }
670 977
671 SBOX_TESTS_COMMAND int CheckWin8MonitorsRedirection(int argc, wchar_t** argv) { 978 SBOX_TESTS_COMMAND int CheckWin8MonitorsRedirection(int argc, wchar_t** argv) {
672 std::map<HMONITOR, base::string16> monitors = EnumerateMonitors(); 979 std::map<HMONITOR, base::string16> monitors = EnumerateMonitors();
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 sandbox::SBOX_ALL_OK); 1329 sandbox::SBOX_ALL_OK);
1023 policy->SetEnableOPMRedirection(); 1330 policy->SetEnableOPMRedirection();
1024 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckWin8Lockdown")); 1331 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckWin8Lockdown"));
1025 EXPECT_EQ(SBOX_TEST_SUCCEEDED, 1332 EXPECT_EQ(SBOX_TEST_SUCCEEDED,
1026 runner.RunTest(L"CheckWin8MonitorsRedirection")); 1333 runner.RunTest(L"CheckWin8MonitorsRedirection"));
1027 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckWin8MonitorInfo")); 1334 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckWin8MonitorInfo"));
1028 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckWin8OPMApis")); 1335 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckWin8OPMApis"));
1029 } 1336 }
1030 1337
1031 //------------------------------------------------------------------------------ 1338 //------------------------------------------------------------------------------
1339 // Disable extension points (MITIGATION_EXTENSION_POINT_DISABLE).
1340 // >= Win8
1341 //------------------------------------------------------------------------------
1342 SBOX_TESTS_COMMAND int CheckWin8ExtensionPointSetting(int argc,
1343 wchar_t** argv) {
1344 get_process_mitigation_policy =
1345 reinterpret_cast<GetProcessMitigationPolicyFunction>(::GetProcAddress(
1346 ::GetModuleHandleW(L"kernel32.dll"), "GetProcessMitigationPolicy"));
1347 if (!get_process_mitigation_policy)
1348 return SBOX_TEST_NOT_FOUND;
1349
1350 if (!CheckWin8ExtensionPointPolicy())
1351 return SBOX_TEST_FIRST_ERROR;
1352 return SBOX_TEST_SUCCEEDED;
1353 }
1354
1355 // This test validates that setting the MITIGATION_EXTENSION_POINT_DISABLE
1356 // mitigation enables the setting on a process.
1357 TEST(ProcessMitigationsTest, CheckWin8ExtensionPointPolicySuccess) {
1358 if (base::win::GetVersion() < base::win::VERSION_WIN8)
1359 return;
1360
1361 TestRunner runner;
1362 sandbox::TargetPolicy* policy = runner.GetPolicy();
1363
1364 EXPECT_EQ(policy->SetProcessMitigations(MITIGATION_EXTENSION_POINT_DISABLE),
1365 SBOX_ALL_OK);
1366 EXPECT_EQ(SBOX_TEST_SUCCEEDED,
1367 runner.RunTest(L"CheckWin8ExtensionPointSetting"));
1368 }
1369
1370 // This test validates that a "legitimate" global hook CAN be set on the
1371 // sandboxed proc/thread if the MITIGATION_EXTENSION_POINT_DISABLE
1372 // mitigation is not set.
1373 //
1374 // MANUAL testing only.
1375 TEST(ProcessMitigationsTest,
1376 DISABLED_CheckWin8ExtensionPoint_GlobalHook_Success) {
1377 if (base::win::GetVersion() < base::win::VERSION_WIN8)
1378 return;
1379
1380 HANDLE mutex = ::CreateMutexW(NULL, FALSE, g_extension_point_test_mutex);
1381 EXPECT_TRUE(mutex != NULL && mutex != INVALID_HANDLE_VALUE);
1382 EXPECT_EQ(WAIT_OBJECT_0, ::WaitForSingleObject(mutex, event_timeout));
1383
1384 // (is_success_test, global_hook)
1385 TestWin8ExtensionPointHookWrapper(true, true);
1386
1387 EXPECT_TRUE(::ReleaseMutex(mutex));
1388 EXPECT_TRUE(::CloseHandle(mutex));
1389 }
1390
1391 // This test validates that setting the MITIGATION_EXTENSION_POINT_DISABLE
1392 // mitigation prevents a global hook on WinProc.
1393 //
1394 // MANUAL testing only.
1395 TEST(ProcessMitigationsTest,
1396 DISABLED_CheckWin8ExtensionPoint_GlobalHook_Failure) {
1397 if (base::win::GetVersion() < base::win::VERSION_WIN8)
1398 return;
1399
1400 HANDLE mutex = ::CreateMutexW(NULL, FALSE, g_extension_point_test_mutex);
1401 EXPECT_TRUE(mutex != NULL && mutex != INVALID_HANDLE_VALUE);
1402 EXPECT_EQ(WAIT_OBJECT_0, ::WaitForSingleObject(mutex, event_timeout));
1403
1404 // (is_success_test, global_hook)
1405 TestWin8ExtensionPointHookWrapper(false, true);
1406
1407 EXPECT_TRUE(::ReleaseMutex(mutex));
1408 EXPECT_TRUE(::CloseHandle(mutex));
1409 }
1410
1411 // This test validates that a "legitimate" hook CAN be set on the sandboxed
1412 // proc/thread if the MITIGATION_EXTENSION_POINT_DISABLE mitigation is not set.
1413 //
1414 // MANUAL testing only.
1415 TEST(ProcessMitigationsTest, DISABLED_CheckWin8ExtensionPoint_Hook_Success) {
1416 if (base::win::GetVersion() < base::win::VERSION_WIN8)
1417 return;
1418
1419 HANDLE mutex = ::CreateMutexW(NULL, FALSE, g_extension_point_test_mutex);
1420 EXPECT_TRUE(mutex != NULL && mutex != INVALID_HANDLE_VALUE);
1421 EXPECT_EQ(WAIT_OBJECT_0, ::WaitForSingleObject(mutex, event_timeout));
1422
1423 // (is_success_test, global_hook)
1424 TestWin8ExtensionPointHookWrapper(true, false);
1425
1426 EXPECT_TRUE(::ReleaseMutex(mutex));
1427 EXPECT_TRUE(::CloseHandle(mutex));
1428 }
1429
1430 // *** Important: MITIGATION_EXTENSION_POINT_DISABLE does NOT prevent
1431 // hooks targetted at a specific thread id. It only prevents
1432 // global hooks. So this test does NOT actually expect the hook
1433 // to fail (see TestWin8ExtensionPointHookWrapper function) even
1434 // with the mitigation on.
1435 //
1436 // MANUAL testing only.
1437 TEST(ProcessMitigationsTest, DISABLED_CheckWin8ExtensionPoint_Hook_Failure) {
1438 if (base::win::GetVersion() < base::win::VERSION_WIN8)
1439 return;
1440
1441 HANDLE mutex = ::CreateMutexW(NULL, FALSE, g_extension_point_test_mutex);
1442 EXPECT_TRUE(mutex != NULL && mutex != INVALID_HANDLE_VALUE);
1443 EXPECT_EQ(WAIT_OBJECT_0, ::WaitForSingleObject(mutex, event_timeout));
1444
1445 // (is_success_test, global_hook)
1446 TestWin8ExtensionPointHookWrapper(false, false);
1447
1448 EXPECT_TRUE(::ReleaseMutex(mutex));
1449 EXPECT_TRUE(::CloseHandle(mutex));
1450 }
1451
1452 // This test validates that an AppInit Dll CAN be added to a target
1453 // WinProc if the MITIGATION_EXTENSION_POINT_DISABLE mitigation is not set.
1454 //
1455 // MANUAL testing only.
1456 // Must run this test as admin/elevated.
1457 TEST(ProcessMitigationsTest, DISABLED_CheckWin8ExtensionPoint_AppInit_Success) {
1458 if (base::win::GetVersion() < base::win::VERSION_WIN8)
1459 return;
1460
1461 HANDLE mutex = ::CreateMutexW(NULL, FALSE, g_extension_point_test_mutex);
1462 EXPECT_TRUE(mutex != NULL && mutex != INVALID_HANDLE_VALUE);
1463 EXPECT_EQ(WAIT_OBJECT_0, ::WaitForSingleObject(mutex, event_timeout));
1464
1465 TestWin8ExtensionPointAppInitWrapper(true);
1466
1467 EXPECT_TRUE(::ReleaseMutex(mutex));
1468 EXPECT_TRUE(::CloseHandle(mutex));
1469 }
1470
1471 // This test validates that setting the MITIGATION_EXTENSION_POINT_DISABLE
1472 // mitigation prevents the loading of any AppInit Dll into WinProc.
1473 //
1474 // MANUAL testing only.
1475 // Must run this test as admin/elevated.
1476 TEST(ProcessMitigationsTest, DISABLED_CheckWin8ExtensionPoint_AppInit_Failure) {
1477 if (base::win::GetVersion() < base::win::VERSION_WIN8)
1478 return;
1479
1480 HANDLE mutex = ::CreateMutexW(NULL, FALSE, g_extension_point_test_mutex);
1481 EXPECT_TRUE(mutex != NULL && mutex != INVALID_HANDLE_VALUE);
1482 EXPECT_EQ(WAIT_OBJECT_0, ::WaitForSingleObject(mutex, event_timeout));
1483
1484 TestWin8ExtensionPointAppInitWrapper(false);
1485
1486 EXPECT_TRUE(::ReleaseMutex(mutex));
1487 EXPECT_TRUE(::CloseHandle(mutex));
1488 }
1489
1490 //------------------------------------------------------------------------------
1032 // Disable non-system font loads (MITIGATION_NONSYSTEM_FONT_DISABLE) 1491 // Disable non-system font loads (MITIGATION_NONSYSTEM_FONT_DISABLE)
1033 // >= Win10 1492 // >= Win10
1034 //------------------------------------------------------------------------------ 1493 //------------------------------------------------------------------------------
1035 1494
1036 SBOX_TESTS_COMMAND int CheckWin10FontLockDown(int argc, wchar_t** argv) { 1495 SBOX_TESTS_COMMAND int CheckWin10FontLockDown(int argc, wchar_t** argv) {
1037 get_process_mitigation_policy = 1496 get_process_mitigation_policy =
1038 reinterpret_cast<GetProcessMitigationPolicyFunction>(::GetProcAddress( 1497 reinterpret_cast<GetProcessMitigationPolicyFunction>(::GetProcAddress(
1039 ::GetModuleHandleW(L"kernel32.dll"), "GetProcessMitigationPolicy")); 1498 ::GetModuleHandleW(L"kernel32.dll"), "GetProcessMitigationPolicy"));
1040 if (!get_process_mitigation_policy) 1499 if (!get_process_mitigation_policy)
1041 return SBOX_TEST_NOT_FOUND; 1500 return SBOX_TEST_NOT_FOUND;
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 policy->SetDelayedProcessMitigations(MITIGATION_IMAGE_LOAD_NO_REMOTE), 1645 policy->SetDelayedProcessMitigations(MITIGATION_IMAGE_LOAD_NO_REMOTE),
1187 SBOX_ALL_OK); 1646 SBOX_ALL_OK);
1188 EXPECT_EQ(SBOX_TEST_SUCCEEDED, 1647 EXPECT_EQ(SBOX_TEST_SUCCEEDED,
1189 runner.RunTest(L"CheckWin10ImageLoadNoRemote")); 1648 runner.RunTest(L"CheckWin10ImageLoadNoRemote"));
1190 } 1649 }
1191 1650
1192 // This test validates that we CAN create a new process from 1651 // This test validates that we CAN create a new process from
1193 // a remote UNC device, if the MITIGATION_IMAGE_LOAD_NO_REMOTE 1652 // a remote UNC device, if the MITIGATION_IMAGE_LOAD_NO_REMOTE
1194 // mitigation is NOT set. 1653 // mitigation is NOT set.
1195 // 1654 //
1196 // DISABLED for automated testing bots. Enable for manual testing. 1655 // MANUAL testing only.
1197 TEST(ProcessMitigationsTest, DISABLED_CheckWin10ImageLoadNoRemoteSuccess) { 1656 TEST(ProcessMitigationsTest, DISABLED_CheckWin10ImageLoadNoRemoteSuccess) {
1198 if (base::win::GetVersion() < base::win::VERSION_WIN10_TH2) 1657 if (base::win::GetVersion() < base::win::VERSION_WIN10_TH2)
1199 return; 1658 return;
1200 1659
1201 TestWin10ImageLoadRemote(true); 1660 TestWin10ImageLoadRemote(true);
1202 } 1661 }
1203 1662
1204 // This test validates that setting the MITIGATION_IMAGE_LOAD_NO_REMOTE 1663 // This test validates that setting the MITIGATION_IMAGE_LOAD_NO_REMOTE
1205 // mitigation prevents creating a new process from a remote 1664 // mitigation prevents creating a new process from a remote
1206 // UNC device. 1665 // UNC device.
1207 // 1666 //
1208 // DISABLED for automated testing bots. Enable for manual testing. 1667 // MANUAL testing only.
1209 TEST(ProcessMitigationsTest, DISABLED_CheckWin10ImageLoadNoRemoteFailure) { 1668 TEST(ProcessMitigationsTest, DISABLED_CheckWin10ImageLoadNoRemoteFailure) {
1210 if (base::win::GetVersion() < base::win::VERSION_WIN10_TH2) 1669 if (base::win::GetVersion() < base::win::VERSION_WIN10_TH2)
1211 return; 1670 return;
1212 1671
1213 TestWin10ImageLoadRemote(false); 1672 TestWin10ImageLoadRemote(false);
1214 } 1673 }
1215 1674
1216 //------------------------------------------------------------------------------ 1675 //------------------------------------------------------------------------------
1217 // Disable image load when "mandatory low label" (integrity level). 1676 // Disable image load when "mandatory low label" (integrity level).
1218 // (MITIGATION_IMAGE_LOAD_NO_LOW_LABEL) 1677 // (MITIGATION_IMAGE_LOAD_NO_LOW_LABEL)
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1340 cmd = cmd.Append(L"calc.exe"); 1799 cmd = cmd.Append(L"calc.exe");
1341 1800
1342 std::wstring test_command(base::StringPrintf(L"TestChildProcess %ls 0x%08X", 1801 std::wstring test_command(base::StringPrintf(L"TestChildProcess %ls 0x%08X",
1343 cmd.value().c_str(), 1802 cmd.value().c_str(),
1344 STATUS_ACCESS_VIOLATION)); 1803 STATUS_ACCESS_VIOLATION));
1345 1804
1346 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(test_command.c_str())); 1805 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(test_command.c_str()));
1347 } 1806 }
1348 1807
1349 } // namespace sandbox 1808 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/win/src/process_mitigations.cc ('k') | sandbox/win/src/security_level.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698