]> git.baikalelectronics.ru Git - kernel.git/commit
tracing: Add length protection to histogram string copies
authorSteven Rostedt (VMware) <rostedt@goodmis.org>
Sun, 14 Nov 2021 18:28:34 +0000 (13:28 -0500)
committerSteven Rostedt (VMware) <rostedt@goodmis.org>
Mon, 15 Nov 2021 02:21:08 +0000 (21:21 -0500)
commit5bbb6b6e575dc883fe0ba8dd917490d3ed5253e9
tree36e95f98f81a2c46e98914cf0e2752e896d66347
parentb8e8ee1bc066fa80caee45767f94b1e2ce7d99b7
tracing: Add length protection to histogram string copies

The string copies to the histogram storage has a max size of 256 bytes
(defined by MAX_FILTER_STR_VAL). Only the string size of the event field
needs to be copied to the event storage, but no more than what is in the
event storage. Although nothing should be bigger than 256 bytes, there's
no protection against overwriting of the storage if one day there is.

Copy no more than the destination size, and enforce it.

Also had to turn MAX_FILTER_STR_VAL into an unsigned int, to keep the
min() comparison of the string sizes of comparable types.

Link: https://lore.kernel.org/all/CAHk-=wjREUihCGrtRBwfX47y_KrLCGjiq3t6QtoNJpmVrAEb1w@mail.gmail.com/
Link: https://lkml.kernel.org/r/20211114132834.183429a4@rorschach.local.home
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Tom Zanussi <zanussi@kernel.org>
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Reviewed-by: Masami Hiramatsu <mhiramat@kernel.org>
Fixes: b2e23b4fbc2a ("tracing/histogram: Do not copy the fixed-size char array field over the field size")
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
include/linux/trace_events.h
kernel/trace/trace_events_hist.c