Skip to content

Commit

Permalink
Add export to query for blacklisted-ness.
Browse files Browse the repository at this point in the history
BUG=394532
TEST=unit_tests

Review URL: https://codereview.chromium.org/444543002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287899 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
robertshield@chromium.org committed Aug 6, 2014
1 parent 00a9b94 commit 83b651b
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 0 deletions.
34 changes: 34 additions & 0 deletions chrome/browser/chrome_elf_init_unittest_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
#include "chrome/browser/chrome_elf_init_win.h"

#include "base/basictypes.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "base/metrics/field_trial.h"
#include "base/path_service.h"
#include "base/scoped_native_library.h"
#include "base/strings/string16.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/test_reg_util_win.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome_elf/blacklist/blacklist.h"
#include "chrome_elf/chrome_elf_constants.h"
#include "components/variations/entropy_provider.h"
#include "components/variations/variations_associated_data.h"
Expand All @@ -21,6 +25,7 @@
namespace {

const char kBrowserBlacklistTrialEnabledGroupName[] = "Enabled";
const wchar_t kTestDllName[] = L"blacklist_test_dll_1.dll";

class ChromeBlacklistTrialTest : public testing::Test {
protected:
Expand Down Expand Up @@ -195,4 +200,33 @@ TEST_F(ChromeBlacklistTrialTest, AddFinchBlacklistToRegistry) {
}
}

TEST_F(ChromeBlacklistTrialTest, TestBlacklistBypass) {
base::FilePath current_dir;
ASSERT_TRUE(PathService::Get(base::DIR_EXE, &current_dir));

// Load test dll.
base::ScopedNativeLibrary dll1(current_dir.Append(kTestDllName));

// No blacklisted dll should be found.
std::vector<base::string16> module_names;
EXPECT_TRUE(GetLoadedBlacklistedModules(&module_names));
EXPECT_TRUE(module_names.empty());
// For posterity, print any that are.
std::vector<base::string16>::const_iterator module_iter(module_names.begin());
for (; module_iter != module_names.end(); ++module_iter) {
LOG(ERROR) << "Found blacklisted module: " << *module_iter;
}

// Add test dll to blacklist
blacklist::AddDllToBlacklist(kTestDllName);

// Check that the test dll appears in list.
module_names.clear();
EXPECT_TRUE(GetLoadedBlacklistedModules(&module_names));
ASSERT_EQ(1, module_names.size());
EXPECT_STREQ(kTestDllName,
StringToLowerASCII(
base::FilePath(module_names[0]).BaseName().value()).c_str());
}

} // namespace
23 changes: 23 additions & 0 deletions chrome/browser/chrome_elf_init_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
// found in the LICENSE file.

#include "base/bind.h"
#include "base/files/file_path.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram.h"
#include "base/metrics/sparse_histogram.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/win/registry.h"
#include "chrome/browser/chrome_elf_init_win.h"
#include "chrome/browser/install_verification/win/module_info.h"
#include "chrome/browser/install_verification/win/module_verification_common.h"
#include "chrome_elf/blacklist/blacklist.h"
#include "chrome_elf/chrome_elf_constants.h"
#include "chrome_elf/dll_hash/dll_hash.h"
Expand Down Expand Up @@ -204,3 +208,22 @@ void BrowserBlacklistBeaconSetup() {
RecordBlacklistSetupEvent(BLACKLIST_SETUP_ENABLED);
}
}

bool GetLoadedBlacklistedModules(std::vector<base::string16>* module_names) {
DCHECK(module_names);

std::set<ModuleInfo> module_info_set;
if (!GetLoadedModules(&module_info_set))
return false;

std::set<ModuleInfo>::const_iterator module_iter(module_info_set.begin());
for (; module_iter != module_info_set.end(); ++module_iter) {
base::string16 module_file_name(StringToLowerASCII(
base::FilePath(module_iter->name).BaseName().value()));
if (blacklist::GetBlacklistIndex(module_file_name.c_str()) != -1) {
module_names->push_back(module_iter->name);
}
}

return true;
}
8 changes: 8 additions & 0 deletions chrome/browser/chrome_elf_init_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#ifndef CHROME_BROWSER_CHROME_ELF_INIT_WIN_H_
#define CHROME_BROWSER_CHROME_ELF_INIT_WIN_H_

#include <vector>

#include "base/strings/string16.h"

// Field trial name and full name for the blacklist disabled group.
extern const char kBrowserBlacklistTrialName[];
extern const char kBrowserBlacklistTrialDisabledGroupName[];
Expand All @@ -19,4 +23,8 @@ void AddFinchBlacklistToRegistry();
// Set the required state for an enabled browser blacklist.
void BrowserBlacklistBeaconSetup();

// Retrieves the set of blacklisted modules that are loaded in the process.
// Returns true if successful, false otherwise.
bool GetLoadedBlacklistedModules(std::vector<base::string16>* module_names);

#endif // CHROME_BROWSER_CHROME_ELF_INIT_WIN_H_
1 change: 1 addition & 0 deletions chrome/chrome_tests_unit.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -2458,6 +2458,7 @@
'dependencies': [
'chrome_version_resources',
'installer_util_strings',
'../chrome_elf/chrome_elf.gyp:blacklist_test_dll_1',
'../third_party/iaccessible2/iaccessible2.gyp:iaccessible2',
'../third_party/isimpledom/isimpledom.gyp:isimpledom',
],
Expand Down
1 change: 1 addition & 0 deletions chrome/unit_tests.isolate
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
['OS=="win"', {
'variables': {
'isolate_dependency_tracked': [
'<(PRODUCT_DIR)/blacklist_test_dll_1.dll',
'<(PRODUCT_DIR)/chrome_elf.dll',
'<(PRODUCT_DIR)/ffmpegsumo.dll',
'<(PRODUCT_DIR)/libexif.dll',
Expand Down
8 changes: 8 additions & 0 deletions chrome_elf/blacklist/blacklist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,14 @@ bool IsBlacklistInitialized() {
return g_blacklist_initialized;
}

int GetBlacklistIndex(const wchar_t* dll_name) {
for (int i = 0; i < kTroublesomeDllsMaxCount, g_troublesome_dlls[i]; ++i) {
if (_wcsicmp(dll_name, g_troublesome_dlls[i]) == 0)
return i;
}
return -1;
}

bool AddDllToBlacklist(const wchar_t* dll_name) {
int blacklist_size = BlacklistSize();
// We need to leave one space at the end for the null pointer.
Expand Down
4 changes: 4 additions & 0 deletions chrome_elf/blacklist/blacklist.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ int BlacklistSize();
// Returns if true if the blacklist has been initialized.
extern "C" bool IsBlacklistInitialized();

// Returns the index of the DLL named |dll_name| on the blacklist, or -1 if not
// found.
extern "C" int GetBlacklistIndex(const wchar_t* dll_name);

// Adds the given dll name to the blacklist. Returns true if the dll name is in
// the blacklist when this returns, false on error. Note that this will copy
// |dll_name| and will leak it on exit if the string is not subsequently removed
Expand Down
2 changes: 2 additions & 0 deletions chrome_elf/chrome_elf.def
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ EXPORTS
IsBlacklistInitialized
SignalChromeElf
SuccessfullyBlocked
GetBlacklistIndex
AddDllToBlacklist

0 comments on commit 83b651b

Please sign in to comment.