forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tracing] Sanitize process memory dump names for background mode
For background mode: 1. ProcessMemoryDump knows the level of detail. 2. It checks for dump name to be present in whitelist. If not then returns a dummy mad. The strings are stripped of numbers (ids) and checked against a whitelist of dump names. 3. Disable creating new dumps just to mark suballocations. 4. Disable creation of global allocator dumps. 5. Disable string attributes in allocator dumps. Also creates a new whitelist file to handle whitelisting logic. BUG=613198 TBR=shess@chromium.org, jochen@chromium.org Review-Url: https://codereview.chromium.org/2006943003 Cr-Commit-Position: refs/heads/master@{#397918}
- Loading branch information
1 parent
40451c5
commit 448e5ed
Showing
26 changed files
with
303 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright 2016 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "base/trace_event/memory_infra_background_whitelist.h" | ||
|
||
#include <ctype.h> | ||
#include <string.h> | ||
|
||
#include <string> | ||
|
||
namespace base { | ||
namespace trace_event { | ||
namespace { | ||
|
||
// The names of dump providers whitelisted for background tracing. Dump | ||
// providers can be added here only if the background mode dump has very | ||
// less performance and memory overhead. | ||
const char* const kDumpProviderWhitelist[] = { | ||
// TODO(ssid): Fill this list with dump provider names which support | ||
// background mode, crbug.com/613198. | ||
nullptr // End of list marker. | ||
}; | ||
|
||
// A list of string names that are allowed for the memory allocator dumps in | ||
// background mode. | ||
const char* const kAllocatorDumpNameWhitelist[] = { | ||
// TODO(ssid): Fill this list with dump names, crbug.com/613198. | ||
nullptr // End of list marker. | ||
}; | ||
|
||
const char* const* g_dump_provider_whitelist = kDumpProviderWhitelist; | ||
const char* const* g_allocator_dump_name_whitelist = | ||
kAllocatorDumpNameWhitelist; | ||
|
||
} // namespace | ||
|
||
bool IsMemoryDumpProviderWhitelisted(const char* mdp_name) { | ||
for (size_t i = 0; g_dump_provider_whitelist[i] != nullptr; ++i) { | ||
if (strcmp(mdp_name, g_dump_provider_whitelist[i]) == 0) | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
bool IsMemoryAllocatorDumpNameWhitelisted(const std::string& name) { | ||
// Remove special characters, numbers (including hexadecimal which are marked | ||
// by '0x') from the given string. | ||
const size_t length = name.size(); | ||
std::string stripped_str; | ||
stripped_str.reserve(length); | ||
bool parsing_hex = false; | ||
for (size_t i = 0; i < length; ++i) { | ||
if (parsing_hex) { | ||
if (isxdigit(name[i])) { | ||
continue; | ||
} else { | ||
parsing_hex = false; | ||
} | ||
} | ||
if (i + 1 < length && name[i] == '0' && name[i + 1] == 'x') { | ||
parsing_hex = true; | ||
++i; | ||
} else if (isalpha(name[i]) || | ||
(name[i] == '/' && stripped_str.back() != '/')) { | ||
// Do not add successive '/'(s) in |stripped_str|. | ||
stripped_str.push_back(name[i]); | ||
} | ||
} | ||
|
||
for (size_t i = 0; g_allocator_dump_name_whitelist[i] != nullptr; ++i) { | ||
if (stripped_str == g_allocator_dump_name_whitelist[i]) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
void SetDumpProviderWhitelistForTesting(const char* const* list) { | ||
g_dump_provider_whitelist = list; | ||
} | ||
|
||
void SetAllocatorDumpNameWhitelistForTesting(const char* const* list) { | ||
g_allocator_dump_name_whitelist = list; | ||
} | ||
|
||
} // namespace trace_event | ||
} // namespace base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2016 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef BASE_TRACE_EVENT_MEMORY_INFRA_BACKGROUND_WHITELIST_H_ | ||
#define BASE_TRACE_EVENT_MEMORY_INFRA_BACKGROUND_WHITELIST_H_ | ||
|
||
// This file contains the whitelists for background mode to limit the tracing | ||
// overhead and remove sensitive information from traces. | ||
|
||
#include <string> | ||
|
||
#include "base/base_export.h" | ||
|
||
namespace base { | ||
namespace trace_event { | ||
|
||
// Checks if the given |mdp_name| is in the whitelist. | ||
bool BASE_EXPORT IsMemoryDumpProviderWhitelisted(const char* mdp_name); | ||
|
||
// Checks if the given |name| matches any of the whitelisted patterns. | ||
bool BASE_EXPORT IsMemoryAllocatorDumpNameWhitelisted(const std::string& name); | ||
|
||
// The whitelist is replaced with the given list for tests. The last element of | ||
// the list must be nullptr. | ||
void BASE_EXPORT SetDumpProviderWhitelistForTesting(const char* const* list); | ||
void BASE_EXPORT | ||
SetAllocatorDumpNameWhitelistForTesting(const char* const* list); | ||
|
||
} // namespace trace_event | ||
} // namespace base | ||
|
||
#endif // BASE_TRACE_EVENT_MEMORY_INFRA_BACKGROUND_WHITELIST_H_ |
Oops, something went wrong.