-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path96fb78fb034568922526420d5226fe9ff5193e10.diff
514 lines (484 loc) · 24 KB
/
96fb78fb034568922526420d5226fe9ff5193e10.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
diff --git a/sandbox/win/src/app_container_base.cc b/sandbox/win/src/app_container_base.cc
index 8fd0b01040c31..c8816bb41947c 100644
--- a/sandbox/win/src/app_container_base.cc
+++ b/sandbox/win/src/app_container_base.cc
@@ -20,6 +20,18 @@ namespace sandbox {
namespace {
+typedef decltype(::CreateAppContainerProfile) CreateAppContainerProfileFunc;
+
+typedef decltype(::DeriveAppContainerSidFromAppContainerName)
+ DeriveAppContainerSidFromAppContainerNameFunc;
+
+typedef decltype(::DeleteAppContainerProfile) DeleteAppContainerProfileFunc;
+
+typedef decltype(::GetAppContainerFolderPath) GetAppContainerFolderPathFunc;
+
+typedef decltype(
+ ::GetAppContainerRegistryLocation) GetAppContainerRegistryLocationFunc;
+
struct FreeSidDeleter {
inline void operator()(void* ptr) const { ::FreeSid(ptr); }
};
@@ -30,8 +42,14 @@ struct FreeSidDeleter {
AppContainerBase* AppContainerBase::CreateProfile(const wchar_t* package_name,
const wchar_t* display_name,
const wchar_t* description) {
+ static auto create_app_container_profile =
+ reinterpret_cast<CreateAppContainerProfileFunc*>(GetProcAddress(
+ GetModuleHandle(L"userenv"), "CreateAppContainerProfile"));
+ if (!create_app_container_profile)
+ return nullptr;
+
PSID package_sid_ptr = nullptr;
- HRESULT hr = ::CreateAppContainerProfile(
+ HRESULT hr = create_app_container_profile(
package_name, display_name, description, nullptr, 0, &package_sid_ptr);
if (hr == HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS))
return Open(package_name);
@@ -47,9 +65,15 @@ AppContainerBase* AppContainerBase::CreateProfile(const wchar_t* package_name,
// static
AppContainerBase* AppContainerBase::Open(const wchar_t* package_name) {
+ static auto derive_app_container_sid =
+ reinterpret_cast<DeriveAppContainerSidFromAppContainerNameFunc*>(
+ GetProcAddress(GetModuleHandle(L"userenv"),
+ "DeriveAppContainerSidFromAppContainerName"));
+ if (!derive_app_container_sid)
+ return nullptr;
+
PSID package_sid_ptr = nullptr;
- HRESULT hr = ::DeriveAppContainerSidFromAppContainerName(package_name,
- &package_sid_ptr);
+ HRESULT hr = derive_app_container_sid(package_name, &package_sid_ptr);
if (FAILED(hr))
return nullptr;
@@ -71,7 +95,13 @@ AppContainerBase* AppContainerBase::CreateLowbox(const wchar_t* sid) {
// static
bool AppContainerBase::Delete(const wchar_t* package_name) {
- return SUCCEEDED(::DeleteAppContainerProfile(package_name));
+ static auto delete_app_container_profile =
+ reinterpret_cast<DeleteAppContainerProfileFunc*>(GetProcAddress(
+ GetModuleHandle(L"userenv"), "DeleteAppContainerProfile"));
+ if (!delete_app_container_profile)
+ return false;
+
+ return SUCCEEDED(delete_app_container_profile(package_name));
}
AppContainerBase::AppContainerBase(base::win::Sid& package_sid,
diff --git a/sandbox/win/src/lpc_policy_test.cc b/sandbox/win/src/lpc_policy_test.cc
index d4e1473d56b2a..567d3fdfe6080 100644
--- a/sandbox/win/src/lpc_policy_test.cc
+++ b/sandbox/win/src/lpc_policy_test.cc
@@ -98,13 +98,35 @@ TEST(LpcPolicyTest, GetUserDefaultLCID) {
EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(cmd.c_str()));
}
+// GetUserDefaultLocaleName is not available on WIN XP. So we'll
+// load it on-the-fly.
+const wchar_t kKernel32DllName[] = L"kernel32.dll";
+typedef int(WINAPI* GetUserDefaultLocaleNameFunction)(LPWSTR lpLocaleName,
+ int cchLocaleName);
+
SBOX_TESTS_COMMAND int Lpc_GetUserDefaultLocaleName(int argc, wchar_t** argv) {
if (argc != 1)
return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND;
std::wstring expected_locale_name(argv[0]);
+ static GetUserDefaultLocaleNameFunction GetUserDefaultLocaleName_func =
+ nullptr;
+ if (!GetUserDefaultLocaleName_func) {
+ // GetUserDefaultLocaleName is not available on WIN XP. So we'll
+ // load it on-the-fly.
+ HMODULE kernel32_dll = ::GetModuleHandle(kKernel32DllName);
+ if (!kernel32_dll) {
+ return SBOX_TEST_FAILED;
+ }
+ GetUserDefaultLocaleName_func =
+ reinterpret_cast<GetUserDefaultLocaleNameFunction>(
+ GetProcAddress(kernel32_dll, "GetUserDefaultLocaleName"));
+ if (!GetUserDefaultLocaleName_func) {
+ return SBOX_TEST_FAILED;
+ }
+ }
wchar_t locale_name[LOCALE_NAME_MAX_LENGTH] = {0};
// This will cause an exception if not warmed up suitably.
- int ret = ::GetUserDefaultLocaleName(
+ int ret = GetUserDefaultLocaleName_func(
locale_name, LOCALE_NAME_MAX_LENGTH * sizeof(wchar_t));
if (!ret) {
return SBOX_TEST_FAILED;
@@ -120,8 +142,20 @@ SBOX_TESTS_COMMAND int Lpc_GetUserDefaultLocaleName(int argc, wchar_t** argv) {
}
TEST(LpcPolicyTest, GetUserDefaultLocaleName) {
+ static GetUserDefaultLocaleNameFunction GetUserDefaultLocaleName_func =
+ nullptr;
+ if (!GetUserDefaultLocaleName_func) {
+ // GetUserDefaultLocaleName is not available on WIN XP. So we'll
+ // load it on-the-fly.
+ HMODULE kernel32_dll = ::GetModuleHandle(kKernel32DllName);
+ EXPECT_NE(nullptr, kernel32_dll);
+ GetUserDefaultLocaleName_func =
+ reinterpret_cast<GetUserDefaultLocaleNameFunction>(
+ GetProcAddress(kernel32_dll, "GetUserDefaultLocaleName"));
+ EXPECT_NE(nullptr, GetUserDefaultLocaleName_func);
+ }
wchar_t locale_name[LOCALE_NAME_MAX_LENGTH] = {0};
- EXPECT_NE(0, ::GetUserDefaultLocaleName(
+ EXPECT_NE(0, GetUserDefaultLocaleName_func(
locale_name, LOCALE_NAME_MAX_LENGTH * sizeof(wchar_t)));
EXPECT_NE(0U, wcsnlen(locale_name, LOCALE_NAME_MAX_LENGTH));
std::wstring cmd =
diff --git a/sandbox/win/src/process_mitigations_unittest.cc b/sandbox/win/src/process_mitigations_unittest.cc
index 267d5dfcaef6c..7923ccf0ae5dc 100644
--- a/sandbox/win/src/process_mitigations_unittest.cc
+++ b/sandbox/win/src/process_mitigations_unittest.cc
@@ -51,6 +51,22 @@ typedef struct _PROCESS_MITIGATION_SYSTEM_CALL_DISABLE_POLICY_2 {
namespace {
+//------------------------------------------------------------------------------
+// Internal Defines & Functions
+//------------------------------------------------------------------------------
+
+// API defined in winbase.h.
+using GetProcessDEPPolicyFunction = decltype(&GetProcessDEPPolicy);
+
+// API defined in processthreadsapi.h.
+using GetProcessMitigationPolicyFunction =
+ decltype(&GetProcessMitigationPolicy);
+GetProcessMitigationPolicyFunction get_process_mitigation_policy;
+
+// APIs defined in wingdi.h.
+using AddFontMemResourceExFunction = decltype(&AddFontMemResourceEx);
+using RemoveFontMemResourceExFunction = decltype(&RemoveFontMemResourceEx);
+
//------------------------------------------------------------------------------
// NonSystemFont test helper function.
//
@@ -104,6 +120,12 @@ SBOX_TESTS_COMMAND int CheckPolicy(int argc, wchar_t** argv) {
if (!test)
return SBOX_TEST_INVALID_PARAMETER;
+ get_process_mitigation_policy =
+ reinterpret_cast<GetProcessMitigationPolicyFunction>(::GetProcAddress(
+ ::GetModuleHandleW(L"kernel32.dll"), "GetProcessMitigationPolicy"));
+ if (!get_process_mitigation_policy)
+ return SBOX_TEST_NOT_FOUND;
+
switch (test) {
//--------------------------------------------------
// MITIGATION_DEP
@@ -113,8 +135,9 @@ SBOX_TESTS_COMMAND int CheckPolicy(int argc, wchar_t** argv) {
#if !defined(_WIN64)
// DEP - always enabled on 64-bit.
PROCESS_MITIGATION_DEP_POLICY policy = {};
- if (!::GetProcessMitigationPolicy(::GetCurrentProcess(), ProcessDEPPolicy,
- &policy, sizeof(policy))) {
+ if (!get_process_mitigation_policy(::GetCurrentProcess(),
+ ProcessDEPPolicy, &policy,
+ sizeof(policy))) {
return SBOX_TEST_NOT_FOUND;
}
if (!policy.Enable || !policy.Permanent)
@@ -128,9 +151,9 @@ SBOX_TESTS_COMMAND int CheckPolicy(int argc, wchar_t** argv) {
//--------------------------------------------------
case (TESTPOLICY_ASLR): {
PROCESS_MITIGATION_ASLR_POLICY policy = {};
- if (!::GetProcessMitigationPolicy(::GetCurrentProcess(),
- ProcessASLRPolicy, &policy,
- sizeof(policy))) {
+ if (!get_process_mitigation_policy(::GetCurrentProcess(),
+ ProcessASLRPolicy, &policy,
+ sizeof(policy))) {
return SBOX_TEST_NOT_FOUND;
}
if (!policy.EnableForceRelocateImages || !policy.DisallowStrippedImages)
@@ -143,9 +166,9 @@ SBOX_TESTS_COMMAND int CheckPolicy(int argc, wchar_t** argv) {
//--------------------------------------------------
case (TESTPOLICY_STRICTHANDLE): {
PROCESS_MITIGATION_STRICT_HANDLE_CHECK_POLICY policy = {};
- if (!::GetProcessMitigationPolicy(::GetCurrentProcess(),
- ProcessStrictHandleCheckPolicy, &policy,
- sizeof(policy))) {
+ if (!get_process_mitigation_policy(::GetCurrentProcess(),
+ ProcessStrictHandleCheckPolicy,
+ &policy, sizeof(policy))) {
return SBOX_TEST_NOT_FOUND;
}
if (!policy.RaiseExceptionOnInvalidHandleReference ||
@@ -160,9 +183,9 @@ SBOX_TESTS_COMMAND int CheckPolicy(int argc, wchar_t** argv) {
}
PROCESS_MITIGATION_SYSTEM_CALL_DISABLE_POLICY policy = {};
- if (!::GetProcessMitigationPolicy(::GetCurrentProcess(),
- ProcessSystemCallDisablePolicy, &policy,
- sizeof(policy))) {
+ if (!get_process_mitigation_policy(::GetCurrentProcess(),
+ ProcessSystemCallDisablePolicy,
+ &policy, sizeof(policy))) {
return SBOX_TEST_NOT_FOUND;
}
if (!policy.DisallowWin32kSystemCalls)
@@ -179,9 +202,9 @@ SBOX_TESTS_COMMAND int CheckPolicy(int argc, wchar_t** argv) {
//--------------------------------------------------
case (TESTPOLICY_EXTENSIONPOINT): {
PROCESS_MITIGATION_EXTENSION_POINT_DISABLE_POLICY policy = {};
- if (!::GetProcessMitigationPolicy(::GetCurrentProcess(),
- ProcessExtensionPointDisablePolicy,
- &policy, sizeof(policy))) {
+ if (!get_process_mitigation_policy(::GetCurrentProcess(),
+ ProcessExtensionPointDisablePolicy,
+ &policy, sizeof(policy))) {
return SBOX_TEST_NOT_FOUND;
}
if (!policy.DisableExtensionPoints)
@@ -194,9 +217,9 @@ SBOX_TESTS_COMMAND int CheckPolicy(int argc, wchar_t** argv) {
//--------------------------------------------------
case (TESTPOLICY_DYNAMICCODE): {
PROCESS_MITIGATION_DYNAMIC_CODE_POLICY policy = {};
- if (!::GetProcessMitigationPolicy(::GetCurrentProcess(),
- ProcessDynamicCodePolicy, &policy,
- sizeof(policy))) {
+ if (!get_process_mitigation_policy(::GetCurrentProcess(),
+ ProcessDynamicCodePolicy, &policy,
+ sizeof(policy))) {
return SBOX_TEST_NOT_FOUND;
}
if (!policy.ProhibitDynamicCode)
@@ -209,9 +232,9 @@ SBOX_TESTS_COMMAND int CheckPolicy(int argc, wchar_t** argv) {
//--------------------------------------------------
case (TESTPOLICY_NONSYSFONT): {
PROCESS_MITIGATION_FONT_DISABLE_POLICY policy = {};
- if (!::GetProcessMitigationPolicy(::GetCurrentProcess(),
- ProcessFontDisablePolicy, &policy,
- sizeof(policy))) {
+ if (!get_process_mitigation_policy(::GetCurrentProcess(),
+ ProcessFontDisablePolicy, &policy,
+ sizeof(policy))) {
return SBOX_TEST_NOT_FOUND;
}
if (!policy.DisableNonSystemFonts)
@@ -224,9 +247,9 @@ SBOX_TESTS_COMMAND int CheckPolicy(int argc, wchar_t** argv) {
//--------------------------------------------------
case (TESTPOLICY_MSSIGNED): {
PROCESS_MITIGATION_BINARY_SIGNATURE_POLICY policy = {};
- if (!::GetProcessMitigationPolicy(::GetCurrentProcess(),
- ProcessSignaturePolicy, &policy,
- sizeof(policy))) {
+ if (!get_process_mitigation_policy(::GetCurrentProcess(),
+ ProcessSignaturePolicy, &policy,
+ sizeof(policy))) {
return SBOX_TEST_NOT_FOUND;
}
if (!policy.MicrosoftSignedOnly)
@@ -239,9 +262,9 @@ SBOX_TESTS_COMMAND int CheckPolicy(int argc, wchar_t** argv) {
//--------------------------------------------------
case (TESTPOLICY_LOADNOREMOTE): {
PROCESS_MITIGATION_IMAGE_LOAD_POLICY policy = {};
- if (!::GetProcessMitigationPolicy(::GetCurrentProcess(),
- ProcessImageLoadPolicy, &policy,
- sizeof(policy))) {
+ if (!get_process_mitigation_policy(::GetCurrentProcess(),
+ ProcessImageLoadPolicy, &policy,
+ sizeof(policy))) {
return SBOX_TEST_NOT_FOUND;
}
if (!policy.NoRemoteImages)
@@ -254,9 +277,9 @@ SBOX_TESTS_COMMAND int CheckPolicy(int argc, wchar_t** argv) {
//--------------------------------------------------
case (TESTPOLICY_LOADNOLOW): {
PROCESS_MITIGATION_IMAGE_LOAD_POLICY policy = {};
- if (!::GetProcessMitigationPolicy(::GetCurrentProcess(),
- ProcessImageLoadPolicy, &policy,
- sizeof(policy))) {
+ if (!get_process_mitigation_policy(::GetCurrentProcess(),
+ ProcessImageLoadPolicy, &policy,
+ sizeof(policy))) {
return SBOX_TEST_NOT_FOUND;
}
if (!policy.NoLowMandatoryLabelImages)
@@ -269,9 +292,9 @@ SBOX_TESTS_COMMAND int CheckPolicy(int argc, wchar_t** argv) {
//--------------------------------------------------
case (TESTPOLICY_DYNAMICCODEOPTOUT): {
PROCESS_MITIGATION_DYNAMIC_CODE_POLICY policy = {};
- if (!::GetProcessMitigationPolicy(::GetCurrentProcess(),
- ProcessDynamicCodePolicy, &policy,
- sizeof(policy))) {
+ if (!get_process_mitigation_policy(::GetCurrentProcess(),
+ ProcessDynamicCodePolicy, &policy,
+ sizeof(policy))) {
return SBOX_TEST_NOT_FOUND;
}
if (!policy.ProhibitDynamicCode || !policy.AllowThreadOptOut)
@@ -284,9 +307,9 @@ SBOX_TESTS_COMMAND int CheckPolicy(int argc, wchar_t** argv) {
//--------------------------------------------------
case (TESTPOLICY_LOADPREFERSYS32): {
PROCESS_MITIGATION_IMAGE_LOAD_POLICY policy = {};
- if (!::GetProcessMitigationPolicy(::GetCurrentProcess(),
- ProcessImageLoadPolicy, &policy,
- sizeof(policy))) {
+ if (!get_process_mitigation_policy(::GetCurrentProcess(),
+ ProcessImageLoadPolicy, &policy,
+ sizeof(policy))) {
return SBOX_TEST_NOT_FOUND;
}
if (!policy.PreferSystem32Images)
@@ -309,9 +332,9 @@ SBOX_TESTS_COMMAND int CheckPolicy(int argc, wchar_t** argv) {
//--------------------------------------------------
case (TESTPOLICY_CETDISABLED): {
PROCESS_MITIGATION_USER_SHADOW_STACK_POLICY policy = {};
- if (!::GetProcessMitigationPolicy(::GetCurrentProcess(),
- ProcessUserShadowStackPolicy, &policy,
- sizeof(policy))) {
+ if (!get_process_mitigation_policy(::GetCurrentProcess(),
+ ProcessUserShadowStackPolicy, &policy,
+ sizeof(policy))) {
return SBOX_TEST_NOT_FOUND;
}
// We wish to disable the policy.
@@ -325,9 +348,9 @@ SBOX_TESTS_COMMAND int CheckPolicy(int argc, wchar_t** argv) {
//--------------------------------------------------
case (TESTPOLICY_CETDYNAMICAPIS): {
PROCESS_MITIGATION_USER_SHADOW_STACK_POLICY policy = {};
- if (!::GetProcessMitigationPolicy(::GetCurrentProcess(),
- ProcessUserShadowStackPolicy, &policy,
- sizeof(policy))) {
+ if (!get_process_mitigation_policy(::GetCurrentProcess(),
+ ProcessUserShadowStackPolicy, &policy,
+ sizeof(policy))) {
return SBOX_TEST_NOT_FOUND;
}
@@ -348,9 +371,9 @@ SBOX_TESTS_COMMAND int CheckPolicy(int argc, wchar_t** argv) {
//--------------------------------------------------
case (TESTPOLICY_CETSTRICT): {
PROCESS_MITIGATION_USER_SHADOW_STACK_POLICY policy = {};
- if (!::GetProcessMitigationPolicy(::GetCurrentProcess(),
- ProcessUserShadowStackPolicy, &policy,
- sizeof(policy))) {
+ if (!get_process_mitigation_policy(::GetCurrentProcess(),
+ ProcessUserShadowStackPolicy, &policy,
+ sizeof(policy))) {
return SBOX_TEST_NOT_FOUND;
}
@@ -389,9 +412,9 @@ SBOX_TESTS_COMMAND int CheckPolicy(int argc, wchar_t** argv) {
case (TESTPOLICY_PREANDPOSTSTARTUP): {
// Both policies should be set now.
PROCESS_MITIGATION_IMAGE_LOAD_POLICY policy = {};
- if (!::GetProcessMitigationPolicy(::GetCurrentProcess(),
- ProcessImageLoadPolicy, &policy,
- sizeof(policy))) {
+ if (!get_process_mitigation_policy(::GetCurrentProcess(),
+ ProcessImageLoadPolicy, &policy,
+ sizeof(policy))) {
return SBOX_TEST_NOT_FOUND;
}
if (!policy.NoLowMandatoryLabelImages)
@@ -429,24 +452,43 @@ SBOX_TESTS_COMMAND int CheckPolicy(int argc, wchar_t** argv) {
// This test attempts a non-system font load.
//
+// 1) Load gdi32.dll for required font APIs.
+// 2) Load file contents of font file passed in arg1 into memory.
+// 3) Call API to try loading a non-system font.
+//
// Arg1: Full path to font file to try loading.
SBOX_TESTS_COMMAND int CheckWin10FontLoad(int argc, wchar_t** argv) {
if (argc < 1)
return SBOX_TEST_INVALID_PARAMETER;
// When the test is run with SetTestState(EVERY_STATE), the return value
// is ignored for the first two states (before InitCalled and before
// RevertedToSelf).
if (!SandboxFactory::GetTargetServices()->GetState()->InitCalled()) {
return 0;
} else if (!SandboxFactory::GetTargetServices()
->GetState()
->RevertedToSelf()) {
// Need to warm up gdi32.dll for the test.
CHECK(::LoadLibrary(L"gdi32.dll"));
return 0;
}
+ HMODULE gdi_module = ::LoadLibraryW(L"gdi32.dll");
+ if (!gdi_module)
+ return SBOX_TEST_NOT_FOUND;
+
+ AddFontMemResourceExFunction add_font_mem_resource =
+ reinterpret_cast<AddFontMemResourceExFunction>(
+ ::GetProcAddress(gdi_module, "AddFontMemResourceEx"));
+
+ RemoveFontMemResourceExFunction rem_font_mem_resource =
+ reinterpret_cast<RemoveFontMemResourceExFunction>(
+ ::GetProcAddress(gdi_module, "RemoveFontMemResourceEx"));
+
+ if (!add_font_mem_resource || !rem_font_mem_resource)
+ return SBOX_TEST_NOT_FOUND;
+
// Open font file passed in as an argument.
base::File file(base::FilePath(argv[0]),
base::File::FLAG_OPEN | base::File::FLAG_READ);
@@ -454,12 +496,12 @@ SBOX_TESTS_COMMAND int CheckWin10FontLoad(int argc, wchar_t** argv) {
return SBOX_TEST_NOT_FOUND;
DWORD font_count = 0;
- HANDLE font_handle = ::AddFontMemResourceEx(
- &font_data[0], static_cast<DWORD>(font_data.size()), nullptr,
- &font_count);
+ HANDLE font_handle =
+ add_font_mem_resource(&font_data[0], static_cast<DWORD>(font_data.size()),
+ nullptr, &font_count);
if (font_handle) {
- ::RemoveFontMemResourceEx(font_handle);
+ rem_font_mem_resource(font_handle);
return SBOX_TEST_SUCCEEDED;
}
@@ -573,14 +615,6 @@ TEST(ProcessMitigationsTest, CheckDepWin8PolicySuccess) {
if (base::win::GetVersion() < base::win::Version::WIN8)
return;
- DWORD flags;
- BOOL permanent;
- ASSERT_TRUE(::GetProcessDEPPolicy(::GetCurrentProcess(), &flags, &permanent));
- // If DEP is enabled permanently these tests are meaningless. Just ignore them
- // for this system.
- if (permanent)
- return;
-
std::wstring test_command = L"CheckPolicy ";
test_command += std::to_wstring(TESTPOLICY_DEP);
@@ -1023,10 +1057,14 @@ TEST(ProcessMitigationsTest, CetDisablePolicy) {
// Verify policy is available and set for this process (i.e. CET is
// enabled via IFEO or through the CETCOMPAT bit on the executable).
+ auto get_process_mitigation_policy =
+ reinterpret_cast<decltype(&GetProcessMitigationPolicy)>(::GetProcAddress(
+ ::GetModuleHandleA("kernel32.dll"), "GetProcessMitigationPolicy"));
+
PROCESS_MITIGATION_USER_SHADOW_STACK_POLICY uss_policy;
- if (!::GetProcessMitigationPolicy(GetCurrentProcess(),
- ProcessUserShadowStackPolicy, &uss_policy,
- sizeof(uss_policy))) {
+ if (!get_process_mitigation_policy(GetCurrentProcess(),
+ ProcessUserShadowStackPolicy, &uss_policy,
+ sizeof(uss_policy))) {
return;
}
@@ -1063,10 +1101,14 @@ TEST(ProcessMitigationsTest, CetAllowDynamicApis) {
// Verify policy is available and set for this process (i.e. CET is
// enabled via IFEO or through the CETCOMPAT bit on the executable).
+ auto get_process_mitigation_policy =
+ reinterpret_cast<decltype(&GetProcessMitigationPolicy)>(::GetProcAddress(
+ ::GetModuleHandleA("kernel32.dll"), "GetProcessMitigationPolicy"));
+
PROCESS_MITIGATION_USER_SHADOW_STACK_POLICY uss_policy;
- if (!::GetProcessMitigationPolicy(GetCurrentProcess(),
- ProcessUserShadowStackPolicy, &uss_policy,
- sizeof(uss_policy))) {
+ if (!get_process_mitigation_policy(GetCurrentProcess(),
+ ProcessUserShadowStackPolicy, &uss_policy,
+ sizeof(uss_policy))) {
return;
}
@@ -1101,10 +1143,14 @@ TEST(ProcessMitigationsTest, CetStrictMode) {
// Verify policy is available and set for this process (i.e. CET is
// enabled via IFEO or through the CETCOMPAT bit on the executable).
+ auto get_process_mitigation_policy =
+ reinterpret_cast<decltype(&GetProcessMitigationPolicy)>(::GetProcAddress(
+ ::GetModuleHandleA("kernel32.dll"), "GetProcessMitigationPolicy"));
+
PROCESS_MITIGATION_USER_SHADOW_STACK_POLICY uss_policy;
- if (!::GetProcessMitigationPolicy(GetCurrentProcess(),
- ProcessUserShadowStackPolicy, &uss_policy,
- sizeof(uss_policy))) {
+ if (!get_process_mitigation_policy(GetCurrentProcess(),
+ ProcessUserShadowStackPolicy, &uss_policy,
+ sizeof(uss_policy))) {
return;
}