Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: chrome/browser/chrome_elf_init_win.cc

Issue 174013007: Add UMA stats to record when DLLs are successfully blocked in the Browser. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/bind.h"
6 #include "base/md5.h"
5 #include "base/metrics/field_trial.h" 7 #include "base/metrics/field_trial.h"
6 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/metrics/sparse_histogram.h"
7 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
8 #include "base/win/registry.h" 11 #include "base/win/registry.h"
9 #include "chrome/browser/chrome_elf_init_win.h" 12 #include "chrome/browser/chrome_elf_init_win.h"
10 #include "chrome_elf/blacklist/blacklist.h" 13 #include "chrome_elf/blacklist/blacklist.h"
14 #include "content/public/browser/browser_thread.h"
11 #include "version.h" // NOLINT 15 #include "version.h" // NOLINT
12 16
13 namespace { 17 namespace {
14 18
15 const char kBrowserBlacklistTrialName[] = "BrowserBlacklist"; 19 const char kBrowserBlacklistTrialName[] = "BrowserBlacklist";
16 const char kBrowserBlacklistTrialEnabledGroupName[] = "Enabled"; 20 const char kBrowserBlacklistTrialEnabledGroupName[] = "Enabled";
17 21
18 // This enum is used to define the buckets for an enumerated UMA histogram. 22 // This enum is used to define the buckets for an enumerated UMA histogram.
19 // Hence, 23 // Hence,
20 // (a) existing enumerated constants should never be deleted or reordered, and 24 // (a) existing enumerated constants should never be deleted or reordered, and
(...skipping 29 matching lines...) Expand all
50 54
51 void InitializeChromeElf() { 55 void InitializeChromeElf() {
52 if (base::FieldTrialList::FindFullName(kBrowserBlacklistTrialName) == 56 if (base::FieldTrialList::FindFullName(kBrowserBlacklistTrialName) ==
53 kBrowserBlacklistTrialEnabledGroupName) { 57 kBrowserBlacklistTrialEnabledGroupName) {
54 BrowserBlacklistBeaconSetup(); 58 BrowserBlacklistBeaconSetup();
55 } else { 59 } else {
56 // Disable the blacklist for all future runs by removing the beacon. 60 // Disable the blacklist for all future runs by removing the beacon.
57 base::win::RegKey blacklist_registry_key(HKEY_CURRENT_USER); 61 base::win::RegKey blacklist_registry_key(HKEY_CURRENT_USER);
58 blacklist_registry_key.DeleteKey(blacklist::kRegistryBeaconPath); 62 blacklist_registry_key.DeleteKey(blacklist::kRegistryBeaconPath);
59 } 63 }
64
65 // Report all successful blacklist interception.
robertshield 2014/02/24 15:24:05 interceptions
csharp 2014/02/24 21:37:16 Done.
66 ReportSuccessfulBlocks();
67
68 // Schedule another task to report all sucessfully interceptions later.
robertshield 2014/02/24 15:24:05 successful
csharp 2014/02/24 21:37:16 Done.
69 // This timne delay should be long enough to catch any dlls that attempt to
robertshield 2014/02/24 15:24:05 time
csharp 2014/02/24 21:37:16 Done.
70 // inject after Chrome has started up.
71 content::BrowserThread::PostDelayedTask(content::BrowserThread::UI,
72 FROM_HERE,
73 base::Bind(&ReportSuccessfulBlocks),
74 base::TimeDelta::FromSeconds(600));
robertshield 2014/02/24 15:24:05 Make the 600 a constant declared at the top with t
csharp 2014/02/24 21:37:16 Done.
60 } 75 }
61 76
62 void BrowserBlacklistBeaconSetup() { 77 void BrowserBlacklistBeaconSetup() {
63 base::win::RegKey blacklist_registry_key(HKEY_CURRENT_USER, 78 base::win::RegKey blacklist_registry_key(HKEY_CURRENT_USER,
64 blacklist::kRegistryBeaconPath, 79 blacklist::kRegistryBeaconPath,
65 KEY_QUERY_VALUE | KEY_SET_VALUE); 80 KEY_QUERY_VALUE | KEY_SET_VALUE);
66 81
67 // Find the last recorded blacklist version. 82 // Find the last recorded blacklist version.
68 base::string16 blacklist_version; 83 base::string16 blacklist_version;
69 blacklist_registry_key.ReadValue(blacklist::kBeaconVersion, 84 blacklist_registry_key.ReadValue(blacklist::kBeaconVersion,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 127
113 // Since some part of the blacklist failed, ensure it is now disabled 128 // Since some part of the blacklist failed, ensure it is now disabled
114 // for this version. 129 // for this version.
115 if (blacklist_state != blacklist::BLACKLIST_DISABLED) { 130 if (blacklist_state != blacklist::BLACKLIST_DISABLED) {
116 blacklist_registry_key.WriteValue(blacklist::kBeaconState, 131 blacklist_registry_key.WriteValue(blacklist::kBeaconState,
117 blacklist::BLACKLIST_DISABLED); 132 blacklist::BLACKLIST_DISABLED);
118 } 133 }
119 } 134 }
120 } 135 }
121 } 136 }
137
138 void ReportSuccessfulBlocks() {
139 typedef void(*SuccessfullyBlocked)(const wchar_t**, int*);
robertshield 2014/02/24 15:24:05 s/SuccessfullyBlocked/SuccessfullyBlockedPtr/
csharp 2014/02/24 21:37:16 Done.
140 SuccessfullyBlocked successfully_blocked =
141 reinterpret_cast<SuccessfullyBlocked>(
142 GetProcAddress(GetModuleHandle(L"chrome_elf.dll"),
143 "SuccessfullyBlocked"));
robertshield 2014/02/24 15:24:05 line this up either with a four space indent or wi
csharp 2014/02/24 21:37:16 Done.
144
145 if (!successfully_blocked)
146 return;
147
148 // Figure out how many dlls were blocked.
149 int num_blocked_dlls;
robertshield 2014/02/24 15:24:05 = 0
csharp 2014/02/24 21:37:16 Done.
150 successfully_blocked(NULL, &num_blocked_dlls);
151
152 // Now retrieve the list of blocked dlls.
153 std::vector<const wchar_t *> blocked_dlls(num_blocked_dlls);
robertshield 2014/02/24 15:24:05 wchar_t* (no space)
csharp 2014/02/24 21:37:16 Done.
154 successfully_blocked(&(blocked_dlls[0]), &num_blocked_dlls);
robertshield 2014/02/24 15:24:05 don't need the parens: &blocked_dlls[0]
csharp 2014/02/24 21:37:16 Done.
155
156 // Send up the hashes of the blocked dlls via UMA.
157 for (size_t i = 0; i < blocked_dlls.size(); ++i) {
158 base::MD5Digest hash;
csharp 2014/02/20 19:48:37 This hashing approach seems pretty silly, but I co
159 base::MD5Sum(blocked_dlls[i], wcslen(blocked_dlls[i]), &hash);
160
161 // Convert the md5 hash to an integer. Strip off the signed bit because
162 // UMA doesn't support negative values, but takes a signed int as input.
163 uint32 uma_hash = static_cast<int>(hash.a[0] +
164 (hash.a[1] << 8) +
165 (hash.a[2] << 12) +
166 ((hash.a[3] * 0x7f) << 16));
167
168 UMA_HISTOGRAM_SPARSE_SLOWLY("Blacklist.Blocked", uma_hash);
169 }
170 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698