[PATCH] tracing: avoid overflow when parsing histogram map size
From: Kyuwon Cho
Date: Thu Dec 03 2026 - 11:52:37 EST
parse_map_size() rounds the requested size up to a power of two before
checking the supported bit range. A size above the largest representable
power of two makes roundup_pow_of_two() shift by the word size.
Use order_base_2(), which computes the required order without constructing
the power-of-two value. The existing range check then rejects the request.
Fixes: 7ef224d1d0e3 ("tracing: Add 'hist' event trigger command")
Signed-off-by: Kyuwon Cho <kyuwon.cho@xxxxxxxx>
---
The issue was found by an LLM-guided test generator that we are
developing as a research prototype.
The reproducer mounts tracefs and requests ULONG_MAX as a histogram map
size. Access to tracefs requires root in the initial namespace.
The decoded trace is:
UBSAN: shift-out-of-bounds in include/linux/log2.h:57:13
shift exponent 64 is too large for 64-bit type 'long unsigned int'
event_hist_trigger_parse.cold (include/linux/log2.h:57
kernel/trace/trace_events_hist.c:1438
kernel/trace/trace_events_hist.c:6929)
trigger_process_regex (kernel/trace/trace_events_trigger.c:388)
event_trigger_write (kernel/trace/trace_events_trigger.c:418)
vfs_write (fs/read_write.c:665)
The patch was tested on v7.4-rc5, rebased onto tracing commit
175e5f3eddc6 ("tracing: Use test_bit() in event_enable_count_probe()"),
and built there.
kernel/trace/trace_events_hist.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index d4702ad4e003..4ab3baa602ad 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -1435,7 +1435,7 @@ static int parse_map_size(char *str)
goto out;
}
- map_bits = ilog2(roundup_pow_of_two(size));
+ map_bits = order_base_2(size);
if (map_bits < TRACING_MAP_BITS_MIN ||
map_bits > TRACING_MAP_BITS_MAX)
ret = -EINVAL;
--
2.43.0