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 bool AddDllsFromRegistryToBlacklist() { | |
| 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 false; | |
| 362 | |
| 363 // We add dlls from the registry to the blacklist, and then clear registry | |
| 364 // in the next loop. | |
| 365 std::vector<std::wstring> dll_names; | |
| 366 for (int i = 0; result == ERROR_SUCCESS; ++i) { | |
| 367 DWORD name_len = MAX_PATH; | |
| 368 DWORD value_len = 0; | |
| 369 assert(name_len > 0); | |
|
csharp
2014/06/03 21:11:36
This assert doesn't seem to useful, so you can pro
krstnmnlsn
2014/06/04 16:55:44
Done.
| |
| 370 std::vector<wchar_t> name_buffer(name_len); | |
|
csharp
2014/06/03 21:11:36
Since you are always initializing it to the same s
krstnmnlsn
2014/06/04 16:55:44
Done.
| |
| 371 result = ::RegEnumValue( | |
| 372 key, i, &name_buffer[0], &name_len, NULL, NULL, NULL, &value_len); | |
| 373 name_len = name_len + 1; | |
| 374 value_len = value_len + 1; | |
| 375 assert(value_len > 0); | |
|
csharp
2014/06/03 21:11:36
I'm not sure if this assert is useful, I don't thi
krstnmnlsn
2014/06/04 16:55:44
Yeah the only case I could think of involved someo
| |
| 376 std::vector<wchar_t> value_buffer(value_len); | |
| 377 result = ::RegEnumValue(key, i, &name_buffer[0], &name_len, NULL, NULL, | |
| 378 reinterpret_cast<BYTE*>(&value_buffer[0]), | |
| 379 &value_len); | |
| 380 value_buffer[value_len-1] = L'\0'; | |
| 381 | |
| 382 if (result == ERROR_SUCCESS) { | |
| 383 AddDllToBlacklist(&value_buffer[0]); | |
| 384 dll_names.push_back(std::wstring(name_buffer.begin(), name_buffer.end())); | |
| 385 } | |
| 386 } | |
| 387 | |
| 388 for (size_t i = 0; i < dll_names.size(); ++i) { | |
|
csharp
2014/06/03 21:11:36
Can RegDeleteKey replace this loop?
krstnmnlsn
2014/06/04 16:55:44
It seems to work yes :)
| |
| 389 ::RegDeleteValue(key, dll_names[i].c_str()); | |
| 390 } | |
| 391 | |
| 392 ::RegCloseKey(key); | |
| 393 return true; | |
| 394 } | |
| 395 | |
| 348 } // namespace blacklist | 396 } // namespace blacklist |
| OLD | NEW |