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 |
63 WOW64Status GetWOW64StatusForCurrentProcess() { | 67 WOW64Status GetWOW64StatusForCurrentProcess() { |
64 typedef BOOL (WINAPI* IsWow64ProcessFunc)(HANDLE, PBOOL); | 68 typedef BOOL (WINAPI* IsWow64ProcessFunc)(HANDLE, PBOOL); |
65 IsWow64ProcessFunc is_wow64_process = reinterpret_cast<IsWow64ProcessFunc>( | 69 IsWow64ProcessFunc is_wow64_process = reinterpret_cast<IsWow64ProcessFunc>( |
66 GetProcAddress(GetModuleHandle(L"kernel32.dll"), "IsWow64Process")); | 70 GetProcAddress(GetModuleHandle(L"kernel32.dll"), "IsWow64Process")); |
67 if (!is_wow64_process) | 71 if (!is_wow64_process) |
68 return WOW64_DISABLED; | 72 return WOW64_DISABLED; |
69 BOOL is_wow64 = FALSE; | 73 BOOL is_wow64 = FALSE; |
70 if (!(*is_wow64_process)(GetCurrentProcess(), &is_wow64)) | 74 if (!(*is_wow64_process)(GetCurrentProcess(), &is_wow64)) |
71 return WOW64_UNKNOWN; | 75 return WOW64_UNKNOWN; |
72 return is_wow64 ? WOW64_ENABLED : WOW64_DISABLED; | 76 return is_wow64 ? WOW64_ENABLED : WOW64_DISABLED; |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 return (result == ERROR_SUCCESS); | 269 return (result == ERROR_SUCCESS); |
266 } | 270 } |
267 | 271 |
268 int BlacklistSize() { | 272 int BlacklistSize() { |
269 int size = -1; | 273 int size = -1; |
270 while (blacklist::g_troublesome_dlls[++size] != NULL) {} | 274 while (blacklist::g_troublesome_dlls[++size] != NULL) {} |
271 | 275 |
272 return size; | 276 return size; |
273 } | 277 } |
274 | 278 |
| 279 bool IsBlacklistInitialized() { |
| 280 return g_blacklist_initialized; |
| 281 } |
| 282 |
275 bool AddDllToBlacklist(const wchar_t* dll_name) { | 283 bool AddDllToBlacklist(const wchar_t* dll_name) { |
276 int blacklist_size = BlacklistSize(); | 284 int blacklist_size = BlacklistSize(); |
277 // We need to leave one space at the end for the null pointer. | 285 // We need to leave one space at the end for the null pointer. |
278 if (blacklist_size + 1 >= kTroublesomeDllsMaxCount) | 286 if (blacklist_size + 1 >= kTroublesomeDllsMaxCount) |
279 return false; | 287 return false; |
280 for (int i = 0; i < blacklist_size; ++i) { | 288 for (int i = 0; i < blacklist_size; ++i) { |
281 if (!_wcsicmp(g_troublesome_dlls[i], dll_name)) | 289 if (!_wcsicmp(g_troublesome_dlls[i], dll_name)) |
282 return true; | 290 return true; |
283 } | 291 } |
284 | 292 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 thunk = new sandbox::Wow64W8ResolverThunk(current_process, kRelaxed); | 374 thunk = new sandbox::Wow64W8ResolverThunk(current_process, kRelaxed); |
367 else | 375 else |
368 thunk = new sandbox::Wow64ResolverThunk(current_process, kRelaxed); | 376 thunk = new sandbox::Wow64ResolverThunk(current_process, kRelaxed); |
369 } else if (os_info.version() >= VERSION_WIN8) { | 377 } else if (os_info.version() >= VERSION_WIN8) { |
370 thunk = new sandbox::Win8ResolverThunk(current_process, kRelaxed); | 378 thunk = new sandbox::Win8ResolverThunk(current_process, kRelaxed); |
371 } else { | 379 } else { |
372 thunk = new sandbox::ServiceResolverThunk(current_process, kRelaxed); | 380 thunk = new sandbox::ServiceResolverThunk(current_process, kRelaxed); |
373 } | 381 } |
374 #endif | 382 #endif |
375 | 383 |
| 384 // Record that we have initialized the blacklist. |
| 385 g_blacklist_initialized = true; |
| 386 |
376 BYTE* thunk_storage = reinterpret_cast<BYTE*>(&g_thunk_storage); | 387 BYTE* thunk_storage = reinterpret_cast<BYTE*>(&g_thunk_storage); |
377 | 388 |
378 // Mark the thunk storage as readable and writeable, since we | 389 // Mark the thunk storage as readable and writeable, since we |
379 // ready to write to it. | 390 // ready to write to it. |
380 DWORD old_protect = 0; | 391 DWORD old_protect = 0; |
381 if (!VirtualProtect(&g_thunk_storage, | 392 if (!VirtualProtect(&g_thunk_storage, |
382 sizeof(g_thunk_storage), | 393 sizeof(g_thunk_storage), |
383 PAGE_EXECUTE_READWRITE, | 394 PAGE_EXECUTE_READWRITE, |
384 &old_protect)) { | 395 &old_protect)) { |
385 RecordSuccessfulThunkSetup(&key); | 396 RecordSuccessfulThunkSetup(&key); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 sizeof(g_thunk_storage), | 441 sizeof(g_thunk_storage), |
431 PAGE_EXECUTE_READ, | 442 PAGE_EXECUTE_READ, |
432 &old_protect); | 443 &old_protect); |
433 | 444 |
434 RecordSuccessfulThunkSetup(&key); | 445 RecordSuccessfulThunkSetup(&key); |
435 | 446 |
436 return NT_SUCCESS(ret) && page_executable; | 447 return NT_SUCCESS(ret) && page_executable; |
437 } | 448 } |
438 | 449 |
439 } // namespace blacklist | 450 } // namespace blacklist |
OLD | NEW |