From patchwork Fri Dec 23 14:40:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Khoroshilov X-Patchwork-Id: 36287 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp358583wrn; Fri, 23 Dec 2022 06:50:57 -0800 (PST) X-Google-Smtp-Source: AMrXdXtJTf6xvUVrOiH7WMI4k6RjT24uRcsn8BM3DvZ4tRjnAaqa578Pg9z7EZzENC4snCW2QCyK X-Received: by 2002:a05:6402:1f0b:b0:46c:f903:7ea3 with SMTP id b11-20020a0564021f0b00b0046cf9037ea3mr8450647edb.32.1671807056930; Fri, 23 Dec 2022 06:50:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671807056; cv=none; d=google.com; s=arc-20160816; b=SqXp4z52VEv1LB95RQbg10bZ+2ISNseiUEDtNGD2e3PopalFT1OP9j3QVm2ovQ2uvy 6HFqmPXfmZFT0FhptYF3P/OWIwR2EZJgFi59hqzB9aMklzdky6aswg014Hb3BCB0v28n PRnfKjp9vbl7lxep5D2l27kgjFlCP4NMlRzVTp/57v8ITsxxS85UmDfGI5g7sAQLqmjr upb7spk3UNXis2oBrb99ItKiA2sIYQ+v/zdDT4OHNNo0ZCl2wuJl4w89w4JH3onS0qLY jddS1h7XCLYbZOaeM9QffEPZtq5RHam2HQ1Lfmy5jdBm5WM6kd1jxqpp0m02LH1mHLA2 OlPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=EhcMZIauTuOelwIwzHF+SwckBgMoMMbhnIK4cfP049Y=; b=0uWSOdfJdi0Hz1WWTx0rCjNAOUVuM5igE7jv6RMorQMV8DZpd9+NKQzx88PWftGoUo rhtQe739xijURIepDaFSeZoEd2hhpn4y6Betgz6EWgfZogVUhGNmUGA5/nHncVY/dG+S NhoEmrRbRZ3UhHlORbhvWRzCnSa9cVT87gBQ/G++Kf/daJvpvISFiT/GSWrSODVfx0qb 8DsriMbmrRSb4A7dpxb70f4r5JrAgRJxR9GTmIzz2NjW1hTX5I5hU+h1MxKXR/MUzwuN 4rdlLLr5yq3Bw3b+KfGPaDtxfgz2HmcRFaRRx5RLd6QdnAU9cyOE3ib3xkhkfVP1o54P 20uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=ZN2d9wc1; 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=ispras.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m5-20020a056402430500b0047d9b861edbsi3153268edc.227.2022.12.23.06.50.33; Fri, 23 Dec 2022 06:50:56 -0800 (PST) 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=@ispras.ru header.s=default header.b=ZN2d9wc1; 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=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236292AbiLWOkf (ORCPT + 99 others); Fri, 23 Dec 2022 09:40:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230239AbiLWOkd (ORCPT ); Fri, 23 Dec 2022 09:40:33 -0500 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E16837FA8; Fri, 23 Dec 2022 06:40:31 -0800 (PST) Received: from hednb3.intra.ispras.ru (unknown [10.10.2.52]) by mail.ispras.ru (Postfix) with ESMTPSA id CF5DE40737B8; Fri, 23 Dec 2022 14:40:25 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru CF5DE40737B8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1671806425; bh=EhcMZIauTuOelwIwzHF+SwckBgMoMMbhnIK4cfP049Y=; h=From:To:Cc:Subject:Date:In-Reply-To:From; b=ZN2d9wc1csXf2o6f6UXQjMhGVzmhPifJTTac+l5OK9RFPfW/tHUi7BOPKbpCFpxuE nf5dP9/VM50u7tB7FW6Kvqeb3qo8czZAnixVYqM+4BFrheXEP79DzXdsNffmPu0FJm 6O6zz7gJ/u4U1mtdTSHbD7SOeYqmvvhtlWiUhoJA= From: Alexey Khoroshilov To: Geert Uytterhoeven , Chris Brandt Cc: Alexey Khoroshilov , Michael Turquette , Stephen Boyd , linux-renesas-soc@vger.kernel.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org Subject: [PATCH v2] clk: renesas: cpg-mssr: Fix use after free if cpg_mssr_common_init() failed Date: Fri, 23 Dec 2022 17:40:17 +0300 Message-Id: <1671806417-32623-1-git-send-email-khoroshilov@ispras.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752955576447708402?= X-GMAIL-MSGID: =?utf-8?q?1753016756881364904?= If cpg_mssr_common_init() fails after assigning priv to global variable cpg_mssr_priv, it deallocates priv, but cpg_mssr_priv keeps dangling pointer that potentially can be used later. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: 1f7db7bbf031 ("clk: renesas: cpg-mssr: Add early clock support") Signed-off-by: Alexey Khoroshilov Reviewed-by: Geert Uytterhoeven --- v2: Move cpg_mssr_priv assignment just before return 0; instead of clearing it as Geert Uytterhoeven suggested. drivers/clk/renesas/renesas-cpg-mssr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/clk/renesas/renesas-cpg-mssr.c b/drivers/clk/renesas/renesas-cpg-mssr.c index 1a0cdf001b2f..5dce9779324d 100644 --- a/drivers/clk/renesas/renesas-cpg-mssr.c +++ b/drivers/clk/renesas/renesas-cpg-mssr.c @@ -989,7 +989,6 @@ static int __init cpg_mssr_common_init(struct device *dev, goto out_err; } - cpg_mssr_priv = priv; priv->num_core_clks = info->num_total_core_clks; priv->num_mod_clks = info->num_hw_mod_clks; priv->last_dt_core_clk = info->last_dt_core_clk; @@ -1019,6 +1018,8 @@ static int __init cpg_mssr_common_init(struct device *dev, if (error) goto out_err; + cpg_mssr_priv = priv; + return 0; out_err: