]> git.dujemihanovic.xyz Git - linux.git/commit
tracing: Fix print_fields() for __dyn_loc/__rel_loc
authorBeau Belgrave <beaub@linux.microsoft.com>
Wed, 19 Apr 2023 21:41:40 +0000 (14:41 -0700)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Wed, 26 Apr 2023 00:11:26 +0000 (20:11 -0400)
commitc7bdb07902e0b633795372665d0154e7267ecd0e
treef6e8b632585c7f5ff529be4852afb353130f4f1b
parent9872c07b14e5ad3e3a89a7fd43e9488072007118
tracing: Fix print_fields() for __dyn_loc/__rel_loc

Both print_fields() and print_array() do not handle if dynamic data ends
at the last byte of the payload for both __dyn_loc and __rel_loc field
types. For __rel_loc, the offset was off by 4 bytes, leading to
incorrect strings and data being printed out. In print_array() the
buffer pos was missed from being advanced, which results in the first
payload byte being used as the offset base instead of the field offset.

Advance __rel_loc offset by 4 to ensure correct offset and advance pos
to the field offset to ensure correct data is displayed when printing
arrays. Change >= to > when checking if data is in-bounds, since it's
valid for dynamic data to include the last byte of the payload.

Example outputs for event format:
        field:unsigned short common_type;       offset:0;       size:2; signed:0;
        field:unsigned char common_flags;       offset:2;       size:1; signed:0;
        field:unsigned char common_preempt_count;       offset:3;       size:1; signed:0;
        field:int common_pid;   offset:4;       size:4; signed:1;

        field:__rel_loc char text[];  offset:8;      size:4; signed:1;

Output before:
tp_rel_loc: text=<OVERFLOW>

Output after:
tp_rel_loc: text=Test

Link: https://lkml.kernel.org/r/20230419214140.4158-3-beaub@linux.microsoft.com
Fixes: 80a76994b2d8 ("tracing: Add "fields" option to show raw trace event fields")
Reported-by: Doug Cook <dcook@linux.microsoft.com>
Signed-off-by: Beau Belgrave <beaub@linux.microsoft.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
kernel/trace/trace_output.c