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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 return (result == ERROR_SUCCESS); | 263 return (result == ERROR_SUCCESS); |
260 } | 264 } |
261 | 265 |
262 int BlacklistSize() { | 266 int BlacklistSize() { |
263 int size = -1; | 267 int size = -1; |
264 while (blacklist::g_troublesome_dlls[++size] != NULL) {} | 268 while (blacklist::g_troublesome_dlls[++size] != NULL) {} |
265 | 269 |
266 return size; | 270 return size; |
267 } | 271 } |
268 | 272 |
| 273 bool IsBlacklistInitialized() { |
| 274 return g_blacklist_initialized; |
| 275 } |
| 276 |
269 bool AddDllToBlacklist(const wchar_t* dll_name) { | 277 bool AddDllToBlacklist(const wchar_t* dll_name) { |
270 int blacklist_size = BlacklistSize(); | 278 int blacklist_size = BlacklistSize(); |
271 // We need to leave one space at the end for the null pointer. | 279 // We need to leave one space at the end for the null pointer. |
272 if (blacklist_size + 1 >= kTroublesomeDllsMaxCount) | 280 if (blacklist_size + 1 >= kTroublesomeDllsMaxCount) |
273 return false; | 281 return false; |
274 for (int i = 0; i < blacklist_size; ++i) { | 282 for (int i = 0; i < blacklist_size; ++i) { |
275 if (!_wcsicmp(g_troublesome_dlls[i], dll_name)) | 283 if (!_wcsicmp(g_troublesome_dlls[i], dll_name)) |
276 return true; | 284 return true; |
277 } | 285 } |
278 | 286 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 thunk = new sandbox::Wow64W8ResolverThunk(current_process, kRelaxed); | 368 thunk = new sandbox::Wow64W8ResolverThunk(current_process, kRelaxed); |
361 else | 369 else |
362 thunk = new sandbox::Wow64ResolverThunk(current_process, kRelaxed); | 370 thunk = new sandbox::Wow64ResolverThunk(current_process, kRelaxed); |
363 } else if (os_info.version() >= VERSION_WIN8) { | 371 } else if (os_info.version() >= VERSION_WIN8) { |
364 thunk = new sandbox::Win8ResolverThunk(current_process, kRelaxed); | 372 thunk = new sandbox::Win8ResolverThunk(current_process, kRelaxed); |
365 } else { | 373 } else { |
366 thunk = new sandbox::ServiceResolverThunk(current_process, kRelaxed); | 374 thunk = new sandbox::ServiceResolverThunk(current_process, kRelaxed); |
367 } | 375 } |
368 #endif | 376 #endif |
369 | 377 |
| 378 // Record that we have initialized the blacklist. |
| 379 g_blacklist_initialized = true; |
| 380 |
370 BYTE* thunk_storage = reinterpret_cast<BYTE*>(&g_thunk_storage); | 381 BYTE* thunk_storage = reinterpret_cast<BYTE*>(&g_thunk_storage); |
371 | 382 |
372 // Mark the thunk storage as readable and writeable, since we | 383 // Mark the thunk storage as readable and writeable, since we |
373 // ready to write to it. | 384 // ready to write to it. |
374 DWORD old_protect = 0; | 385 DWORD old_protect = 0; |
375 if (!VirtualProtect(&g_thunk_storage, | 386 if (!VirtualProtect(&g_thunk_storage, |
376 sizeof(g_thunk_storage), | 387 sizeof(g_thunk_storage), |
377 PAGE_EXECUTE_READWRITE, | 388 PAGE_EXECUTE_READWRITE, |
378 &old_protect)) { | 389 &old_protect)) { |
379 RecordSuccessfulThunkSetup(&key); | 390 RecordSuccessfulThunkSetup(&key); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 sizeof(g_thunk_storage), | 435 sizeof(g_thunk_storage), |
425 PAGE_EXECUTE_READ, | 436 PAGE_EXECUTE_READ, |
426 &old_protect); | 437 &old_protect); |
427 | 438 |
428 RecordSuccessfulThunkSetup(&key); | 439 RecordSuccessfulThunkSetup(&key); |
429 | 440 |
430 return NT_SUCCESS(ret) && page_executable; | 441 return NT_SUCCESS(ret) && page_executable; |
431 } | 442 } |
432 | 443 |
433 } // namespace blacklist | 444 } // namespace blacklist |
OLD | NEW |