[for-linus][PATCH 07/32] tracing: Avoid undefined shifts for zero histogram map size

From: Steven Rostedt

Date: Fri Nov 20 2026 - 12:42:28 EST


From: Jaewon Jung <jaewon8868@xxxxxxxxx>

Reject size=0 before calling roundup_pow_of_two().

include/linux/log2.h documents roundup_pow_of_two() as:

- the result is undefined when n == 0

With CONFIG_UBSAN_SHIFT=y, a size=0 histogram trigger reports:

UBSAN: shift-out-of-bounds in include/linux/log2.h
shift exponent 64 is too large for 64-bit type 'long unsigned int'

Tested on x86_64 QEMU: size=0 is rejected without UBSAN warnings,
and the histogram modifier and parser tests pass.

Fixes: 7ef224d1d0e3 ("tracing: Add 'hist' event trigger command")
Cc: stable@xxxxxxxxxxxxxxx
Link: https://patch.msgid.link/20261028074610.2212374-1-jaewon8868@xxxxxxxxx
Signed-off-by: Jaewon Jung <jaewon8868@xxxxxxxxx>
Signed-off-by: Steven Rostedt <rostedt@xxxxxxxxxxx>
---
kernel/trace/trace_events_hist.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index a87d626e40e8..d4702ad4e003 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -1430,6 +1430,11 @@ static int parse_map_size(char *str)
if (ret)
goto out;

+ if (!size) {
+ ret = -EINVAL;
+ goto out;
+ }
+
map_bits = ilog2(roundup_pow_of_two(size));
if (map_bits < TRACING_MAP_BITS_MIN ||
map_bits > TRACING_MAP_BITS_MAX)
--
2.53.0