Include PERF_SAMPLE_HOST_IP in ASLR_SAMPLE_MASK and remap sampled host_ip addresses against the host machine in aslr_tool__process_sample() so anonymized perf.data files do not leak raw host hypervisor virtual addresses. Signed-off-by: Ian Rogers --- tools/perf/util/aslr.c | 32 ++++++++++++++++++++++++++++++++ tools/perf/util/aslr.h | 3 ++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/aslr.c b/tools/perf/util/aslr.c index e365f807b021..ec2c0989e19d 100644 --- a/tools/perf/util/aslr.c +++ b/tools/perf/util/aslr.c @@ -1109,6 +1109,38 @@ static int aslr_tool__process_sample(const struct perf_tool *tool, if (orig_sample_type & PERF_SAMPLE_CODE_PAGE_SIZE) COPY_U64(); /* code_page_size */ + if (orig_sample_type & PERF_SAMPLE_HOST_IP) { + u64 remapped = 0; + + if (CHECK_BOUNDS(1, 1)) { + ret = -EFAULT; + goto out_put; + } + if (sample->host_ip) { + struct machine *host_machine = &aslr->machines.host; + struct thread *host_thread; + u8 host_cpumode = PERF_RECORD_MISC_USER; + + if (aslr_tool__preload_kernel_maps(host_machine) < 0) { + ret = -ENOMEM; + goto out_put; + } + host_thread = machine__findnew_thread(host_machine, sample->pid, + sample->tid); + if (!host_thread) { + ret = -ENOMEM; + goto out_put; + } + if (machine__kernel_ip(host_machine, sample->host_ip)) + host_cpumode = PERF_RECORD_MISC_KERNEL; + remapped = aslr_tool__remap_address(aslr, host_thread, + host_cpumode, sample->host_ip); + thread__put(host_thread); + } + out_array[j++] = remapped; + i++; + } + if (orig_sample_type & PERF_SAMPLE_AUX) { u64 size; diff --git a/tools/perf/util/aslr.h b/tools/perf/util/aslr.h index 9cc14f0263db..8850511a4a43 100644 --- a/tools/perf/util/aslr.h +++ b/tools/perf/util/aslr.h @@ -26,7 +26,8 @@ PERF_SAMPLE_CGROUP | \ PERF_SAMPLE_DATA_PAGE_SIZE | \ PERF_SAMPLE_CODE_PAGE_SIZE | \ - PERF_SAMPLE_AUX) + PERF_SAMPLE_AUX | \ + PERF_SAMPLE_HOST_IP) struct perf_session; struct perf_tool; -- 2.56.1.915.g69d5ec7298-goog