]> git.baikalelectronics.ru Git - kernel.git/commit
tracing: Check length before giving out the filter buffer
authorSteven Rostedt (VMware) <rostedt@goodmis.org>
Wed, 10 Feb 2021 16:53:22 +0000 (11:53 -0500)
committerSteven Rostedt (VMware) <rostedt@goodmis.org>
Thu, 11 Feb 2021 19:23:37 +0000 (14:23 -0500)
commit1183ece32af91b8ac7b2cdf809e935081a52e641
tree33d5cd03fa6e48c31266ae3104c0f2f1bc4ca60c
parenteffd19b9d72b11748c0a1f8dea7645921da584eb
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/1612839593-2308-1-git-send-email-wgong@codeaurora.org/
Cc: stable@vger.kernel.org
Fixes: 17619fe65e505 ("tracing: Use temp buffer when filtering events")
Reported-by: Wen Gong <wgong@codeaurora.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
kernel/trace/trace.c