From patchwork Wed Apr 19 14:23:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 13216972 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CE023C6FD18 for ; Wed, 19 Apr 2023 14:23:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Subject:Cc:To: From:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=As6Zc7Wp9F9aCo0KBq819D75V94WWQExpxUUunNRH/k=; b=XyuvfMUcXcwLGk wmL/ShE9qZaK+XdXOfwrRW6qGjKCyJ7WVU+CJa4etSgW+HxyQSdoKSIFI9p4jj+3FOgmEUbzj21LH kaTUx0diWJ4wHQUB0N6nlg7h1byk2fb1GcrJI69Faf6xYUHihJ7z4/A9lPStrmTgOpOKJU1av/8cN c3DVUWl9JtPkWjJTfowntRQXJtzgrV3mFCVQBeLFSIbJ2uwVj6wjFirrx7nBPlynZWV32p7O6u5Yc gekyvrlkVZ7kzU+9RNvwfb5m2IpG2eRZECueLnCM6ctsISfcnwlW/eurBjHHjIHh4dsmNcjr/A0KY 0r82I9eIYUbX60uoDQpQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pp8iD-005eEj-2x; Wed, 19 Apr 2023 14:23:09 +0000 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pp8iB-005eBT-0S for linux-arm-kernel@lists.infradead.org; Wed, 19 Apr 2023 14:23:08 +0000 Received: by mail-wm1-x330.google.com with SMTP id q5so17196862wmo.4 for ; Wed, 19 Apr 2023 07:23:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681914185; x=1684506185; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=/XcbEMF2wS+NEiOe1W+U7oicROXrfzxaAv5byhv5AaM=; b=PcOAtQKUXeuQXgP4RP0Npp16jyTJYWyIpDecFJs2Rc50CfnD4cKH19lAt/x1AYm/SM a/p3UimpCwrzD+dmnP+tK+9sadz+jSAB9jM+OSFW2TJgXIgRa7ROTNpB4Pal2ArWD00l eefvEWQzWNQTqawLq7ujoDx9egy+HiBtI8vlppMGYWc4w+ryB2IEM13fDyzfeaDzdbpI PauWnpRu5RZ1ivOIt7tnxNkmRHJhTd3uXu3LUeinzP1UW77W8J/WoW0MwZfTr6g8pfuu uw8A6adglv6YPx2jO30lnuvuRr5oJeP54dltCO5wSVzRVFF/iWpr1++Fup6UNOrDGB3w 8zig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681914185; x=1684506185; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/XcbEMF2wS+NEiOe1W+U7oicROXrfzxaAv5byhv5AaM=; b=iwR7snpWPB/n6XQmpLwQH0WYkdV5vcwDs0LvI+3VVzWn7ouMEnmTHdMp/rHdUIexpV h8H//7XpffhDykGzp4OqqyRwT0mLCdogBf+tQCCPFcK6UJ5H70cKN2DcRTmzUdvGk9Id XvhOFtgmPALytbrPsU0t7WQ3SMXOFZi6VDN2xsIlV4MQIjbABzzAi9OQnNp515GTXDzA pLkXAr0kM3LCkGkUmG0asse1LsEHCaJ2VhB8Gu/YYZz26xdATlrClUV7woz+Bm2wMGSq 9Ot+7ZKs41wGyFDSb9C+RRxrMDDEdJIpeRmlFTytTPK6kfsfkViLtxmS0zWnw8Ef0edz LhDw== X-Gm-Message-State: AAQBX9eRsVi5xiv6+v4JLZvz8cYN64oTNvTE6Yj/PdMeyRJUVDlQV2J7 OqGYJxAjY/3DlVmQS8ab+9RNhg== X-Google-Smtp-Source: AKy350b1WMulog8jUcFSnfvv3joSXcZ4nJGc5I/rUk7fB5Yu5Dj/J1lBRuTlRNJ+wGAKXKJuYJ4fig== X-Received: by 2002:a1c:7c03:0:b0:3f1:7a50:dd66 with SMTP id x3-20020a1c7c03000000b003f17a50dd66mr4782095wmc.27.1681914185353; Wed, 19 Apr 2023 07:23:05 -0700 (PDT) Received: from localhost ([102.36.222.112]) by smtp.gmail.com with ESMTPSA id d10-20020a1c730a000000b003ee63fe5203sm2303590wmb.36.2023.04.19.07.23.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 07:23:04 -0700 (PDT) Date: Wed, 19 Apr 2023 17:23:01 +0300 From: Dan Carpenter To: Dong Aisheng Cc: Abel Vesa , Peng Fan , Michael Turquette , Stephen Boyd , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel-janitors@vger.kernel.org Subject: [PATCH] clk: imx: scu: use _safe list iterator to avoid a use after free Message-ID: <0793fbd1-d2b5-4ec2-9403-3c39343a3e2d@kili.mountain> MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email haha only kidding X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230419_072307_182492_D9FC2FAC X-CRM114-Status: GOOD ( 14.46 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This loop is freeing "clk" so it needs to use list_for_each_entry_safe(). Otherwise it dereferences a freed variable to get the next item on the loop. Fixes: 77d8f3068c63 ("clk: imx: scu: add two cells binding support") Signed-off-by: Dan Carpenter Reviewed-by: Abel Vesa --- drivers/clk/imx/clk-scu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/clk/imx/clk-scu.c b/drivers/clk/imx/clk-scu.c index 1e6870f3671f..db307890e4c1 100644 --- a/drivers/clk/imx/clk-scu.c +++ b/drivers/clk/imx/clk-scu.c @@ -707,11 +707,11 @@ struct clk_hw *imx_clk_scu_alloc_dev(const char *name, void imx_clk_scu_unregister(void) { - struct imx_scu_clk_node *clk; + struct imx_scu_clk_node *clk, *n; int i; for (i = 0; i < IMX_SC_R_LAST; i++) { - list_for_each_entry(clk, &imx_scu_clks[i], node) { + list_for_each_entry_safe(clk, n, &imx_scu_clks[i], node) { clk_hw_unregister(clk->hw); kfree(clk); }