Message ID | 1671747798-12935-1-git-send-email-khoroshilov@ispras.ru |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp22906wrn; Thu, 22 Dec 2022 14:38:31 -0800 (PST) X-Google-Smtp-Source: AMrXdXsN/DIQ9BNX0tj85fzJ+Lxm9w5iPhcitcsd3eimdNaPaaRx4fTJMWA5+7tP3+DIwwppM6Rg X-Received: by 2002:a05:6a21:998b:b0:a6:713d:4343 with SMTP id ve11-20020a056a21998b00b000a6713d4343mr12232826pzb.5.1671748711303; Thu, 22 Dec 2022 14:38:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671748711; cv=none; d=google.com; s=arc-20160816; b=HfsUtf7sSzpH2peupl6znWJDkNpeai7P8zby79x4endhNy1k8JMGZD9HBtP4tQrxuB Bfbe3c4MOFWuQFv5FaYHgHxDJauXxD8VKabqU2NACQEElng0zp5b/wf+SOZFr74hCc89 fBOqowadlzAJE77VtW/bemvZVKXnd+sewP0kXgiTjDnoUSguaGb0n7apkRkIMqy9gttH 2UNhzsJ2m16IdPXHPNFtDatVjhFN0EBhOvZALpdQ/OPSW+f8LFEQ42bJPWvwrb0GA6k7 AQayIuK703/oHrFuC4096hcrI2mWkcgB7mIaaJWYATwOWfp1EqSKdC4F8xiljETWJ0N4 6wuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=jk73c5NJJA/FvCk7056jbrerrHp19o8I8HwVkJyNo4c=; b=anVQveufrzH8cKlHxBHlEM+VT9BAuQcC25CF8R2c2K7eiqYG1mJrIx9slL5mGptpQM /E7A4jmEM3QtY/0md3jYtGk7nKyrvp0ac7VlAQGxlXODl/pXwOkmx1FsKK+y+5LtI+kQ ZeARooSFvliRkhi0VUWBX+SMVi+cktqL6isHaq3tPT0h3hH1+0fqJnkob1QNO9FOqUzE StLuu3LILXhbiI1hM+Cab7CFRrGpXQq5hwoomnfi/z1GFhgd96uIpq3OEYrBgeh2lOHQ 2d6J0uKpog98p/TnhxsQBtGAeoq4UN2ld6/KCWRmhvUMC4LLJsUxxU979AkETcVdqNCa ZU8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=MJJynVxz; 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 j1-20020a654301000000b004792b0801f3si1867792pgq.558.2022.12.22.14.37.52; Thu, 22 Dec 2022 14:38:31 -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=MJJynVxz; 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 S235741AbiLVWXi (ORCPT <rfc822;pacteraone@gmail.com> + 99 others); Thu, 22 Dec 2022 17:23:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230042AbiLVWXg (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 22 Dec 2022 17:23:36 -0500 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 953B613F7A; Thu, 22 Dec 2022 14:23:35 -0800 (PST) Received: from hednb3.intra.ispras.ru (unknown [109.252.115.251]) by mail.ispras.ru (Postfix) with ESMTPSA id BE990419E9CD; Thu, 22 Dec 2022 22:23:31 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru BE990419E9CD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1671747812; bh=jk73c5NJJA/FvCk7056jbrerrHp19o8I8HwVkJyNo4c=; h=From:To:Cc:Subject:Date:From; b=MJJynVxzGehMCerhsCb3WTrMDabvMGhtsyAuU/YRQoizCP4vxkabfxZkchW2nS++z gdMlWE12JjaKL0Z55kJ4z+dQDFRXOo2uM7bQjyldTf+lX1iZUPuUwLpqbHLaDqZSZd fevtOuFjoKoDuBaA+RknfTMDf/Yo6aldh5Is4eSM= From: Alexey Khoroshilov <khoroshilov@ispras.ru> To: Geert Uytterhoeven <geert+renesas@glider.be>, Chris Brandt <chris.brandt@renesas.com> Cc: Alexey Khoroshilov <khoroshilov@ispras.ru>, Michael Turquette <mturquette@baylibre.com>, Stephen Boyd <sboyd@kernel.org>, linux-renesas-soc@vger.kernel.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org Subject: [PATCH] clk: renesas: cpg-mssr: Fix use after free if cpg_mssr_common_init() failed Date: Fri, 23 Dec 2022 01:23:18 +0300 Message-Id: <1671747798-12935-1-git-send-email-khoroshilov@ispras.ru> X-Mailer: git-send-email 2.7.4 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: <linux-kernel.vger.kernel.org> 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?1752955576447708402?= |
Series |
clk: renesas: cpg-mssr: Fix use after free if cpg_mssr_common_init() failed
|
|
Commit Message
Alexey Khoroshilov
Dec. 22, 2022, 10:23 p.m. UTC
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 <khoroshilov@ispras.ru>
---
drivers/clk/renesas/renesas-cpg-mssr.c | 1 +
1 file changed, 1 insertion(+)
Comments
Hi Alexey, On Thu, Dec 22, 2022 at 11:23 PM Alexey Khoroshilov <khoroshilov@ispras.ru> wrote: > 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 <khoroshilov@ispras.ru> Thanks for your patch! > --- a/drivers/clk/renesas/renesas-cpg-mssr.c > +++ b/drivers/clk/renesas/renesas-cpg-mssr.c > @@ -1025,6 +1025,7 @@ static int __init cpg_mssr_common_init(struct device *dev, > if (priv->base) > iounmap(priv->base); > kfree(priv); > + cpg_mssr_priv = NULL; While this is correct, I think it would be better to just postpone the initial assignment to cpg_mssr_priv until everything in cpg_mssr_common_init() has succeeded, i.e. just below the "return 0;" above. > > return error; > } Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
diff --git a/drivers/clk/renesas/renesas-cpg-mssr.c b/drivers/clk/renesas/renesas-cpg-mssr.c index 1a0cdf001b2f..27da127ca4a8 100644 --- a/drivers/clk/renesas/renesas-cpg-mssr.c +++ b/drivers/clk/renesas/renesas-cpg-mssr.c @@ -1025,6 +1025,7 @@ static int __init cpg_mssr_common_init(struct device *dev, if (priv->base) iounmap(priv->base); kfree(priv); + cpg_mssr_priv = NULL; return error; }