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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 return (result == ERROR_SUCCESS); | 240 return (result == ERROR_SUCCESS); |
237 } | 241 } |
238 | 242 |
239 int BlacklistSize() { | 243 int BlacklistSize() { |
240 int size = -1; | 244 int size = -1; |
241 while(blacklist::g_troublesome_dlls[++size] != NULL); | 245 while(blacklist::g_troublesome_dlls[++size] != NULL); |
242 | 246 |
243 return size; | 247 return size; |
244 } | 248 } |
245 | 249 |
| 250 bool IsBlacklistInitialized() { |
| 251 return g_blacklist_initialized; |
| 252 } |
| 253 |
246 bool AddDllToBlacklist(const wchar_t* dll_name) { | 254 bool AddDllToBlacklist(const wchar_t* dll_name) { |
247 int blacklist_size = BlacklistSize(); | 255 int blacklist_size = BlacklistSize(); |
248 // We need to leave one space at the end for the null pointer. | 256 // We need to leave one space at the end for the null pointer. |
249 if (blacklist_size + 1 >= kTroublesomeDllsMaxCount) | 257 if (blacklist_size + 1 >= kTroublesomeDllsMaxCount) |
250 return false; | 258 return false; |
251 for (int i=0; i < blacklist_size; ++i) { | 259 for (int i=0; i < blacklist_size; ++i) { |
252 if (!_wcsicmp(g_troublesome_dlls[i], dll_name)) | 260 if (!_wcsicmp(g_troublesome_dlls[i], dll_name)) |
253 return true; | 261 return true; |
254 } | 262 } |
255 | 263 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 thunk = new sandbox::Wow64W8ResolverThunk(current_process, kRelaxed); | 325 thunk = new sandbox::Wow64W8ResolverThunk(current_process, kRelaxed); |
318 else | 326 else |
319 thunk = new sandbox::Wow64ResolverThunk(current_process, kRelaxed); | 327 thunk = new sandbox::Wow64ResolverThunk(current_process, kRelaxed); |
320 } else if (os_info.version() >= VERSION_WIN8) { | 328 } else if (os_info.version() >= VERSION_WIN8) { |
321 thunk = new sandbox::Win8ResolverThunk(current_process, kRelaxed); | 329 thunk = new sandbox::Win8ResolverThunk(current_process, kRelaxed); |
322 } else { | 330 } else { |
323 thunk = new sandbox::ServiceResolverThunk(current_process, kRelaxed); | 331 thunk = new sandbox::ServiceResolverThunk(current_process, kRelaxed); |
324 } | 332 } |
325 #endif | 333 #endif |
326 | 334 |
| 335 // Record that we have initialized the blacklist. |
| 336 g_blacklist_initialized = true; |
| 337 |
327 BYTE* thunk_storage = reinterpret_cast<BYTE*>(&g_thunk_storage); | 338 BYTE* thunk_storage = reinterpret_cast<BYTE*>(&g_thunk_storage); |
328 | 339 |
329 // Mark the thunk storage as readable and writeable, since we | 340 // Mark the thunk storage as readable and writeable, since we |
330 // ready to write to it. | 341 // ready to write to it. |
331 DWORD old_protect = 0; | 342 DWORD old_protect = 0; |
332 if (!VirtualProtect(&g_thunk_storage, | 343 if (!VirtualProtect(&g_thunk_storage, |
333 sizeof(g_thunk_storage), | 344 sizeof(g_thunk_storage), |
334 PAGE_EXECUTE_READWRITE, | 345 PAGE_EXECUTE_READWRITE, |
335 &old_protect)) | 346 &old_protect)) |
336 return false; | 347 return false; |
(...skipping 15 matching lines...) Expand all Loading... |
352 // Mark the thunk storage as executable and prevent any future writes to it. | 363 // Mark the thunk storage as executable and prevent any future writes to it. |
353 BOOL page_executable = VirtualProtect(&g_thunk_storage, | 364 BOOL page_executable = VirtualProtect(&g_thunk_storage, |
354 sizeof(g_thunk_storage), | 365 sizeof(g_thunk_storage), |
355 PAGE_EXECUTE_READ, | 366 PAGE_EXECUTE_READ, |
356 &old_protect); | 367 &old_protect); |
357 | 368 |
358 return NT_SUCCESS(ret) && page_executable; | 369 return NT_SUCCESS(ret) && page_executable; |
359 } | 370 } |
360 | 371 |
361 } // namespace blacklist | 372 } // namespace blacklist |
OLD | NEW |