]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf annotate: Fix memcpy size in arch__grow_instructions()
authorSuchit Karunakaran <suchitkarunakaran@gmail.com>
Thu, 22 Jan 2026 17:17:04 +0000 (22:47 +0530)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 23 Jan 2026 19:58:39 +0000 (16:58 -0300)
The memcpy() in arch__grow_instructions() is copying the wrong number of
bytes when growing from a non-allocated table.

It should copy arch->nr_instructions * sizeof(struct ins) bytes, not
just arch->nr_instructions bytes.

This bug causes data corruption as only a partial copy of the
instruction table is made, leading to garbage data in most entries and
potential crashes

Fixes: 2a1ff812c40be982 ("perf annotate: Introduce alternative method of keeping instructions table")
Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: Suchit Karunakaran <suchitkarunakaran@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/disasm.c

index 4f60726247d62764b1a6f710ea5173c80f152b9f..9b0ba1fc5aecd0fdd47986a8cbef46f1602524dc 100644 (file)
@@ -82,7 +82,7 @@ grow_from_non_allocated_table:
        if (new_instructions == NULL)
                return -1;
 
-       memcpy(new_instructions, arch->instructions, arch->nr_instructions);
+       memcpy(new_instructions, arch->instructions, arch->nr_instructions * sizeof(struct ins));
        goto out_update_instructions;
 }