xref: /aosp_15_r20/external/perfetto/docs/design-docs/security-model.md (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1*6dbdd20aSAndroid Build Coastguard Worker# Security model for system-wide tracing on Android/Linux
2*6dbdd20aSAndroid Build Coastguard Worker
3*6dbdd20aSAndroid Build Coastguard WorkerThe tracing service has two endpoints (in Chromium: Mojo services, on
4*6dbdd20aSAndroid Build Coastguard WorkerAndroid/Linux: UNIX sockets): one for producer(s) and one for consumer(s).
5*6dbdd20aSAndroid Build Coastguard WorkerThe former is typically public, the latter is restricted only to trusted
6*6dbdd20aSAndroid Build Coastguard Workerconsumers.
7*6dbdd20aSAndroid Build Coastguard Worker
8*6dbdd20aSAndroid Build Coastguard Worker![Security overview](https://storage.googleapis.com/perfetto/markdown_img/security-overview.png)
9*6dbdd20aSAndroid Build Coastguard Worker
10*6dbdd20aSAndroid Build Coastguard Worker## Producers
11*6dbdd20aSAndroid Build Coastguard Worker
12*6dbdd20aSAndroid Build Coastguard WorkerProducers are never trusted. We assume they will try their best to DoS / crash /
13*6dbdd20aSAndroid Build Coastguard Workerexploit the tracing service. We do so at the
14*6dbdd20aSAndroid Build Coastguard Worker[service/tracing_service_impl.cc](/src/tracing/service/tracing_service_impl.cc) so
15*6dbdd20aSAndroid Build Coastguard Workerthat the same level of security and testing is applied regardless of the
16*6dbdd20aSAndroid Build Coastguard Workerembedder and the IPC transport.
17*6dbdd20aSAndroid Build Coastguard Worker
18*6dbdd20aSAndroid Build Coastguard Worker## Tracing service
19*6dbdd20aSAndroid Build Coastguard Worker
20*6dbdd20aSAndroid Build Coastguard Worker- The tracing service has to validate all inputs.
21*6dbdd20aSAndroid Build Coastguard Worker- In the worst case a bug in the tracing service allowing remote code execution,
22*6dbdd20aSAndroid Build Coastguard Worker  the tracing service should have no meaningful capabilities to exploit.
23*6dbdd20aSAndroid Build Coastguard Worker- The tracing service, by design, has a limited syscall surface to simplify
24*6dbdd20aSAndroid Build Coastguard Worker  its sandboxing:
25*6dbdd20aSAndroid Build Coastguard Worker  - It doesn't open or create files (% tmpfs).
26*6dbdd20aSAndroid Build Coastguard Worker  - It writes only onto file descriptors passed over the IPC channel.
27*6dbdd20aSAndroid Build Coastguard Worker  - It doesn't open or create sockets (on Android the IPC sockets are passed by
28*6dbdd20aSAndroid Build Coastguard Worker    init, see [perfetto.rc](/perfetto.rc))
29*6dbdd20aSAndroid Build Coastguard Worker  - On Android it runs as nobody:nobody and is allowed to do very little
30*6dbdd20aSAndroid Build Coastguard Worker    see [traced.te](https://android.googlesource.com/platform/system/sepolicy/+/main/private/traced.te).
31*6dbdd20aSAndroid Build Coastguard Worker  - In Chromium it should run as a utility process.
32*6dbdd20aSAndroid Build Coastguard Worker
33*6dbdd20aSAndroid Build Coastguard Worker## Consumers
34*6dbdd20aSAndroid Build Coastguard WorkerConsumers are always trusted. They still shouldn't be able to crash or exploit
35*6dbdd20aSAndroid Build Coastguard Workerthe service. They can easily DoS it though, but that is WAI.
36*6dbdd20aSAndroid Build Coastguard Worker  - In Chromium the trust path is established through service manifest.
37*6dbdd20aSAndroid Build Coastguard Worker  - In Android the trust path is established locking down the consumer socket
38*6dbdd20aSAndroid Build Coastguard Worker    to shell through SELinux.
39*6dbdd20aSAndroid Build Coastguard Worker
40*6dbdd20aSAndroid Build Coastguard Worker## Shared memory isolation
41*6dbdd20aSAndroid Build Coastguard WorkerMemory is shared only point-to-point between each producer and the tracing
42*6dbdd20aSAndroid Build Coastguard Workerservice. We should never ever share memory across producers (in order to not
43*6dbdd20aSAndroid Build Coastguard Workerleak trace data belonging to different producers) nor between producers and
44*6dbdd20aSAndroid Build Coastguard Workerconsumers (that would open a hard to audit path between
45*6dbdd20aSAndroid Build Coastguard Workeruntrusted-and-unprivileged and trusted-and-more-privileged entities).
46*6dbdd20aSAndroid Build Coastguard Worker
47*6dbdd20aSAndroid Build Coastguard Worker## Attestation of trace contents
48*6dbdd20aSAndroid Build Coastguard WorkerThe tracing service guarantees that the `TracePacket` fields written by the
49*6dbdd20aSAndroid Build Coastguard WorkerService cannot be spoofed by the Producer(s).
50*6dbdd20aSAndroid Build Coastguard WorkerPackets that try to define those fields are rejected, modulo clock snapshots.
51*6dbdd20aSAndroid Build Coastguard WorkerSee [PacketStreamValidator](/src/tracing/service/packet_stream_validator.cc) and
52*6dbdd20aSAndroid Build Coastguard Worker[its unit test](/src/tracing/service/packet_stream_validator_unittest.cc) for more
53*6dbdd20aSAndroid Build Coastguard Workerdetails.
54*6dbdd20aSAndroid Build Coastguard WorkerAt the moment nothing prevents that a producer writes `TracePacket(s)` that do
55*6dbdd20aSAndroid Build Coastguard Workernot belong to its data sources. Realistically the service will never prevent
56*6dbdd20aSAndroid Build Coastguard Workerthat because doing so would imply that the service knows about all the possible
57*6dbdd20aSAndroid Build Coastguard Workertypes of packets, which doesn't scale.
58*6dbdd20aSAndroid Build Coastguard WorkerHowever, the service appends the POSIX uid of the producer to each `TracePacket`
59*6dbdd20aSAndroid Build Coastguard Workerto perform offline attestation of the contents of the trace.
60