Commit b9e7f15e authored by Siddhartha S's avatar Siddhartha S Committed by Commit Bot

Add auto generated file for privacy filtering

Internal script will generate the proto structure based on
whitelisted fields.

BUG=925148

Change-Id: I24d136031fd0bb5441272d6e90efff90181decc6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1600718Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avataroysteine <oysteine@chromium.org>
Commit-Queue: ssid <ssid@chromium.org>
Cr-Commit-Position: refs/heads/master@{#658320}
parent 0656577c
...@@ -91,18 +91,11 @@ PerfettoFileTracer::PerfettoFileTracer() ...@@ -91,18 +91,11 @@ PerfettoFileTracer::PerfettoFileTracer()
const auto& chrome_config = const auto& chrome_config =
tracing::TraceStartupConfig::GetInstance()->GetTraceConfig(); tracing::TraceStartupConfig::GetInstance()->GetTraceConfig();
// The output is always proto based. So, enable privacy filtering if argument
// filter is enabled.
bool privacy_filtering = chrome_config.IsArgumentFilterEnabled();
perfetto::TraceConfig trace_config = perfetto::TraceConfig trace_config =
tracing::GetDefaultPerfettoConfig(chrome_config); tracing::GetDefaultPerfettoConfig(chrome_config, privacy_filtering);
// TODO(ssid): This should be moved to GetDefaultPerfettoConfig(). But,
// currently we only require this for proto output since JSON exporter still
// needs sensitive fields in trace, which will later be stripped.
for (auto& source : *trace_config.mutable_data_sources()) {
source.mutable_config()
->mutable_chrome_config()
->set_privacy_filtering_enabled(
chrome_config.IsArgumentFilterEnabled());
}
int duration_in_seconds = int duration_in_seconds =
tracing::TraceStartupConfig::GetInstance()->GetStartupDuration(); tracing::TraceStartupConfig::GetInstance()->GetStartupDuration();
......
...@@ -62,6 +62,7 @@ source_set("privacy_check") { ...@@ -62,6 +62,7 @@ source_set("privacy_check") {
testonly = true testonly = true
sources = [ sources = [
"perfetto/privacy_filtered_fields-inl.h",
"perfetto/privacy_filtering_check.cc", "perfetto/privacy_filtering_check.cc",
"perfetto/privacy_filtering_check.h", "perfetto/privacy_filtering_check.h",
] ]
......
// Copyright 2019 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 SERVICES_TRACING_PERFETTO_PRIVACY_FILTERED_FIELDS_INL_H_
#define SERVICES_TRACING_PERFETTO_PRIVACY_FILTERED_FIELDS_INL_H_
// This file is auto generated from internal copy of the TracePacket proto, that
// does not contain any privacy sensitive fields. Updates to this file should be
// made by changing internal copy and then running the generator script. Follow
// instructions at:
// https://goto.google.com/chrome-trace-privacy-filtered-fields
namespace tracing {
// A MessageInfo node created from a tree of TracePacket proto messages.
struct MessageInfo {
// List of accepted field ids in the output for this message. The end of list
// is marked by a -1.
const int* accepted_field_ids;
// List of sub messages that correspond to the accepted field ids list. There
// is no end of list marker and the length is this list is equal to length of
// |accepted_field_ids| - 1.
const MessageInfo* const* const sub_messages;
};
// Proto Message: TaskExecution
constexpr int kTaskExecutionIndices[] = {1, -1};
constexpr MessageInfo kTaskExecution = {kTaskExecutionIndices, nullptr};
// Proto Message: LegacyEvent
constexpr int kLegacyEventIndices[] = {1, 2, 3, 4, 6, 8, 9, 10,
11, 12, 13, 14, 18, 19, -1};
constexpr MessageInfo kLegacyEvent = {kLegacyEventIndices, nullptr};
// Proto Message: TrackEvent
constexpr int kTrackEventIndices[] = {1, 2, 3, 5, 6, 16, 17, -1};
constexpr MessageInfo const* kTrackEventComplexMessages[] = {
nullptr, nullptr, nullptr, &kTaskExecution,
&kLegacyEvent, nullptr, nullptr};
constexpr MessageInfo kTrackEvent = {kTrackEventIndices,
kTrackEventComplexMessages};
// Proto Message: EventCategory
constexpr int kEventCategoryIndices[] = {1, 2, -1};
constexpr MessageInfo kEventCategory = {kEventCategoryIndices, nullptr};
// Proto Message: LegacyEventName
constexpr int kLegacyEventNameIndices[] = {1, 2, -1};
constexpr MessageInfo kLegacyEventName = {kLegacyEventNameIndices, nullptr};
// Proto Message: SourceLocation
constexpr int kSourceLocationIndices[] = {1, 2, 3, -1};
constexpr MessageInfo kSourceLocation = {kSourceLocationIndices, nullptr};
// Proto Message: InternedData
constexpr int kInternedDataIndices[] = {1, 2, 4, -1};
constexpr MessageInfo const* kInternedDataComplexMessages[] = {
&kEventCategory, &kLegacyEventName, &kSourceLocation};
constexpr MessageInfo kInternedData = {kInternedDataIndices,
kInternedDataComplexMessages};
// Proto Message: BufferStats
constexpr int kBufferStatsIndices[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, -1};
constexpr MessageInfo kBufferStats = {kBufferStatsIndices, nullptr};
// Proto Message: TraceStats
constexpr int kTraceStatsIndices[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, -1};
constexpr MessageInfo const* kTraceStatsComplexMessages[] = {
&kBufferStats, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr};
constexpr MessageInfo kTraceStats = {kTraceStatsIndices,
kTraceStatsComplexMessages};
// Proto Message: ProcessDescriptor
constexpr int kProcessDescriptorIndices[] = {1, 4, -1};
constexpr MessageInfo kProcessDescriptor = {kProcessDescriptorIndices, nullptr};
// Proto Message: ThreadDescriptor
constexpr int kThreadDescriptorIndices[] = {1, 2, 4, 6, 7, -1};
constexpr MessageInfo kThreadDescriptor = {kThreadDescriptorIndices, nullptr};
// EDIT: Contains field numbers: {3} which are not autogenerated.
// Proto Message: TracePacket
constexpr int kTracePacketIndices[] = {3, 10, 11, 12, 35, 36,
41, 42, 43, 44, -1};
constexpr MessageInfo const* kTracePacketComplexMessages[] = {
nullptr, nullptr, &kTrackEvent, &kInternedData, &kTraceStats,
nullptr, nullptr, nullptr, &kProcessDescriptor, &kThreadDescriptor};
constexpr MessageInfo kTracePacket = {kTracePacketIndices,
kTracePacketComplexMessages};
} // namespace tracing
#endif // SERVICES_TRACING_PERFETTO_PRIVACY_FILTERED_FIELDS_INL_H_
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "services/tracing/perfetto/privacy_filtering_check.h" #include "services/tracing/perfetto/privacy_filtering_check.h"
#include "base/logging.h" #include "base/logging.h"
#include "services/tracing/perfetto/privacy_filtered_fields-inl.h"
#include "third_party/perfetto/protos/perfetto/trace/interned_data/interned_data.pbzero.h" #include "third_party/perfetto/protos/perfetto/trace/interned_data/interned_data.pbzero.h"
#include "third_party/perfetto/protos/perfetto/trace/trace.pbzero.h" #include "third_party/perfetto/protos/perfetto/trace/trace.pbzero.h"
#include "third_party/perfetto/protos/perfetto/trace/trace_packet.pbzero.h" #include "third_party/perfetto/protos/perfetto/trace/trace_packet.pbzero.h"
...@@ -18,79 +19,6 @@ using perfetto::protos::pbzero::TracePacket; ...@@ -18,79 +19,6 @@ using perfetto::protos::pbzero::TracePacket;
using perfetto::protos::pbzero::TrackEvent; using perfetto::protos::pbzero::TrackEvent;
using protozero::ProtoDecoder; using protozero::ProtoDecoder;
// A Message node created from a tree of trace packet proto messages.
struct Message {
// List of accepted field ids in the output for this message. The end of list
// is marked by a -1.
const int* accepted_field_ids;
// List of sub messages that correspond to the accepted field ids list. There
// is no end of list marker and the length is this list is equal to length of
// |accepted_field_ids| - 1.
const Message* const* const sub_messages;
};
// The structure of acceptable field IDs in the output proto.
// TODO(ssid): This should be generated as a resource file using the proto
// definitions using a script.
// Interned data types:
constexpr int kSourceLocationIndices[] = {1, 2, 3, -1};
constexpr Message kSourceLocation = {kSourceLocationIndices, nullptr};
constexpr int kLegacyEventNameIndices[] = {1, 2, -1};
constexpr Message kLegacyEventName = {kLegacyEventNameIndices, nullptr};
constexpr int kEventCategoryIndices[] = {1, 2, -1};
constexpr Message kEventCategory = {kEventCategoryIndices, nullptr};
constexpr int kInternedDataIndices[] = {1, 2, 4, -1};
constexpr Message const* kInternedDataComplexMessages[] = {
&kEventCategory, &kLegacyEventName, &kSourceLocation};
constexpr Message kInternedData = {kInternedDataIndices,
kInternedDataComplexMessages};
// Typed track events:
constexpr int kTaskExecutionIndices[] = {1, -1};
constexpr Message kTaskExecution = {kTaskExecutionIndices, nullptr};
// Track event tree:
constexpr int kThreadDescriptorIndices[] = {1, 2, 4, 6, 7, -1};
constexpr Message kThreadDescriptor = {kThreadDescriptorIndices, nullptr};
constexpr int kProcessDescriptorIndices[] = {1, 4, -1};
constexpr Message kProcessDescriptor = {kProcessDescriptorIndices, nullptr};
constexpr int kLegacyEventIndices[] = {1, 2, 3, 4, 6, 8, 9, 10,
11, 12, 13, 14, 18, 19, -1};
constexpr Message kLegacyEvent = {kLegacyEventIndices, nullptr};
constexpr int kTrackEventIndices[] = {1, 2, 3, 5, 6, 16, 17, -1};
constexpr Message const* kTrackEventComplexMessages[] = {
nullptr, nullptr, nullptr, &kTaskExecution,
&kLegacyEvent, nullptr, nullptr};
constexpr Message kTrackEvent = {kTrackEventIndices,
kTrackEventComplexMessages};
// Trace packet:
constexpr int kTracePacketIndices[] = {10, 11, 12, 41, 42, 43, 44,
// These should be removed or whitelisted
3, 33, 35, 36, 45, -1};
constexpr Message const* kTracePacketComplexMessages[] = {nullptr,
&kTrackEvent,
&kInternedData,
nullptr,
nullptr,
&kProcessDescriptor,
&kThreadDescriptor,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr};
constexpr Message kTracePacket = {kTracePacketIndices,
kTracePacketComplexMessages};
int FindIndexOfValue(const int* const arr, uint32_t value) { int FindIndexOfValue(const int* const arr, uint32_t value) {
for (unsigned i = 0; arr[i] != -1; ++i) { for (unsigned i = 0; arr[i] != -1; ++i) {
if (static_cast<int>(value) == arr[i]) if (static_cast<int>(value) == arr[i])
...@@ -101,7 +29,7 @@ int FindIndexOfValue(const int* const arr, uint32_t value) { ...@@ -101,7 +29,7 @@ int FindIndexOfValue(const int* const arr, uint32_t value) {
// Recursively verifies that the |proto| contains only accepted field IDs // Recursively verifies that the |proto| contains only accepted field IDs
// including all sub messages. // including all sub messages.
void VerifyProto(const Message* root, ProtoDecoder* proto) { void VerifyProto(const MessageInfo* root, ProtoDecoder* proto) {
proto->Reset(); proto->Reset();
for (auto f = proto->ReadField(); f.valid(); f = proto->ReadField()) { for (auto f = proto->ReadField(); f.valid(); f = proto->ReadField()) {
int index = FindIndexOfValue(root->accepted_field_ids, f.id()); int index = FindIndexOfValue(root->accepted_field_ids, f.id());
...@@ -129,7 +57,7 @@ void PrivacyFilteringCheck::CheckProtoForUnexpectedFields( ...@@ -129,7 +57,7 @@ void PrivacyFilteringCheck::CheckProtoForUnexpectedFields(
for (auto it = trace.packet(); !!it; ++it) { for (auto it = trace.packet(); !!it; ++it) {
TracePacket::Decoder packet(it->data(), it->size()); TracePacket::Decoder packet(it->data(), it->size());
const Message* root = &kTracePacket; const MessageInfo* root = &kTracePacket;
VerifyProto(root, &packet); VerifyProto(root, &packet);
if (packet.has_track_event()) { if (packet.has_track_event()) {
......
...@@ -29,6 +29,8 @@ perfetto::TraceConfig GetDefaultPerfettoConfig( ...@@ -29,6 +29,8 @@ perfetto::TraceConfig GetDefaultPerfettoConfig(
// blocked by the sandboxed and isn't needed for Chrome regardless. // blocked by the sandboxed and isn't needed for Chrome regardless.
auto* builtin_data_sources = perfetto_config.mutable_builtin_data_sources(); auto* builtin_data_sources = perfetto_config.mutable_builtin_data_sources();
builtin_data_sources->set_disable_clock_snapshotting(true); builtin_data_sources->set_disable_clock_snapshotting(true);
builtin_data_sources->set_disable_trace_config(privacy_filtering_enabled);
builtin_data_sources->set_disable_system_info(privacy_filtering_enabled);
// Capture actual trace events. // Capture actual trace events.
auto* trace_event_data_source = perfetto_config.add_data_sources(); auto* trace_event_data_source = perfetto_config.add_data_sources();
......
...@@ -149,11 +149,18 @@ struct DataSource { ...@@ -149,11 +149,18 @@ struct DataSource {
array<string> producer_name_filter; array<string> producer_name_filter;
}; };
struct PerfettoBuiltinDataSource {
bool disable_clock_snapshotting;
bool disable_trace_config;
bool disable_system_info;
};
// The configuration provided by a Consumer to the Perfetto service which // The configuration provided by a Consumer to the Perfetto service which
// primarily configures which named data sources it would like to enable and // primarily configures which named data sources it would like to enable and
// receive tracing data from, and how large the destination buffers should be. // receive tracing data from, and how large the destination buffers should be.
struct TraceConfig { struct TraceConfig {
array<DataSource> data_sources; array<DataSource> data_sources;
PerfettoBuiltinDataSource perfetto_builtin_data_source;
array<BufferConfig> buffers; array<BufferConfig> buffers;
uint32 duration_ms; uint32 duration_ms;
......
...@@ -36,5 +36,6 @@ type_mappings = [ ...@@ -36,5 +36,6 @@ type_mappings = [
"tracing.mojom.DataSourceConfig=perfetto::DataSourceConfig", "tracing.mojom.DataSourceConfig=perfetto::DataSourceConfig",
"tracing.mojom.ChromeConfig=perfetto::ChromeConfig", "tracing.mojom.ChromeConfig=perfetto::ChromeConfig",
"tracing.mojom.DataSourceRegistration=perfetto::DataSourceDescriptor", "tracing.mojom.DataSourceRegistration=perfetto::DataSourceDescriptor",
"tracing.mojom.PerfettoBuiltinDataSource=perfetto::TraceConfig::BuiltinDataSource",
"tracing.mojom.TraceConfig=perfetto::TraceConfig", "tracing.mojom.TraceConfig=perfetto::TraceConfig",
] ]
...@@ -44,12 +44,25 @@ bool StructTraits<tracing::mojom::DataSourceDataView, ...@@ -44,12 +44,25 @@ bool StructTraits<tracing::mojom::DataSourceDataView,
return true; return true;
} }
// static
bool StructTraits<tracing::mojom::PerfettoBuiltinDataSourceDataView,
perfetto::TraceConfig::BuiltinDataSource>::
Read(tracing::mojom::PerfettoBuiltinDataSourceDataView data,
perfetto::TraceConfig::BuiltinDataSource* out) {
out->set_disable_clock_snapshotting(data.disable_clock_snapshotting());
out->set_disable_trace_config(data.disable_trace_config());
out->set_disable_system_info(data.disable_system_info());
return true;
}
// static // static
bool StructTraits<tracing::mojom::TraceConfigDataView, perfetto::TraceConfig>:: bool StructTraits<tracing::mojom::TraceConfigDataView, perfetto::TraceConfig>::
Read(tracing::mojom::TraceConfigDataView data, perfetto::TraceConfig* out) { Read(tracing::mojom::TraceConfigDataView data, perfetto::TraceConfig* out) {
std::vector<perfetto::TraceConfig::DataSource> data_sources; std::vector<perfetto::TraceConfig::DataSource> data_sources;
std::vector<perfetto::TraceConfig::BufferConfig> buffers; std::vector<perfetto::TraceConfig::BufferConfig> buffers;
if (!data.ReadDataSources(&data_sources) || !data.ReadBuffers(&buffers)) { if (!data.ReadDataSources(&data_sources) || !data.ReadBuffers(&buffers) ||
!data.ReadPerfettoBuiltinDataSource(
out->mutable_builtin_data_sources())) {
return false; return false;
} }
......
...@@ -49,6 +49,30 @@ class StructTraits<tracing::mojom::DataSourceDataView, ...@@ -49,6 +49,30 @@ class StructTraits<tracing::mojom::DataSourceDataView,
perfetto::TraceConfig::DataSource* out); perfetto::TraceConfig::DataSource* out);
}; };
// perfetto::TraceConfig::BuiltinDataSource
template <>
class StructTraits<tracing::mojom::PerfettoBuiltinDataSourceDataView,
perfetto::TraceConfig::BuiltinDataSource> {
public:
static bool disable_clock_snapshotting(
const perfetto::TraceConfig::BuiltinDataSource& src) {
return src.disable_clock_snapshotting();
}
static bool disable_trace_config(
const perfetto::TraceConfig::BuiltinDataSource& src) {
return src.disable_trace_config();
}
static bool disable_system_info(
const perfetto::TraceConfig::BuiltinDataSource& src) {
return src.disable_system_info();
}
static bool Read(tracing::mojom::PerfettoBuiltinDataSourceDataView data,
perfetto::TraceConfig::BuiltinDataSource* out);
};
// perfetto::TraceConfig // perfetto::TraceConfig
template <> template <>
class StructTraits<tracing::mojom::TraceConfigDataView, perfetto::TraceConfig> { class StructTraits<tracing::mojom::TraceConfigDataView, perfetto::TraceConfig> {
...@@ -58,6 +82,11 @@ class StructTraits<tracing::mojom::TraceConfigDataView, perfetto::TraceConfig> { ...@@ -58,6 +82,11 @@ class StructTraits<tracing::mojom::TraceConfigDataView, perfetto::TraceConfig> {
return src.data_sources(); return src.data_sources();
} }
static const perfetto::TraceConfig::BuiltinDataSource&
perfetto_builtin_data_source(const perfetto::TraceConfig& src) {
return src.builtin_data_sources();
}
static const std::vector<perfetto::TraceConfig::BufferConfig>& buffers( static const std::vector<perfetto::TraceConfig::BufferConfig>& buffers(
const perfetto::TraceConfig& src) { const perfetto::TraceConfig& src) {
return src.buffers(); return src.buffers();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment