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 10 matching lines...) Expand all Loading... | |
21 | 21 |
22 const wchar_t* g_troublesome_dlls[kTroublesomeDllsMaxCount] = { | 22 const wchar_t* g_troublesome_dlls[kTroublesomeDllsMaxCount] = { |
23 L"datamngr.dll", // Unknown (suspected adware). | 23 L"datamngr.dll", // Unknown (suspected adware). |
24 L"hk.dll", // Unknown (keystroke logger). | 24 L"hk.dll", // Unknown (keystroke logger). |
25 L"libsvn_tsvn32.dll", // TortoiseSVN. | 25 L"libsvn_tsvn32.dll", // TortoiseSVN. |
26 L"lmrn.dll", // Unknown. | 26 L"lmrn.dll", // Unknown. |
27 // Keep this null pointer here to mark the end of the list. | 27 // Keep this null pointer here to mark the end of the list. |
28 NULL, | 28 NULL, |
29 }; | 29 }; |
30 | 30 |
31 bool g_blocked_dlls[kTroublesomeDllsMaxCount] = { false }; | |
32 int g_num_blocked_dlls = 0; | |
33 | |
31 const wchar_t kRegistryBeaconPath[] = L"SOFTWARE\\Google\\Chrome\\BLBeacon"; | 34 const wchar_t kRegistryBeaconPath[] = L"SOFTWARE\\Google\\Chrome\\BLBeacon"; |
32 const wchar_t kBeaconVersion[] = L"version"; | 35 const wchar_t kBeaconVersion[] = L"version"; |
33 const wchar_t kBeaconState[] = L"state"; | 36 const wchar_t kBeaconState[] = L"state"; |
34 | 37 |
35 } // namespace blacklist | 38 } // namespace blacklist |
36 | 39 |
37 // Allocate storage for thunks in a page of this module to save on doing | 40 // Allocate storage for thunks in a page of this module to save on doing |
38 // an extra allocation at run time. | 41 // an extra allocation at run time. |
39 #pragma section(".crthunk",read,execute) | 42 #pragma section(".crthunk",read,execute) |
40 __declspec(allocate(".crthunk")) sandbox::ThunkData g_thunk_storage; | 43 __declspec(allocate(".crthunk")) sandbox::ThunkData g_thunk_storage; |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 for (int i = 0; i < blacklist_size; ++i) { | 294 for (int i = 0; i < blacklist_size; ++i) { |
292 if (!_wcsicmp(g_troublesome_dlls[i], dll_name)) | 295 if (!_wcsicmp(g_troublesome_dlls[i], dll_name)) |
293 return true; | 296 return true; |
294 } | 297 } |
295 | 298 |
296 // Copy string to blacklist. | 299 // Copy string to blacklist. |
297 wchar_t* str_buffer = new wchar_t[wcslen(dll_name) + 1]; | 300 wchar_t* str_buffer = new wchar_t[wcslen(dll_name) + 1]; |
298 wcscpy(str_buffer, dll_name); | 301 wcscpy(str_buffer, dll_name); |
299 | 302 |
300 g_troublesome_dlls[blacklist_size] = str_buffer; | 303 g_troublesome_dlls[blacklist_size] = str_buffer; |
304 g_blocked_dlls[blacklist_size] = false; | |
301 return true; | 305 return true; |
302 } | 306 } |
303 | 307 |
304 bool RemoveDllFromBlacklist(const wchar_t* dll_name) { | 308 bool RemoveDllFromBlacklist(const wchar_t* dll_name) { |
305 int blacklist_size = BlacklistSize(); | 309 int blacklist_size = BlacklistSize(); |
306 for (int i = 0; i < blacklist_size; ++i) { | 310 for (int i = 0; i < blacklist_size; ++i) { |
307 if (!_wcsicmp(g_troublesome_dlls[i], dll_name)) { | 311 if (!_wcsicmp(g_troublesome_dlls[i], dll_name)) { |
308 // Found the thing to remove. Delete it then replace it with the last | 312 // Found the thing to remove. Delete it then replace it with the last |
309 // element. | 313 // element. |
310 delete[] g_troublesome_dlls[i]; | 314 delete[] g_troublesome_dlls[i]; |
311 g_troublesome_dlls[i] = g_troublesome_dlls[blacklist_size - 1]; | 315 g_troublesome_dlls[i] = g_troublesome_dlls[blacklist_size - 1]; |
312 g_troublesome_dlls[blacklist_size - 1] = NULL; | 316 g_troublesome_dlls[blacklist_size - 1] = NULL; |
317 | |
318 // Also update the stats recording if we have blocked this dll or not. | |
319 if (g_blocked_dlls[i]) | |
320 --g_num_blocked_dlls; | |
321 g_blocked_dlls[i] = g_blocked_dlls[blacklist_size - 1]; | |
313 return true; | 322 return true; |
314 } | 323 } |
315 } | 324 } |
316 return false; | 325 return false; |
317 } | 326 } |
318 | 327 |
328 // TODO(csharp): Maybe store these values in the registry so we can | |
329 // still report them if Chrome crashes early. | |
330 void SuccessfullyBlocked(const wchar_t** blocked_dlls, int* size) { | |
robertshield
2014/02/24 15:24:05
null check the inputs
csharp
2014/02/24 21:37:16
Done.
| |
331 // If the array isn't big enough, just report the size it needs to be and | |
332 // return. | |
333 if (*size < g_num_blocked_dlls) { | |
334 *size = g_num_blocked_dlls; | |
335 return; | |
336 } | |
337 | |
338 int strings_to_fill = 0; | |
339 for (int i = 0; strings_to_fill != g_num_blocked_dlls; ++i) { | |
robertshield
2014/02/24 15:24:05
be paranoid: also bounds check the index |i| again
csharp
2014/02/24 21:37:16
Done.
| |
340 if (g_blocked_dlls[i]) { | |
341 blocked_dlls[strings_to_fill] = g_troublesome_dlls[i]; | |
342 ++strings_to_fill; | |
343 } | |
344 } | |
345 } | |
346 | |
347 void BlockedDll(int blocked_index) { | |
348 if (!g_blocked_dlls[blocked_index]) { | |
349 ++g_num_blocked_dlls; | |
350 g_blocked_dlls[blocked_index] = true; | |
351 } | |
352 } | |
353 | |
319 bool Initialize(bool force) { | 354 bool Initialize(bool force) { |
320 // Check to see that we found the functions we need in ntdll. | 355 // Check to see that we found the functions we need in ntdll. |
321 if (!InitializeInterceptImports()) | 356 if (!InitializeInterceptImports()) |
322 return false; | 357 return false; |
323 | 358 |
324 // Check to see if this is a non-browser process, abort if so. | 359 // Check to see if this is a non-browser process, abort if so. |
325 if (IsNonBrowserProcess()) | 360 if (IsNonBrowserProcess()) |
326 return false; | 361 return false; |
327 | 362 |
328 // Check to see if a beacon is present, abort if so. | 363 // Check to see if a beacon is present, abort if so. |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
444 sizeof(g_thunk_storage), | 479 sizeof(g_thunk_storage), |
445 PAGE_EXECUTE_READ, | 480 PAGE_EXECUTE_READ, |
446 &old_protect); | 481 &old_protect); |
447 | 482 |
448 RecordSuccessfulThunkSetup(&key); | 483 RecordSuccessfulThunkSetup(&key); |
449 | 484 |
450 return NT_SUCCESS(ret) && page_executable; | 485 return NT_SUCCESS(ret) && page_executable; |
451 } | 486 } |
452 | 487 |
453 } // namespace blacklist | 488 } // namespace blacklist |
OLD | NEW |