Validate resultFileName to prevent path traversal

ProfilingService.sendAnomalyProfile() accepted an unsanitized
resultFileName parameter from callers, which was concatenated directly
with sTempTracePath (/data/misc/perfetto-traces/profiling/) in file
operations (e.g. read via receiveFileDescriptor and delete via
deleteProfilingFiles).

This allowed path traversal payloads (such as
"../../../../data/system/packages.xml") to read or delete arbitrary
files with system_server privileges.

This change adds enforceValidResultFileName() in ProfilingService to
reject null/empty strings, path separators (/ and \), relative path
sequences (..), and paths resolving outside the base profiling
directory.

Bug: 546680461
Bug: 546679793
Test: manual
Flag: EXEMPT bugfix
Cherrypick-From: https://googleplex-android-review.googlesource.com/q/commit:e5e649dd60542f17bc9d3988fb8afd24911a3c8f
Cherrypick-From: https://googleplex-android-review.googlesource.com/q/commit:e954b0f8155ea02b46156ebe478bc66593855aca
Merged-In: I30adfd935a60ac2b878e60cda2b12b1f6423d25b
Change-Id: I30adfd935a60ac2b878e60cda2b12b1f6423d25b
1 file changed