tree: 4944d4c79f009b87c96727e06c511a6df8c541d7 [path history] [tgz]
  1. boardphase_packet_filter_integrationtest.cc
  2. broadphase_packet_filter.cc
  3. broadphase_packet_filter.h
  4. broadphase_packet_filter_unittest.cc
  5. BUILD.gn
  6. collect_frame_cookies.cc
  7. collect_frame_cookies.h
  8. collect_frame_cookies_unittest.cc
  9. collect_system_info.cc
  10. collect_system_info.h
  11. collect_system_info_unittest.cc
  12. collect_timeline_events.cc
  13. collect_timeline_events.h
  14. collect_timeline_events_unittest.cc
  15. filter_sched_waking_events_integrationtest.cc
  16. filter_sched_waking_events_unittest.cc
  17. filter_task_rename_integrationtest.cc
  18. filtering.cc
  19. filtering.h
  20. find_package_uid.cc
  21. find_package_uid.h
  22. find_package_uid_unittest.cc
  23. frame_cookie.h
  24. main.cc
  25. merge_threads.cc
  26. merge_threads.h
  27. modify.cc
  28. modify.h
  29. populate_allow_lists.cc
  30. populate_allow_lists.h
  31. process_thread_timeline.cc
  32. process_thread_timeline.h
  33. process_thread_timeline_integrationtest.cc
  34. process_thread_timeline_unittest.cc
  35. proto_util.cc
  36. proto_util.h
  37. proto_util_unittest.cc
  38. prune_package_list.cc
  39. prune_package_list.h
  40. prune_package_list_integrationtest.cc
  41. prune_package_list_unittest.cc
  42. README.md
  43. redact_ftrace_events.cc
  44. redact_ftrace_events.h
  45. redact_process_events.cc
  46. redact_process_events.h
  47. redact_process_events_unittest.cc
  48. redact_process_trees.cc
  49. redact_process_trees.h
  50. redact_process_trees_integrationtest.cc
  51. redact_sched_events.cc
  52. redact_sched_events.h
  53. redact_sched_events_integrationtest.cc
  54. redact_sched_events_unittest.cc
  55. scrub_process_stats.cc
  56. scrub_process_stats.h
  57. scrub_process_stats_integrationtest.cc
  58. trace_redaction_framework.cc
  59. trace_redaction_framework.h
  60. trace_redaction_integration_fixture.cc
  61. trace_redaction_integration_fixture.h
  62. trace_redactor.cc
  63. trace_redactor.h
  64. verify_integrity.cc
  65. verify_integrity.h
  66. verify_integrity_integrationtest.cc
  67. verify_integrity_unittest.cc
src/trace_redaction/README.md

Trace Redaction

Timeline

Intro

The timeline is at the center of the redaction system. It provides an efficient method to find which package a thread/process belongs to.

The timeline allows queries to be connected to time. Without this, there‘s a significant privacy conern because a pid can be recycled. Just because the pid is excluded from redaction before time T, doesn’t mean it should be redacted after time T.

General Structure

The timeline uses an event-based pattern using two events:

  • Open Event: Marks the begining of a pid's new lifespan.
  • Close Event: Marks the end of a pids's lifespan.

An event-based structure (compared to a span-based structure) is used as it is better suited to handle errors/issues in the underlying data. For example, if a pid doesn't explictly ends before being reused (e.g. two back-to-back open events), the event-based structure “just works”.

Open events contain the thread‘s full state. The close event only contains the information needed to reference the thread’s previous event.

struct Open {
    uint64_t ts;
    int32_t  pid;
    int32_t  ppid;
    uint64_t uid;
};

struct Close {
    uint64_t ts;
    int32_t  pid;
};

The vast majory of threads will have one event, an open event provided by the ProcessTree. For some threads, they will have multiple open (ProcessTree, NewTask) and close events (ProcFree) in alternating order.

Query

struct Slice {
    int32_t  pid;
    uint64_t uid;
};

class Timeline {
  Slice Query(uint64_t ts, int32_t pid) const;
};

Events, regardless of type, are stored in contiguous memory and are ordered first by pid and second by time. This is done to allow events to be found via a binary search.

The vast majory of threads will have one event, the open event. Some threads may have close and re-open events.

To handle a query,

  1. Use a binary search to find the lower bound for pid (the first instance of pid)
  2. Scan forward to find the last event before ts (for pid)

If an event was found:

if (e.type == kOpen && uid != 0)
  return Slice(pid, e.uid);

// The pid is active, check the parent for a uid.
if (e.type == kOpen && uid == 0)
  return Query(ts, e.ppid);

return Slice(pid, kNoPackage);

If pid does not have an immediate package (uid), the parent must be searched. The parent-child tree is short, so the recursive search will be relatively short. To minimize this even more, a union-find operation is applied because any queries can be made.

Simple runtime overview:

Initialization:

  • $sort + union\ find$

  • $nlogn + mlogn$

    • where $n=events$
    • and $m=approx\ average\ depth$

Query:

  • $P(p) = m_p * (logn + e_p)$

    • where $m_p=\ distance\ from\ pid\ to\ uid$
    • and $n=events$
    • and $e_p=number\ of\ events\ for\ process\ p$
  • Because of the union-find in initialization, $m_p \to 0$

To further reduce the runtime, the search domain is reduces by remove all open events for $pids$ that don't connect to a target $uid$. By removing open events, and close events, there are two advantages:

  1. Removing open events are safe and simple. By removing open events, those pids can never be marked by active. Keeping the close events effectively reminds the system that the pid is not active.

  2. The number of open events exceeds the number of close events. Removing open events will have a greater effect on the number of events.

Example:

NameValueNotes
tids3666Total number of threads.
freed threads5Number of threads that were freed.
reused threads0No threads were used more than one time.
process tids64Total number of threads connected to the target process.

After initialization, there would only be 64 open events and 5 close events. This means that every uid lookup would be $logn\ |\ n=64 = 6$. Finding the uid given a pid is one of the most common operations during redaction because uid determines if something needs to be redacted.

Scrub Task Rename Spec

Background

task_rename are generated when a thread renames itself. This often happens after (but not limited to) a task_newtask event. The task_rename event exposes the threads old name and the threads new name.

Protobuf Message(s)

New task event:

event {
  timestamp: 6702094133317685
  pid: 6167
  task_newtask {
    pid: 7972
    comm: "adbd"
    clone_flags: 4001536
    oom_score_adj: -1000
  }
}

Task rename event:

event {
  timestamp: 6702094133665498
  pid: 7972
  task_rename {
    pid: 7972
    oldcomm: "adbd"
    newcomm: "shell svc 7971"
    oom_score_adj: -1000
  }
}

Method

A task_rename should be redacted when event.pid does not belong to that target package (context.package_uid). Since the pid's naming information will be removed everywhere, and naming information is effectively metadata, the whole event can be dropped without effecting the integrity of the trace.