Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tracing: Add a helper function to handle the dereference arg in verifier

Add a helper function called handle_dereference_arg() to replace the logic
that is identical in two locations of test_event_printk().

Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Link: https://lore.kernel.org/20250507191703.5dd8a61d@gandalf.local.home
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

+20 -10
+20 -10
kernel/trace/trace_events.c
··· 400 400 return true; 401 401 } 402 402 403 + static void handle_dereference_arg(const char *arg_str, u64 string_flags, int len, 404 + u64 *dereference_flags, int arg, 405 + struct trace_event_call *call) 406 + { 407 + if (string_flags & (1ULL << arg)) { 408 + if (process_string(arg_str, len, call)) 409 + *dereference_flags &= ~(1ULL << arg); 410 + } else if (process_pointer(arg_str, len, call)) 411 + *dereference_flags &= ~(1ULL << arg); 412 + else 413 + pr_warn("TRACE EVENT ERROR: Bad dereference argument: '%.*s'\n", 414 + len, arg_str); 415 + } 416 + 403 417 /* 404 418 * Examine the print fmt of the event looking for unsafe dereference 405 419 * pointers using %p* that could be recorded in the trace event and ··· 577 563 } 578 564 579 565 if (dereference_flags & (1ULL << arg)) { 580 - if (string_flags & (1ULL << arg)) { 581 - if (process_string(fmt + start_arg, e - start_arg, call)) 582 - dereference_flags &= ~(1ULL << arg); 583 - } else if (process_pointer(fmt + start_arg, e - start_arg, call)) 584 - dereference_flags &= ~(1ULL << arg); 566 + handle_dereference_arg(fmt + start_arg, string_flags, 567 + e - start_arg, 568 + &dereference_flags, arg, call); 585 569 } 586 570 587 571 start_arg = i; ··· 590 578 } 591 579 592 580 if (dereference_flags & (1ULL << arg)) { 593 - if (string_flags & (1ULL << arg)) { 594 - if (process_string(fmt + start_arg, i - start_arg, call)) 595 - dereference_flags &= ~(1ULL << arg); 596 - } else if (process_pointer(fmt + start_arg, i - start_arg, call)) 597 - dereference_flags &= ~(1ULL << arg); 581 + handle_dereference_arg(fmt + start_arg, string_flags, 582 + i - start_arg, 583 + &dereference_flags, arg, call); 598 584 } 599 585 600 586 /*