From nobody Thu Feb 12 07:38:43 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51520C77B78 for ; Wed, 26 Apr 2023 17:18:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234902AbjDZRSF (ORCPT ); Wed, 26 Apr 2023 13:18:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234698AbjDZRRw (ORCPT ); Wed, 26 Apr 2023 13:17:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C07D4659C for ; Wed, 26 Apr 2023 10:17:51 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 561556307A for ; Wed, 26 Apr 2023 17:17:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B93DDC433A0; Wed, 26 Apr 2023 17:17:50 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1prim5-005KYl-2a; Wed, 26 Apr 2023 13:17:49 -0400 Message-ID: <20230426171749.616376240@goodmis.org> User-Agent: quilt/0.66 Date: Wed, 26 Apr 2023 13:17:06 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , Doug Cook , Beau Belgrave Subject: [for-next][PATCH 03/11] tracing: Fix print_fields() for __dyn_loc/__rel_loc References: <20230426171703.202523909@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Beau Belgrave 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 >=3D 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; sig= ned:0; field:unsigned char common_flags; offset:2; size:1; sig= ned:0; field:unsigned char common_preempt_count; offset:3; siz= e: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=3D Output after: tp_rel_loc: text=3DTest 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 Signed-off-by: Beau Belgrave Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_output.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c index 780c6971c944..952cc8aa8e59 100644 --- a/kernel/trace/trace_output.c +++ b/kernel/trace/trace_output.c @@ -819,13 +819,15 @@ static void print_array(struct trace_iterator *iter, = void *pos, len =3D *(int *)pos >> 16; =20 if (field) - offset +=3D field->offset; + offset +=3D field->offset + sizeof(int); =20 - if (offset + len >=3D iter->ent_size) { + if (offset + len > iter->ent_size) { trace_seq_puts(&iter->seq, ""); return; } =20 + pos =3D (void *)iter->ent + offset; + for (i =3D 0; i < len; i++, pos++) { if (i) trace_seq_putc(&iter->seq, ','); @@ -861,9 +863,9 @@ static void print_fields(struct trace_iterator *iter, s= truct trace_event_call *c len =3D *(int *)pos >> 16; =20 if (field->filter_type =3D=3D FILTER_RDYN_STRING) - offset +=3D field->offset; + offset +=3D field->offset + sizeof(int); =20 - if (offset + len >=3D iter->ent_size) { + if (offset + len > iter->ent_size) { trace_seq_puts(&iter->seq, ""); break; } --=20 2.39.2