Skip to content

Commit b220c04

Browse files
committed
tracing: Check length before giving out the filter buffer
When filters are used by trace events, a page is allocated on each CPU and used to copy the trace event fields to this page before writing to the ring buffer. The reason to use the filter and not write directly into the ring buffer is because a filter may discard the event and there's more overhead on discarding from the ring buffer than the extra copy. The problem here is that there is no check against the size being allocated when using this page. If an event asks for more than a page size while being filtered, it will get only a page, leading to the caller writing more that what was allocated. Check the length of the request, and if it is more than PAGE_SIZE minus the header default back to allocating from the ring buffer directly. The ring buffer may reject the event if its too big anyway, but it wont overflow. Link: https://lore.kernel.org/ath10k/[email protected]/ Cc: [email protected] Fixes: 0fc1b09 ("tracing: Use temp buffer when filtering events") Reported-by: Wen Gong <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 256cfdd commit b220c04

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

kernel/trace/trace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2745,7 +2745,7 @@ trace_event_buffer_lock_reserve(struct trace_buffer **current_rb,
27452745
(entry = this_cpu_read(trace_buffered_event))) {
27462746
/* Try to use the per cpu buffer first */
27472747
val = this_cpu_inc_return(trace_buffered_event_cnt);
2748-
if (val == 1) {
2748+
if ((len < (PAGE_SIZE - sizeof(*entry))) && val == 1) {
27492749
trace_event_setup(entry, type, flags, pc);
27502750
entry->array[0] = len;
27512751
return entry;

0 commit comments

Comments
 (0)