Chromium Code Reviews| 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 <assert.h> | 7 #include <assert.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <vector> | |
| 11 | |
| 10 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 11 #include "chrome_elf/blacklist/blacklist_interceptions.h" | 13 #include "chrome_elf/blacklist/blacklist_interceptions.h" |
| 12 #include "chrome_elf/chrome_elf_constants.h" | 14 #include "chrome_elf/chrome_elf_constants.h" |
| 13 #include "chrome_elf/chrome_elf_util.h" | 15 #include "chrome_elf/chrome_elf_util.h" |
| 14 #include "chrome_elf/thunk_getter.h" | 16 #include "chrome_elf/thunk_getter.h" |
| 15 #include "sandbox/win/src/interception_internal.h" | 17 #include "sandbox/win/src/interception_internal.h" |
| 16 #include "sandbox/win/src/internal_types.h" | 18 #include "sandbox/win/src/internal_types.h" |
| 17 #include "sandbox/win/src/service_resolver.h" | 19 #include "sandbox/win/src/service_resolver.h" |
| 18 | 20 |
| 19 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx | 21 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 335 g_blacklist_initialized = NT_SUCCESS(ret); | 337 g_blacklist_initialized = NT_SUCCESS(ret); |
| 336 | 338 |
| 337 // Mark the thunk storage as executable and prevent any future writes to it. | 339 // Mark the thunk storage as executable and prevent any future writes to it. |
| 338 page_executable = page_executable && VirtualProtect(&g_thunk_storage, | 340 page_executable = page_executable && VirtualProtect(&g_thunk_storage, |
| 339 sizeof(g_thunk_storage), | 341 sizeof(g_thunk_storage), |
| 340 PAGE_EXECUTE_READ, | 342 PAGE_EXECUTE_READ, |
| 341 &old_protect); | 343 &old_protect); |
| 342 | 344 |
| 343 RecordSuccessfulThunkSetup(&key); | 345 RecordSuccessfulThunkSetup(&key); |
| 344 | 346 |
| 347 AddDllsFromRegistryToBlacklist(); | |
| 348 | |
| 345 return NT_SUCCESS(ret) && page_executable; | 349 return NT_SUCCESS(ret) && page_executable; |
| 346 } | 350 } |
| 347 | 351 |
| 352 void AddDllsFromRegistryToBlacklist() { | |
|
csharp
2014/05/29 20:51:52
Should this return a boolean to indicate failure o
krstnmnlsn
2014/05/30 14:09:13
Done.
| |
| 353 HKEY key = NULL; | |
| 354 LONG result = ::RegOpenKeyEx(HKEY_CURRENT_USER, | |
| 355 kRegistryFinchListPath, | |
| 356 0, | |
| 357 KEY_QUERY_VALUE | KEY_SET_VALUE, | |
| 358 &key); | |
| 359 | |
| 360 if (result != ERROR_SUCCESS) | |
| 361 return; | |
| 362 | |
| 363 int num_dlls; | |
| 364 int longest_name; | |
| 365 ::RegQueryInfoKey(key, NULL, NULL, NULL, NULL, NULL, NULL, | |
| 366 reinterpret_cast<DWORD*>(&num_dlls), | |
| 367 reinterpret_cast<DWORD*>(&longest_name), NULL, NULL, NULL); | |
| 368 | |
| 369 // Collect dlls so that we can delete them after the enumeration. | |
| 370 std::vector<wchar_t*> dll_names(num_dlls); | |
| 371 | |
| 372 for (int i = 0; i < num_dlls; ++i) { | |
| 373 DWORD name_len(longest_name + 1); | |
| 374 DWORD value_len; | |
| 375 wchar_t* name_buffer = new wchar_t[name_len]; | |
| 376 result = ::RegEnumValue(key, i, name_buffer, &name_len, NULL, NULL, | |
| 377 NULL, &value_len); | |
| 378 name_len = name_len + 1; | |
| 379 wchar_t* value_buffer = new wchar_t[value_len+1]; | |
| 380 result = ::RegEnumValue(key, i, name_buffer, &name_len, NULL, NULL, | |
| 381 reinterpret_cast<BYTE*>(value_buffer), &value_len); | |
| 382 value_buffer[value_len] = L'\0'; | |
| 383 | |
| 384 if (result == ERROR_SUCCESS) { | |
| 385 AddDllToBlacklist(value_buffer); | |
| 386 } | |
| 387 | |
| 388 dll_names[i] = name_buffer; | |
| 389 | |
| 390 delete[] value_buffer; | |
| 391 } | |
| 392 | |
| 393 for (int i = 0; i < num_dlls; ++i) { | |
| 394 ::RegDeleteValue(key, dll_names[i]); | |
| 395 delete[] dll_names[i]; | |
| 396 } | |
| 397 | |
| 398 ::RegCloseKey(key); | |
| 399 } | |
| 400 | |
| 348 } // namespace blacklist | 401 } // namespace blacklist |
| OLD | NEW |