]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
perf tools: NULL bitmap pointers after bitmap_free()
authorArnaldo Carvalho de Melo <acme@redhat.com>
Sun, 7 Jun 2026 00:31:51 +0000 (21:31 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 10 Jun 2026 16:13:32 +0000 (13:13 -0300)
Two call sites free bitmaps without NULLing the pointer, risking
double-free if the structure is reused or cleanup is called twice:

 - mmap__munmap():                 map->affinity_mask.bits
 - record__mmap_cpu_mask_free():   mask->bits

Set each pointer to NULL after bitmap_free().

Fixes: 8384a2600c7ddfc8 ("perf record: Adapt affinity to machines with #CPUs > 1K")
Fixes: f466e5ed6c356d1d ("perf record: Extend --threads command line option")
Reported-by: sashiko-bot <sashiko-bot@kernel.org>
Reviewed-by: Ian Rogers <irogers@google.com>
Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
Cc: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-record.c
tools/perf/util/mmap.c

index a33c78f030d910128ec30e429a04c1ff55b77eb2..e915390556752b9e7dcd112f6bd692b8ea17ee9f 100644 (file)
@@ -3084,6 +3084,7 @@ static int record__mmap_cpu_mask_alloc(struct mmap_cpu_mask *mask, int nr_bits)
 static void record__mmap_cpu_mask_free(struct mmap_cpu_mask *mask)
 {
        bitmap_free(mask->bits);
+       mask->bits = NULL;
        mask->nbits = 0;
 }
 
index d64aec6c7c843e815ea96e3eda4b4db88c8534e6..358e70c4f3edd077c9752115329f29040f1c2a76 100644 (file)
@@ -238,6 +238,8 @@ static void perf_mmap__aio_munmap(struct mmap *map __maybe_unused)
 void mmap__munmap(struct mmap *map)
 {
        bitmap_free(map->affinity_mask.bits);
+       map->affinity_mask.bits = NULL;
+       map->affinity_mask.nbits = 0;
 
        zstd_fini(&map->zstd_data);