Skip to content

Commit eca344a

Browse files
committed
tracing: Have trace event string test handle zero length strings
If a trace event has in its TP_printk(): "%*.s", len, len ? __get_str(string) : NULL It is perfectly valid if len is zero and passing in the NULL. Unfortunately, the runtime string check at time of reading the trace sees the NULL and flags it as a bad string and produces a WARN_ON(). Handle this case by passing into the test function if the format has an asterisk (star) and if so, if the length is zero, then mark it as safe. Link: https://lore.kernel.org/all/YjsWzuw5FbWPrdqq@bfoster/ Cc: [email protected] Reported-by: Brian Foster <[email protected]> Tested-by: Brian Foster <[email protected]> Fixes: 9a6944f ("tracing: Add a verifier to check string pointers for trace events") Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 78cbc65 commit eca344a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

kernel/trace/trace.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3663,12 +3663,17 @@ static char *trace_iter_expand_format(struct trace_iterator *iter)
36633663
}
36643664

36653665
/* Returns true if the string is safe to dereference from an event */
3666-
static bool trace_safe_str(struct trace_iterator *iter, const char *str)
3666+
static bool trace_safe_str(struct trace_iterator *iter, const char *str,
3667+
bool star, int len)
36673668
{
36683669
unsigned long addr = (unsigned long)str;
36693670
struct trace_event *trace_event;
36703671
struct trace_event_call *event;
36713672

3673+
/* Ignore strings with no length */
3674+
if (star && !len)
3675+
return true;
3676+
36723677
/* OK if part of the event data */
36733678
if ((addr >= (unsigned long)iter->ent) &&
36743679
(addr < (unsigned long)iter->ent + iter->ent_size))
@@ -3854,7 +3859,7 @@ void trace_check_vprintf(struct trace_iterator *iter, const char *fmt,
38543859
* instead. See samples/trace_events/trace-events-sample.h
38553860
* for reference.
38563861
*/
3857-
if (WARN_ONCE(!trace_safe_str(iter, str),
3862+
if (WARN_ONCE(!trace_safe_str(iter, str, star, len),
38583863
"fmt: '%s' current_buffer: '%s'",
38593864
fmt, show_buffer(&iter->seq))) {
38603865
int ret;

0 commit comments

Comments
 (0)