tracing: Reject tracefs buffer size values that overflow bytes
PATCH 1/1 tracing: Reject tracefs buffer size values that overflow bytes
From: Samuel Moelius <[email protected]>
tracing_entries_write() accepts a buffer_size_kb value as unsigned long, checks only for zero, then shifts left by 10. On 64-bit, writing 18014398509481984 KB wraps the byte count to zero and the ring buffer resize path accepts it as a tiny buffer instead of rejecting an impossible huge size.
The fix also adds the same pre-scale overflow check to buffer_subbuf_size_write().
--- kernel/trace/trace.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/trace/trace.c +4 -1
@@ -5735,7 +5735,7 @@ tracing_entries_write(struct file *filp, const char __user *ubuf,return ret;/* must have at least 1 entry */ -if (!val) +if (!val || val >ULONG_MAX >>10 )return -EINVAL ;/* value is in KB */
@@ -8206,6 +8206,9 @@ buffer_subbuf_size_write(struct file *filp, const char __user *ubuf,if (ret)return ret; +if (!val || val >ULONG_MAX /1024 ) +return -EINVAL ; + val *=1024 ;/* value passed in is in KB */ pages =DIV_ROUND_UP (val,PAGE_SIZE );
Signature · 1 line
2.43.0
Steven Rostedt
maintainerQuoted 10 lines · On Tue, 2 Jun 2026 18:43:34 +0000 Sam Moelius <[email protected]>…
From: Samuel Moelius <[email protected]>
tracing_entries_write()accepts abuffer_size_kbvalue asunsigned long, checks only for zero, then shifts left by 10. On 64-bit, writing18014398509481984KB wraps the byte count to zero and the ring buffer resize path accepts it as a tiny buffer instead of rejecting an impossible huge size.The fix also adds the same pre-scale overflow check to
buffer_subbuf_size_write().
Honestly, enter stupid values, get stupid results.
I don't think this is necessary. Nothing breaks but the person may get confused by being confused by the confusing entries they make.
-- Steve