linux/kernel/events
Adrian Hunter d666e3c9af perf: Prevent passing zero nr_pages to rb_alloc_aux()
[ Upstream commit dbc48c8f41 ]

nr_pages is unsigned long but gets passed to rb_alloc_aux() as an int,
and is stored as an int.

Only power-of-2 values are accepted, so if nr_pages is a 64_bit value, it
will be passed to rb_alloc_aux() as zero.

That is not ideal because:
 1. the value is incorrect
 2. rb_alloc_aux() is at risk of misbehaving, although it manages to
 return -ENOMEM in that case, it is a result of passing zero to get_order()
 even though the get_order() result is documented to be undefined in that
 case.

Fix by simply validating the maximum supported value in the first place.
Use -ENOMEM error code for consistency with the current error code that
is returned in that case.

Fixes: 45bfb2e504 ("perf: Add AUX area to ring buffer for raw data streams")
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20240624201101.60186-6-adrian.hunter@intel.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-08-03 08:49:07 +02:00
..
callchain.c uaccess: remove CONFIG_SET_FS 2022-02-25 09:36:06 +01:00
core.c perf: Prevent passing zero nr_pages to rb_alloc_aux() 2024-08-03 08:49:07 +02:00
hw_breakpoint_test.c perf/hw_breakpoint: test: Skip the test if dependencies unmet 2022-11-02 12:22:05 +01:00
hw_breakpoint.c perf/hw_breakpoint: Annotate tsk->perf_event_mutex vs ctx->mutex 2022-10-04 13:32:09 +02:00
internal.h perf: Fix perf_aux_size() for greater-than 32-bit size 2024-08-03 08:49:07 +02:00
Makefile perf/hw_breakpoint: Add KUnit test for constraints accounting 2022-08-30 10:56:20 +02:00
ring_buffer.c perf/core: Bail out early if the request AUX area is out of bound 2023-11-28 17:06:54 +00:00
uprobes.c mm/madvise: add file and shmem support to MADV_COLLAPSE 2022-10-03 14:03:33 -07:00