From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v6 4/6] perf inject/aslr: Add aslr tool to remap/obfuscate virtual addresses
Date: Fri, 08 May 2026 21:22:19 +0000 [thread overview]
Message-ID: <20260508212219.C5CD2C2BCB0@smtp.kernel.org> (raw)
In-Reply-To: <20260508082726.2795191-5-irogers@google.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The sample repacking logic silently drops unknown fields without clearing their corresponding UAPI presence flags, corrupting downstream parsing.
- [High] Missing PERF_RECORD_MISC_GUEST_KERNEL checks in mapping and remapping logic break ASLR obfuscation for guest kernel samples.
--
commit e5353f445ca316e60de67b84bb7594a8aa6daa49
Author: Ian Rogers <irogers@google.com>
perf inject/aslr: Add aslr tool to remap/obfuscate virtual addresses
This commit introduces a new ASLR obfuscation tool to perf inject that
remaps or drops virtual addresses to prevent ASLR leaks when sharing
perf.data files. It uses a delegate tool architecture to intercept and
sanitize events and samples.
> diff --git a/tools/perf/util/aslr.c b/tools/perf/util/aslr.c
> new file mode 100644
> index 0000000000000..09b7f2f8fb850
> --- /dev/null
> +++ b/tools/perf/util/aslr.c
[ ... ]
> +static u64 aslr_tool__remap_address(struct aslr_tool *aslr,
> + struct thread *aslr_thread,
> + u8 cpumode,
> + u64 addr)
> +{
[ ... ]
> + key.machine = maps__machine(aslr_thread->maps);
> + key.dso = map__dso(al.map);
> + key.invariant = map__start(al.map) - map__pgoff(al.map);
> + key.pid = effective_cpumode == PERF_RECORD_MISC_KERNEL ? kernel_pid : aslr_thread->pid_;
Does this also need to check for PERF_RECORD_MISC_GUEST_KERNEL? If a guest
kernel sample interrupts a user process, missing this check might cause
key.pid to be assigned aslr_thread->pid_ instead of kernel_pid (-1). Could
this mismatch prevent hashmap__find() from resolving the mapping?
[ ... ]
> +static u64 aslr_tool__findnew_mapping(struct aslr_tool *aslr,
> + struct thread *aslr_thread,
> + u8 cpumode, u64 start,
> + u64 len, u64 pgoff)
> +{
[ ... ]
> + /* The key to look up an incoming address to the outgoing value. */
> + addr_location__init(&al);
> + remap_key.machine = maps__machine(aslr_thread->maps);
> + remap_key.pid = (cpumode == PERF_RECORD_MISC_KERNEL) ? kernel_pid : aslr_thread->pid_;
Similarly here, if cpumode is PERF_RECORD_MISC_GUEST_KERNEL, shouldn't
remap_key.pid also be set to kernel_pid?
[ ... ]
> + /* No mmap, create an entry from the top address. */
> + if (hashmap__find(&aslr->top_addresses, &top_addr_key, &pmax)) {
[ ... ]
> + } else {
> + /* First address of the process, allocate key and first top address. */
> + struct top_addresses_key *tk;
> +
> + remap_addr = (cpumode == PERF_RECORD_MISC_KERNEL) ?
> + kernel_space_start : user_space_start;
Would guest kernel maps erroneously be allocated in the user_space_start
range here instead of kernel_space_start due to the missing check for
PERF_RECORD_MISC_GUEST_KERNEL?
[ ... ]
> +static int aslr_tool__process_sample(const struct perf_tool *tool, union perf_event *event,
> + struct perf_sample *sample,
> + struct evsel *evsel, struct machine *machine)
> +{
[ ... ]
> + if (sample_type & PERF_SAMPLE_AUX) {
> + u64 size;
> +
> + CHECK_BOUNDS(1, 1);
> + size = out_array[j++] = in_array[i++];
> + if (size > 0) {
> + size_t u64_words = size / 8 + (size % 8 ? 1 : 0);
> +
> + if (u64_words > max_i - i || u64_words > max_j - j) {
> + ret = -EFAULT;
> + goto out_put;
> + }
> + memcpy(&out_array[j], &in_array[i], size);
> + if (size % 8) {
> + size_t pad = 8 - (size % 8);
> +
> + memset(((char *)&out_array[j]) + size, 0, pad);
> + }
> + i += u64_words;
> + j += u64_words;
> + }
> + /* TODO: can this be less conservative? */
> + pr_debug("Dropping aux sample as possible ASLR leak\n");
> + ret = 0;
> + goto out_put;
> + }
> +
> + if (evsel__is_offcpu_event(evsel)) {
> + /* TODO: can this be less conservative? */
> + pr_debug("Dropping off-CPU sample as possible ASLR leak\n");
> + ret = 0;
> + goto out_put;
> + }
> +
> + new_event->sample.header.size = sizeof(struct perf_event_header) + j * sizeof(u64);
If the sample contains unknown UAPI fields (for instance, when processing a
perf.data file generated by a newer kernel), they appear to be silently
dropped from the payload during this repacking loop.
However, since unrecognized bits aren't cleared from evsel->core.attr,
will downstream parsers encounter missing fields while expecting them to
be present? Could this lead to reading misaligned data or triggering
-EFAULT parsing failures when analyzing the resulting trace?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260508082726.2795191-1-irogers@google.com?part=4
next prev parent reply other threads:[~2026-05-08 21:22 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-24 22:05 [PATCH v1 1/2] perf inject/aslr: Add aslr tool to remap/obfuscate virtual addresses Ian Rogers
2026-04-24 22:05 ` [PATCH v1 2/2] perf test: Add inject ASLR test Ian Rogers
2026-04-24 22:47 ` sashiko-bot
2026-04-24 22:36 ` [PATCH v1 1/2] perf inject/aslr: Add aslr tool to remap/obfuscate virtual addresses sashiko-bot
2026-04-25 2:05 ` [PATCH v2 " Ian Rogers
2026-04-25 2:05 ` [PATCH v2 2/2] perf test: Add inject ASLR test Ian Rogers
2026-05-04 3:51 ` [PATCH v3 0/4] perf tools: Add inject --aslr feature and prerequisite robustness fixes Ian Rogers
2026-05-04 3:51 ` [PATCH v3 1/4] perf sched: Add missing mmap2 handler in timehist Ian Rogers
2026-05-04 3:51 ` [PATCH v3 2/4] perf tool: Fix missing schedstat delegates and dont_split_sample_group in delegate_tool Ian Rogers
2026-05-04 3:51 ` [PATCH v3 3/4] perf inject/aslr: Add aslr tool to remap/obfuscate virtual addresses Ian Rogers
2026-05-04 4:51 ` sashiko-bot
2026-05-04 3:51 ` [PATCH v3 4/4] perf test: Add inject ASLR test Ian Rogers
2026-05-04 5:02 ` sashiko-bot
2026-05-04 7:29 ` [PATCH v4 0/4] perf tools: Add inject --aslr feature and prerequisite robustness fixes Ian Rogers
2026-05-04 7:29 ` [PATCH v4 1/4] perf sched: Add missing mmap2 handler in timehist Ian Rogers
2026-05-04 7:29 ` [PATCH v4 2/4] perf tool: Fix missing schedstat delegates and dont_split_sample_group in delegate_tool Ian Rogers
2026-05-04 7:29 ` [PATCH v4 3/4] perf inject/aslr: Add aslr tool to remap/obfuscate virtual addresses Ian Rogers
2026-05-04 8:39 ` sashiko-bot
2026-05-04 7:29 ` [PATCH v4 4/4] perf test: Add inject ASLR test Ian Rogers
2026-05-04 8:48 ` sashiko-bot
2026-05-04 8:23 ` [PATCH v4 0/4] perf tools: Add inject --aslr feature and prerequisite robustness fixes Ian Rogers
2026-05-06 0:45 ` [PATCH v5 0/5] " Ian Rogers
2026-05-06 0:45 ` [PATCH v5 1/5] perf sched: Add missing mmap2 handler in timehist Ian Rogers
2026-05-06 13:22 ` Arnaldo Carvalho de Melo
2026-05-06 16:16 ` Ian Rogers
2026-05-06 0:45 ` [PATCH v5 2/5] perf tool: Fix missing schedstat delegates and dont_split_sample_group in delegate_tool Ian Rogers
2026-05-06 0:45 ` [PATCH v5 3/5] perf symbols: Fix map removal sequence inside dso__process_kernel_symbol() Ian Rogers
2026-05-06 1:45 ` sashiko-bot
2026-05-06 0:45 ` [PATCH v5 4/5] perf inject/aslr: Add aslr tool to remap/obfuscate virtual addresses Ian Rogers
2026-05-06 2:40 ` sashiko-bot
2026-05-06 18:52 ` Namhyung Kim
2026-05-06 20:01 ` Ian Rogers
2026-05-06 0:45 ` [PATCH v5 5/5] perf test: Add inject ASLR test Ian Rogers
2026-05-07 15:58 ` James Clark
2026-05-07 16:17 ` Ian Rogers
2026-05-08 10:42 ` James Clark
2026-05-08 10:49 ` James Clark
2026-05-08 8:27 ` [PATCH v6 0/6] perf tools: Add inject --aslr feature and prerequisite robustness fixes Ian Rogers
2026-05-08 8:27 ` [PATCH v6 1/6] perf sched: Add missing mmap2 handler in timehist Ian Rogers
2026-05-08 8:27 ` [PATCH v6 2/6] perf tool: Missing delegate_tool schedstat delegates and dont_split_sample_group Ian Rogers
2026-05-08 8:27 ` [PATCH v6 3/6] perf maps: Add maps__mutate_mapping Ian Rogers
2026-05-08 10:57 ` James Clark
2026-05-08 20:37 ` sashiko-bot
2026-05-11 7:07 ` Namhyung Kim
2026-05-08 8:27 ` [PATCH v6 4/6] perf inject/aslr: Add aslr tool to remap/obfuscate virtual addresses Ian Rogers
2026-05-08 21:22 ` sashiko-bot [this message]
2026-05-11 7:32 ` Namhyung Kim
2026-05-08 8:27 ` [PATCH v6 5/6] perf test: Add inject ASLR test Ian Rogers
2026-05-08 13:29 ` James Clark
2026-05-08 14:29 ` James Clark
2026-05-11 7:34 ` Namhyung Kim
2026-05-08 8:27 ` [PATCH v6 6/6] perf aslr: Strip sample registers Ian Rogers
2026-05-08 21:49 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260508212219.C5CD2C2BCB0@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=irogers@google.com \
--cc=linux-perf-users@vger.kernel.org \
--cc=sashiko@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox