OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome_elf/blacklist/blacklist.h" | 5 #include "chrome_elf/blacklist/blacklist.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "chrome_elf/blacklist/blacklist_interceptions.h" | 10 #include "chrome_elf/blacklist/blacklist_interceptions.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 // processes to run on 64-bit versions of Windows). This will return | 53 // processes to run on 64-bit versions of Windows). This will return |
54 // WOW64_DISABLED for both "32-bit Chrome on 32-bit Windows" and "64-bit | 54 // WOW64_DISABLED for both "32-bit Chrome on 32-bit Windows" and "64-bit |
55 // Chrome on 64-bit Windows". WOW64_UNKNOWN means "an error occurred", e.g. | 55 // Chrome on 64-bit Windows". WOW64_UNKNOWN means "an error occurred", e.g. |
56 // the process does not have sufficient access rights to determine this. | 56 // the process does not have sufficient access rights to determine this. |
57 enum WOW64Status { | 57 enum WOW64Status { |
58 WOW64_DISABLED, | 58 WOW64_DISABLED, |
59 WOW64_ENABLED, | 59 WOW64_ENABLED, |
60 WOW64_UNKNOWN, | 60 WOW64_UNKNOWN, |
61 }; | 61 }; |
62 | 62 |
63 // Record if the blacklist was successfully initialized so processes can easily | |
64 // determine if the blacklist is enabled for them. | |
65 bool g_blacklist_initialized = false; | |
66 | |
67 WOW64Status GetWOW64StatusForCurrentProcess() { | 63 WOW64Status GetWOW64StatusForCurrentProcess() { |
68 typedef BOOL (WINAPI* IsWow64ProcessFunc)(HANDLE, PBOOL); | 64 typedef BOOL (WINAPI* IsWow64ProcessFunc)(HANDLE, PBOOL); |
69 IsWow64ProcessFunc is_wow64_process = reinterpret_cast<IsWow64ProcessFunc>( | 65 IsWow64ProcessFunc is_wow64_process = reinterpret_cast<IsWow64ProcessFunc>( |
70 GetProcAddress(GetModuleHandle(L"kernel32.dll"), "IsWow64Process")); | 66 GetProcAddress(GetModuleHandle(L"kernel32.dll"), "IsWow64Process")); |
71 if (!is_wow64_process) | 67 if (!is_wow64_process) |
72 return WOW64_DISABLED; | 68 return WOW64_DISABLED; |
73 BOOL is_wow64 = FALSE; | 69 BOOL is_wow64 = FALSE; |
74 if (!(*is_wow64_process)(GetCurrentProcess(), &is_wow64)) | 70 if (!(*is_wow64_process)(GetCurrentProcess(), &is_wow64)) |
75 return WOW64_UNKNOWN; | 71 return WOW64_UNKNOWN; |
76 return is_wow64 ? WOW64_ENABLED : WOW64_DISABLED; | 72 return is_wow64 ? WOW64_ENABLED : WOW64_DISABLED; |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 return (result == ERROR_SUCCESS); | 265 return (result == ERROR_SUCCESS); |
270 } | 266 } |
271 | 267 |
272 int BlacklistSize() { | 268 int BlacklistSize() { |
273 int size = -1; | 269 int size = -1; |
274 while (blacklist::g_troublesome_dlls[++size] != NULL) {} | 270 while (blacklist::g_troublesome_dlls[++size] != NULL) {} |
275 | 271 |
276 return size; | 272 return size; |
277 } | 273 } |
278 | 274 |
279 bool IsBlacklistInitialized() { | |
280 return g_blacklist_initialized; | |
281 } | |
282 | |
283 bool AddDllToBlacklist(const wchar_t* dll_name) { | 275 bool AddDllToBlacklist(const wchar_t* dll_name) { |
284 int blacklist_size = BlacklistSize(); | 276 int blacklist_size = BlacklistSize(); |
285 // We need to leave one space at the end for the null pointer. | 277 // We need to leave one space at the end for the null pointer. |
286 if (blacklist_size + 1 >= kTroublesomeDllsMaxCount) | 278 if (blacklist_size + 1 >= kTroublesomeDllsMaxCount) |
287 return false; | 279 return false; |
288 for (int i = 0; i < blacklist_size; ++i) { | 280 for (int i = 0; i < blacklist_size; ++i) { |
289 if (!_wcsicmp(g_troublesome_dlls[i], dll_name)) | 281 if (!_wcsicmp(g_troublesome_dlls[i], dll_name)) |
290 return true; | 282 return true; |
291 } | 283 } |
292 | 284 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 thunk = new sandbox::Wow64W8ResolverThunk(current_process, kRelaxed); | 366 thunk = new sandbox::Wow64W8ResolverThunk(current_process, kRelaxed); |
375 else | 367 else |
376 thunk = new sandbox::Wow64ResolverThunk(current_process, kRelaxed); | 368 thunk = new sandbox::Wow64ResolverThunk(current_process, kRelaxed); |
377 } else if (os_info.version() >= VERSION_WIN8) { | 369 } else if (os_info.version() >= VERSION_WIN8) { |
378 thunk = new sandbox::Win8ResolverThunk(current_process, kRelaxed); | 370 thunk = new sandbox::Win8ResolverThunk(current_process, kRelaxed); |
379 } else { | 371 } else { |
380 thunk = new sandbox::ServiceResolverThunk(current_process, kRelaxed); | 372 thunk = new sandbox::ServiceResolverThunk(current_process, kRelaxed); |
381 } | 373 } |
382 #endif | 374 #endif |
383 | 375 |
384 // Record that we have initialized the blacklist. | |
385 g_blacklist_initialized = true; | |
386 | |
387 BYTE* thunk_storage = reinterpret_cast<BYTE*>(&g_thunk_storage); | 376 BYTE* thunk_storage = reinterpret_cast<BYTE*>(&g_thunk_storage); |
388 | 377 |
389 // Mark the thunk storage as readable and writeable, since we | 378 // Mark the thunk storage as readable and writeable, since we |
390 // ready to write to it. | 379 // ready to write to it. |
391 DWORD old_protect = 0; | 380 DWORD old_protect = 0; |
392 if (!VirtualProtect(&g_thunk_storage, | 381 if (!VirtualProtect(&g_thunk_storage, |
393 sizeof(g_thunk_storage), | 382 sizeof(g_thunk_storage), |
394 PAGE_EXECUTE_READWRITE, | 383 PAGE_EXECUTE_READWRITE, |
395 &old_protect)) { | 384 &old_protect)) { |
396 RecordSuccessfulThunkSetup(&key); | 385 RecordSuccessfulThunkSetup(&key); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 sizeof(g_thunk_storage), | 430 sizeof(g_thunk_storage), |
442 PAGE_EXECUTE_READ, | 431 PAGE_EXECUTE_READ, |
443 &old_protect); | 432 &old_protect); |
444 | 433 |
445 RecordSuccessfulThunkSetup(&key); | 434 RecordSuccessfulThunkSetup(&key); |
446 | 435 |
447 return NT_SUCCESS(ret) && page_executable; | 436 return NT_SUCCESS(ret) && page_executable; |
448 } | 437 } |
449 | 438 |
450 } // namespace blacklist | 439 } // namespace blacklist |
OLD | NEW |