Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2253987iof; Wed, 8 Jun 2022 00:35:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwR3979VkgNqMix8HYQd2U+NKCVrBYWyikPNAdORISBrMWQyjCOIAM81fxuKYIk5n9PSGAY X-Received: by 2002:a17:90b:341:b0:1e0:cf43:df4f with SMTP id fh1-20020a17090b034100b001e0cf43df4fmr36185085pjb.126.1654673714926; Wed, 08 Jun 2022 00:35:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654673714; cv=none; d=google.com; s=arc-20160816; b=yYZ9J2k3jQ3+g0UfKC/6elwONlmmW5HbHs2yNUPVzRlOYIFMO571ylV4Q6/qbnxkeB nY4434NsA0+6LJkHOSgWbsMxYcnxKvGDMsDGuLpYXFfUbYkmuZyj0sYz2ZynAx+qYKA3 LzhUnN7TsMza43LxDB1iJYUy2T4nEfkrXvJFXpneMbF//QNFoYiUIdax2S1/+twKrWjW 6d5WbIWtQsF2hckFBLMuVBcDO0TqblrxAkp7wkBOCjyqwZFFVIBNF7tH2Z98e+F8xYfm maEHPOec5s8TX5BxD6NHvzacd8CaWo+ADoY2/Q7hfSX+Pu75a46uOLX7YM0MN7fSq9o1 l9tA== 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=YVW3+qJ6QYS6N9NPZBW0o58yuFfjVMOC01j6k2sB3rY=; b=Mx+LLbyvIpvCztAYoGD3X0S6epp0IOpSu1vZ6cfOi3StNivHiiU7oxb/S/GbkALw3k aO7u+xuyvpZF+sPSy0HTcSJsjqLNIMWdWAGUrTS9wxKccUAyrQHjSUFbZYnZIGhaTHSk r15ppVFsj2RQfw/4RfWiE6XaFsc3QK4b4xT+8ruou/aw4ypr9s6slAR1xtCkFOqOByNV 71pyFq/9poUHDocutYUU0J2WDHgMnq2CThRPgGpQKfl/hTGyZI3BLUCMR3hQGzCN5uVw ZQ70w8AbOQavu+QZlAv1eYfIDGJR6Zs/lmaBu52Y9BJpMFHU+r6KvGQ2fhvlqQ1GKTrj eS4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HpchsDhF; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id bi10-20020a170902bf0a00b0015d168a0c7fsi27055518plb.94.2022.06.08.00.35.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 00:35:14 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HpchsDhF; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 76D0122EFFD; Wed, 8 Jun 2022 00:07:14 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1388951AbiFHB2F (ORCPT + 99 others); Tue, 7 Jun 2022 21:28:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379706AbiFGWRd (ORCPT ); Tue, 7 Jun 2022 18:17:33 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C4FA2629F3; Tue, 7 Jun 2022 12:20:29 -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 ams.source.kernel.org (Postfix) with ESMTPS id 32D89B823D4; Tue, 7 Jun 2022 19:20:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A1582C385A2; Tue, 7 Jun 2022 19:20:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629605; bh=JxY/VihCn/5qC+b37PZXge5+aQpv5S/03KtLqKxk3nM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HpchsDhFe1XYzDN+iO2UUJ4GT+VwFmiUsvF37wQRJQ+yLqpucOGbr4rch7YoldmCy jxTeaBNsw43DRoW7YJ2G81GzADZHUh/9RAAH2207Mdy+aEa01L/feIq4ptzg111cvn f8tZC9b2iF+CSOhxum008SUZ6bGA1UK67jk+ShXI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Masami Hiramatsu , Tom Zanussi , Keita Suzuki , "Steven Rostedt (Google)" Subject: [PATCH 5.18 750/879] tracing: Fix potential double free in create_var_ref() Date: Tue, 7 Jun 2022 19:04:28 +0200 Message-Id: <20220607165024.630935231@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Keita Suzuki commit 99696a2592bca641eb88cc9a80c90e591afebd0f upstream. In create_var_ref(), init_var_ref() is called to initialize the fields of variable ref_field, which is allocated in the previous function call to create_hist_field(). Function init_var_ref() allocates the corresponding fields such as ref_field->system, but frees these fields when the function encounters an error. The caller later calls destroy_hist_field() to conduct error handling, which frees the fields and the variable itself. This results in double free of the fields which are already freed in the previous function. Fix this by storing NULL to the corresponding fields when they are freed in init_var_ref(). Link: https://lkml.kernel.org/r/20220425063739.3859998-1-keitasuzuki.park@sslab.ics.keio.ac.jp Fixes: 067fe038e70f ("tracing: Add variable reference handling to hist triggers") CC: stable@vger.kernel.org Reviewed-by: Masami Hiramatsu Reviewed-by: Tom Zanussi Signed-off-by: Keita Suzuki Signed-off-by: Steven Rostedt (Google) Signed-off-by: Greg Kroah-Hartman --- kernel/trace/trace_events_hist.c | 3 +++ 1 file changed, 3 insertions(+) --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -2093,8 +2093,11 @@ static int init_var_ref(struct hist_fiel return err; free: kfree(ref_field->system); + ref_field->system = NULL; kfree(ref_field->event_name); + ref_field->event_name = NULL; kfree(ref_field->name); + ref_field->name = NULL; goto out; }