summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorJaewon Jung <jaewon8868@gmail.com>2026-10-28 16:44:54 +0900
committerSteven Rostedt <rostedt@goodmis.org>2026-11-20 10:02:34 -0500
commitcae7fb0d853eff05c70b08ef9e7ecb18867f8945 (patch)
treee8c6965d4574b6c26df991f91c9997ee70b95d6f /kernel
parent2b3bed9617bb71c9b1893d9f54ef8df59a239224 (diff)
tracing: Avoid undefined shifts for zero histogram map size
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@vger.kernel.org Link: https://patch.msgid.link/20261028074610.2212374-1-jaewon8868@gmail.com Signed-off-by: Jaewon Jung <jaewon8868@gmail.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/trace/trace_events_hist.c5
1 files changed, 5 insertions, 0 deletions
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)