Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4962189rdb; Tue, 12 Dec 2023 14:48:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IFHozDFYUoC/EabD+Nj+EQT102RThb0slF7NMlnsfgeSJLyEIlZigdRd8p8lL3TUQHG/gDt X-Received: by 2002:a05:6870:5251:b0:1fa:eb76:c378 with SMTP id o17-20020a056870525100b001faeb76c378mr8827804oai.36.1702421288510; Tue, 12 Dec 2023 14:48:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702421288; cv=none; d=google.com; s=arc-20160816; b=dELHfFvHAA44l6ZM612ciQT1JAN9d0DsCpT0Xg9uZrgIqXjQm4y6ADoM4mfNwY15cG 4MzZDbo7MvFchGocjFqkO3YEsm2+gPa9HBIcMyaGMjWS/roT747EX5vDGVEi7oBuh8t0 CzWxqOTnOcNV3l8eDD2ID5wf6bekLzxrze+jKtRGdryGQkbpEWpaXD7jUOAN2uqLtgVo T+aKoTL04FxVKqp8Qe7o4cGCqqTz4GUM7gCMlXBINJ9SHR0kAv+uOoGRR+s7spsbYEeZ bAo3JiLT0wZTjXlwdNj6k+wQUJjC+tkpTitCb2MsWQwdNGgsBD3givaVqNXgL2yu7WZ8 Z1oA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=iYBrCpf6AKFsRx4zEXC2Yo4AQJYVOq8ve4jdTmJbYXE=; fh=M39LLsJCzO7NrqA7jp+p/Wrw6XX0lv7COmgcBtCDj4Y=; b=FUPJlYGuIkygS6zGakRjcp66SyFKVt9yirqeX7IAs3O8ZFoLeE/ioB/OyHFXYq1MmY 0P29S6m5y1XTh2RCVMiLgVjPaujjS6McxwAgVKD5/5nXRQZSSFPaDubc6Mr0jVvY6uHI uxPQ1MnMhU/LIEeNvx+3R0JJHsszls7k6JPh/KsC0a8q5lXcKmMUrigs88Iu4my82535 t040npnXMa/5XRUPfydhdk2vHdTLdNlvKs3bM67gezQ9IMCmUY8ef2i20IkDtfWe0pw5 wjYeronBW507b73HZj0BBhXe/6O2Vw7fX9/JcfRknOn5x7ebp03zx4ojVZsARxP28B70 eZmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UQoT7kHu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id bw9-20020a056a02048900b005c674eb1cb4si8567677pgb.477.2023.12.12.14.48.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 14:48:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UQoT7kHu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id E811D804C66C; Tue, 12 Dec 2023 14:48:05 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232173AbjLLWrp (ORCPT + 99 others); Tue, 12 Dec 2023 17:47:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231481AbjLLWrp (ORCPT ); Tue, 12 Dec 2023 17:47:45 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43C36AA for ; Tue, 12 Dec 2023 14:47:51 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40E35C433C7; Tue, 12 Dec 2023 22:47:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702421270; bh=fTzQszjJZI1SU83F2DPicXFge7TTPi0j6QJoBbVl1TI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=UQoT7kHuV6vYeIp2c9J97rMAU/aseRE7+I8zj2u86LxOKPQN1l4BJR9RdO27xHGKh bAMyPCc/73mlXUi9IKA+ZnB9OzETYfDcVhTlammymBEyJHwM15dEhUzojsa5nolcjr yWtWXwtFNhy5mzf7KKrLDLZ2KkOWER5le/4pWK0RCxipo+VHPi0UGCKgcp0wyHR1uo xbNi7X8Ugo4Opw8qTpYwfLVUrUslrclsAr0xLXyNOWR05u+TO9w5++hx59S5vO8Y2T +eFu5FGg/fyWaT4J5LYjd0FpZ72mODhtnIubXfkRVjFLSnnZfwXpH9bg/jpNp9jinI yPVerbXa1ysiw== Date: Wed, 13 Dec 2023 07:47:46 +0900 From: Masami Hiramatsu (Google) To: Steven Rostedt Cc: LKML , Linux Trace Kernel , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers Subject: Re: [PATCH] tracing: Add size check when printing trace_marker output Message-Id: <20231213074746.cd2dbd703bd19fe791c5d44a@kernel.org> In-Reply-To: <20231212084444.4619b8ce@gandalf.local.home> References: <20231212084444.4619b8ce@gandalf.local.home> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 12 Dec 2023 14:48:06 -0800 (PST) On Tue, 12 Dec 2023 08:44:44 -0500 Steven Rostedt wrote: > From: "Steven Rostedt (Google)" > > If for some reason the trace_marker write does not have a nul byte for the > string, it will overflow the print: > > trace_seq_printf(s, ": %s", field->buf); > > The field->buf could be missing the nul byte. To prevent overflow, add the > max size that the buf can be by using the event size and the field > location. > > int max = iter->ent_size - offsetof(struct print_entry, buf); > > trace_seq_printf(s, ": %*s", max, field->buf); > This looks good to me. Reviewed-by: Masami Hiramatsu (Google) Thanks! > Signed-off-by: Steven Rostedt (Google) > --- > kernel/trace/trace_output.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c > index d8b302d01083..e11fb8996286 100644 > --- a/kernel/trace/trace_output.c > +++ b/kernel/trace/trace_output.c > @@ -1587,11 +1587,12 @@ static enum print_line_t trace_print_print(struct trace_iterator *iter, > { > struct print_entry *field; > struct trace_seq *s = &iter->seq; > + int max = iter->ent_size - offsetof(struct print_entry, buf); > > trace_assign_type(field, iter->ent); > > seq_print_ip_sym(s, field->ip, flags); > - trace_seq_printf(s, ": %s", field->buf); > + trace_seq_printf(s, ": %*s", max, field->buf); > > return trace_handle_return(s); > } > @@ -1600,10 +1601,11 @@ static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags, > struct trace_event *event) > { > struct print_entry *field; > + int max = iter->ent_size - offsetof(struct print_entry, buf); > > trace_assign_type(field, iter->ent); > > - trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf); > + trace_seq_printf(&iter->seq, "# %lx %*s", field->ip, max, field->buf); > > return trace_handle_return(&iter->seq); > } > -- > 2.42.0 > -- Masami Hiramatsu (Google)