From patchwork Tue Sep 26 03:22:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dinghao Liu X-Patchwork-Id: 13398620 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19C32111B for ; Tue, 26 Sep 2023 03:23:28 +0000 (UTC) X-Greylist: delayed 71822 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 25 Sep 2023 20:23:24 PDT Received: from zg8tmja2lje4os4yms4ymjma.icoremail.net (zg8tmja2lje4os4yms4ymjma.icoremail.net [206.189.21.223]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 87E599D; Mon, 25 Sep 2023 20:23:24 -0700 (PDT) Received: from localhost.localdomain (unknown [10.192.76.118]) by mail-app2 (Coremail) with SMTP id by_KCgBHCrWJThJljucMAQ--.65187S4; Tue, 26 Sep 2023 11:22:54 +0800 (CST) From: Dinghao Liu To: dinghao.liu@zju.edu.cn Cc: Alexander Aring , Stefan Schmidt , Miquel Raynal , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Marcel Holtmann , Harry Morris , linux-wpan@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] [v2] ieee802154: ca8210: Fix a potential UAF in ca8210_probe Date: Tue, 26 Sep 2023 11:22:44 +0800 Message-Id: <20230926032244.11560-1-dinghao.liu@zju.edu.cn> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: by_KCgBHCrWJThJljucMAQ--.65187S4 X-Coremail-Antispam: 1UD129KBjvJXoW7WF4fGFW5ury5Cry5JFW3GFg_yoW8Ww1xpa 10ka4UJryjqF4jga18ArW8Zry5C3WxtayruF95K39293Zxury8tan7AFW3JF45JFWUCa1r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IKE_H4,RCVD_IN_MSPIKE_WL, 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 X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: X-Patchwork-Delegate: kuba@kernel.org If of_clk_add_provider() fails in ca8210_register_ext_clock(), it calls clk_unregister() to release priv->clk and returns an error. However, the caller ca8210_probe() then calls ca8210_remove(), where priv->clk is freed again in ca8210_unregister_ext_clock(). In this case, a use-after-free may happen in the second time we call clk_unregister(). Fix this by removing the first clk_unregister(). Also, priv->clk could be an error code on failure of clk_register_fixed_rate(). Use IS_ERR_OR_NULL to catch this case in ca8210_unregister_ext_clock(). Fixes: ded845a781a5 ("ieee802154: Add CA8210 IEEE 802.15.4 device driver") Signed-off-by: Dinghao Liu --- Changelog: v2: -Remove the first clk_unregister() instead of nulling priv->clk. --- drivers/net/ieee802154/ca8210.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/ieee802154/ca8210.c b/drivers/net/ieee802154/ca8210.c index aebb19f1b3a4..b35c6f59bd1a 100644 --- a/drivers/net/ieee802154/ca8210.c +++ b/drivers/net/ieee802154/ca8210.c @@ -2759,7 +2759,6 @@ static int ca8210_register_ext_clock(struct spi_device *spi) } ret = of_clk_add_provider(np, of_clk_src_simple_get, priv->clk); if (ret) { - clk_unregister(priv->clk); dev_crit( &spi->dev, "Failed to register external clock as clock provider\n" @@ -2780,7 +2779,7 @@ static void ca8210_unregister_ext_clock(struct spi_device *spi) { struct ca8210_priv *priv = spi_get_drvdata(spi); - if (!priv->clk) + if (IS_ERR_OR_NULL(priv->clk)) return of_clk_del_provider(spi->dev.of_node);