Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3124636rwb; Mon, 15 Aug 2022 18:44:29 -0700 (PDT) X-Google-Smtp-Source: AA6agR6LLj4HdmVibBbVGvCPg3PV3Zrid4D/nobG6yn68+Z3dZ8bovP5cHyMK6bX9kBubneTz1s/ X-Received: by 2002:a17:902:b20a:b0:172:7385:ea63 with SMTP id t10-20020a170902b20a00b001727385ea63mr5374568plr.54.1660614269337; Mon, 15 Aug 2022 18:44:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660614269; cv=none; d=google.com; s=arc-20160816; b=lgXwJ9wX4GHgjUiIeCYoqF8Zj588HV3W1dZhTzPUGkNEFS8aMYlp9UN84YUmOyBrNc D7IQJyZMhhmas3DIurCHkqlJyRJvDzVGsfF8JYNwgRUWIrO4v59cFUUV/0rcwuwIP3Gh MYuZnntxsfPcdPEZ7ByBZ9RilPZgvF5hO0R2C0rlHGGQob7CmAq+SuDQc5znP4FkRRnL jE4Z2MDtL2J6qseicBKKpdsTyM4UUTvz9ywjkmIpeIvygYTJA/dC7JM4VOo0gwGHuaH3 CCkSr0MMa2NluT0rqar+dwhZGfuzhsDE3WwuEUDoKx3yiQeNvbXublInMibkP5ScuXOB 90eQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=sZbeOV3wbbWvwa5qSEpA/UWm24RzThh6hpzQ/VN0CwE=; b=B515ARQpuqeiFmu4QCmizwvfvZw7n6VD3nsMY1EXaVlKxEqU/hW0mpmkE3FH/dS3x0 Z/JbF8lSt6AHctTsOOjXvUZvdcDOeQdFFEldw0DJpXfHzuVX8IXx8lTX6H76yz75voVr cXyW9x6RAdzIPQfRNPlETXZIelqPTvu7fj02GQaZasXmORh9LX4K71NS8iWUEX8zFjD/ mXx9RDokZVY+ckGjDPsKN4RgkE2R6fbxI0GQZ/Kqwku/vsplp4/M6mbPIou6ERoRRwBx lKbuMukBMVz6PB0Z+UBtWSh6F89GVEZK7OnbdaLobV0OWuD/+uvmAg3UIm3LfTiVPY+b CTHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sgORQLLw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b3-20020a170903228300b001708e1bb3b8si13234874plh.335.2022.08.15.18.44.18; Mon, 15 Aug 2022 18:44:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sgORQLLw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354406AbiHOXpN (ORCPT + 99 others); Mon, 15 Aug 2022 19:45:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354262AbiHOXlo (ORCPT ); Mon, 15 Aug 2022 19:41:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 530FDA187; Mon, 15 Aug 2022 13:11:28 -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 936F66077B; Mon, 15 Aug 2022 20:11:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99A39C433D6; Mon, 15 Aug 2022 20:11:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660594287; bh=ee2XvZp7qZ5NKC+jn6QmcSc84kcU65loMihwoesT/Xw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sgORQLLwqSN3H7Jwafe7gwiNMZx6WWOhzUHs1r8H7xsqkmXKxDSaZXNsqGxr3O0nT +Jd4s9fFdSnxeBPaAI9MHMPjvgELfoNTefN38Upa3L8Pmx1f73g+a67/7QrfGQu33T RzLYg3jfbwXSEK+zFHIUL5egDzsBsFDyv7AjVDRs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arun Easi , "Steven Rostedt (Google)" Subject: [PATCH 5.18 1083/1095] tracing: Use a copy of the va_list for __assign_vstr() Date: Mon, 15 Aug 2022 20:08:02 +0200 Message-Id: <20220815180513.836978465@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Steven Rostedt (Google) commit 3a2dcbaf4d31023106975d6ae75b6df080c454cb upstream. If an instance of tracing enables the same trace event as another instance, or the top level instance, or even perf, then the va_list passed into some tracepoints can be used more than once. As va_list can only be traversed once, this can cause issues: # cat /sys/kernel/tracing/instances/qla2xxx/trace cat-56106 [012] ..... 2419873.470098: ql_dbg_log: qla2xxx [0000:05:00.0]-1054:14: Entered (null). cat-56106 [012] ..... 2419873.470101: ql_dbg_log: qla2xxx [0000:05:00.0]-1000:14: Entered ×+<96>²Ü<98>^H. cat-56106 [012] ..... 2419873.470102: ql_dbg_log: qla2xxx [0000:05:00.0]-1006:14: Prepare to issue mbox cmd=0xde589000. # cat /sys/kernel/tracing/trace cat-56106 [012] ..... 2419873.470097: ql_dbg_log: qla2xxx [0000:05:00.0]-1054:14: Entered qla2x00_get_firmware_state. cat-56106 [012] ..... 2419873.470100: ql_dbg_log: qla2xxx [0000:05:00.0]-1000:14: Entered qla2x00_mailbox_command. cat-56106 [012] ..... 2419873.470102: ql_dbg_log: qla2xxx [0000:05:00.0]-1006:14: Prepare to issue mbox cmd=0x69. The instance version is corrupted because the top level instance iterated the va_list first. Use va_copy() in the __assign_vstr() macro to make sure that each trace event for each use case gets a fresh va_list. Link: https://lore.kernel.org/all/259d53a5-958e-6508-4e45-74dba2821242@marvell.com/ Link: https://lkml.kernel.org/r/20220719182004.21daa83e@gandalf.local.home Fixes: 0563231f93c6d ("tracing/events: Add __vstring() and __assign_vstr() helper macros") Reported-by: Arun Easi Signed-off-by: Steven Rostedt (Google) Signed-off-by: Greg Kroah-Hartman --- include/trace/stages/stage6_event_callback.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/trace/stages/stage6_event_callback.h b/include/trace/stages/stage6_event_callback.h index 0f51f6b3ab70..3c554a585320 100644 --- a/include/trace/stages/stage6_event_callback.h +++ b/include/trace/stages/stage6_event_callback.h @@ -40,7 +40,12 @@ #undef __assign_vstr #define __assign_vstr(dst, fmt, va) \ - vsnprintf(__get_str(dst), TRACE_EVENT_STR_MAX, fmt, *(va)) + do { \ + va_list __cp_va; \ + va_copy(__cp_va, *(va)); \ + vsnprintf(__get_str(dst), TRACE_EVENT_STR_MAX, fmt, __cp_va); \ + va_end(__cp_va); \ + } while (0) #undef __bitmask #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1) -- 2.37.2