From nobody Thu Sep 11 20:23:41 2025 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 D4F17C61DA4 for ; Fri, 17 Feb 2023 00:50:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229768AbjBQAuy (ORCPT ); Thu, 16 Feb 2023 19:50:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229541AbjBQAuw (ORCPT ); Thu, 16 Feb 2023 19:50:52 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0679D54D2B for ; Thu, 16 Feb 2023 16:50:41 -0800 (PST) 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 95F836120F for ; Fri, 17 Feb 2023 00:50:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8990C4339B; Fri, 17 Feb 2023 00:50:39 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1pSoxS-000qNB-2j; Thu, 16 Feb 2023 19:50:38 -0500 Message-ID: <20230217005038.662352137@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 16 Feb 2023 19:49:56 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Andrew Morton Subject: [for-next][PATCH 2/5] tracing: Add BUILD_BUG() to make sure stacktrace fits in strings References: <20230217004954.719324747@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: "Steven Rostedt (Google)" The max string length for a histogram variable is 256 bytes. The max depth of a stacktrace is 16. With 8byte words, that's 16 * 8 =3D 128. Which can easily fit in the string variable. The histogram stacktrace is being stored in the string value (with the given max length), with the assumption it will fit. To make sure that this is always the case (in the case that the stack trace depth increases), add a BUILD_BUG_ON() to test this. Link: https://lore.kernel.org/linux-trace-kernel/20230214002418.0103b9e765d= 3e5c374d2aa7d@kernel.org/ Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_events_hist.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_h= ist.c index f21e42ddba69..6cef1def1da5 100644 --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -3119,6 +3119,9 @@ static inline void __update_field_vars(struct tracing= _map_elt *elt, unsigned int i, j, var_idx; u64 var_val; =20 + /* Make sure stacktrace can fit in the string variable length */ + BUILD_BUG_ON((HIST_STACKTRACE_DEPTH + 1) * sizeof(long) >=3D STR_VAR_LEN_= MAX); + for (i =3D 0, j =3D field_var_str_start; i < n_field_vars; i++) { struct field_var *field_var =3D field_vars[i]; struct hist_field *var =3D field_var->var; --=20 2.39.1