[PATCH v6 05/10] perf disasm: Fix potential NULL pointer dereference and use-after-free in arch__find()
From: Ian Rogers
Date: Thu Jul 16 2026 - 03:24:49 EST
In arch__find(), if the architecture's arch_new_fn[e_machine]() returns
NULL, the error handling path attempts to read result->name, dereferencing
a NULL pointer and crashing. At the same time, it invokes free(tmp)
BEFORE updating the static global archs pointer to tmp. If the
reallocarray() call moved the allocated block, the original archs pointer
remained active but was freed. A subsequent call to arch__find() would
then pass this dangling pointer into bsearch(), causing a use-after-free.
Fix both by printing the numeric e_machine ID instead of result->name,
and updating the static global archs pointer to tmp immediately after the
successful reallocarray() invocation to safely retain the valid prior
architectures.
Closes: https://lore.kernel.org/linux-perf-users/20260709035721.9EE901F000E9@xxxxxxxxxxxxxxx/
Assisted-by: Antigravity:gemini-3.5-flash
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/util/disasm.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c
index 0a1a7e9cf3ef..6cfdbabbb8c7 100644
--- a/tools/perf/util/disasm.c
+++ b/tools/perf/util/disasm.c
@@ -180,14 +180,14 @@ const struct arch *arch__find(uint16_t e_machine, uint32_t e_flags, const char *
if (!tmp)
return NULL;
+ archs = tmp;
+
result = arch_new_fn[e_machine](&key, cpuid);
if (!result) {
- pr_err("%s: failed to initialize %s (%u) arch priv area\n",
- __func__, result->name, e_machine);
- free(tmp);
+ pr_err("%s: failed to initialize %u arch priv area\n",
+ __func__, e_machine);
return NULL;
}
- archs = tmp;
archs[num_archs++] = result;
qsort(archs, num_archs, sizeof(*archs), arch__cmp);
return result;
--
2.55.0.141.g00534a21ce-goog