All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [v4] ieee802154: ca8210: Fix a potential UAF in ca8210_probe
@ 2023-10-07  3:30 Dinghao Liu
  2023-10-07  3:32 ` kernel test robot
  2023-10-07 18:42 ` Stefan Schmidt
  0 siblings, 2 replies; 3+ messages in thread
From: Dinghao Liu @ 2023-10-07  3:30 UTC (permalink / raw)
  To: dinghao.liu
  Cc: stable, Alexander Aring, Stefan Schmidt, Miquel Raynal,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Harry Morris, Marcel Holtmann, linux-wpan, netdev, linux-kernel

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 <dinghao.liu@zju.edu.cn>
---

Changelog:

v2: -Remove the first clk_unregister() instead of nulling priv->clk.

v3: -Simplify ca8210_register_ext_clock().
    -Add a ';' after return in ca8210_unregister_ext_clock().

v4: -Remove an unused variable 'ret'.
---
 drivers/net/ieee802154/ca8210.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)

diff --git a/drivers/net/ieee802154/ca8210.c b/drivers/net/ieee802154/ca8210.c
index aebb19f1b3a4..4ec0dab38872 100644
--- a/drivers/net/ieee802154/ca8210.c
+++ b/drivers/net/ieee802154/ca8210.c
@@ -2740,7 +2740,6 @@ static int ca8210_register_ext_clock(struct spi_device *spi)
 	struct device_node *np = spi->dev.of_node;
 	struct ca8210_priv *priv = spi_get_drvdata(spi);
 	struct ca8210_platform_data *pdata = spi->dev.platform_data;
-	int ret = 0;
 
 	if (!np)
 		return -EFAULT;
@@ -2757,18 +2756,8 @@ static int ca8210_register_ext_clock(struct spi_device *spi)
 		dev_crit(&spi->dev, "Failed to register external clk\n");
 		return PTR_ERR(priv->clk);
 	}
-	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"
-		);
-	} else {
-		dev_info(&spi->dev, "External clock set as clock provider\n");
-	}
 
-	return ret;
+	return of_clk_add_provider(np, of_clk_src_simple_get, priv->clk);
 }
 
 /**
@@ -2780,8 +2769,8 @@ static void ca8210_unregister_ext_clock(struct spi_device *spi)
 {
 	struct ca8210_priv *priv = spi_get_drvdata(spi);
 
-	if (!priv->clk)
-		return
+	if (IS_ERR_OR_NULL(priv->clk))
+		return;
 
 	of_clk_del_provider(spi->dev.of_node);
 	clk_unregister(priv->clk);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] [v4] ieee802154: ca8210: Fix a potential UAF in ca8210_probe
  2023-10-07  3:30 [PATCH] [v4] ieee802154: ca8210: Fix a potential UAF in ca8210_probe Dinghao Liu
@ 2023-10-07  3:32 ` kernel test robot
  2023-10-07 18:42 ` Stefan Schmidt
  1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2023-10-07  3:32 UTC (permalink / raw)
  To: Dinghao Liu; +Cc: stable, oe-kbuild-all

Hi,

Thanks for your patch.

FYI: kernel test robot notices the stable kernel rule is not satisfied.

The check is based on https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html/#option-1

Rule: add the tag "Cc: stable@vger.kernel.org" in the sign-off area to have the patch automatically included in the stable tree.
Subject: [PATCH] [v4] ieee802154: ca8210: Fix a potential UAF in ca8210_probe
Link: https://lore.kernel.org/stable/20231007033049.22353-1-dinghao.liu%40zju.edu.cn

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] [v4] ieee802154: ca8210: Fix a potential UAF in ca8210_probe
  2023-10-07  3:30 [PATCH] [v4] ieee802154: ca8210: Fix a potential UAF in ca8210_probe Dinghao Liu
  2023-10-07  3:32 ` kernel test robot
@ 2023-10-07 18:42 ` Stefan Schmidt
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Schmidt @ 2023-10-07 18:42 UTC (permalink / raw)
  To: Dinghao Liu
  Cc: stable, Alexander Aring, Miquel Raynal, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Harry Morris,
	Marcel Holtmann, linux-wpan, netdev, linux-kernel

Hello.

On 07.10.23 05:30, Dinghao Liu wrote:
> 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 <dinghao.liu@zju.edu.cn>
> ---
> 
> Changelog:
> 
> v2: -Remove the first clk_unregister() instead of nulling priv->clk.
> 
> v3: -Simplify ca8210_register_ext_clock().
>      -Add a ';' after return in ca8210_unregister_ext_clock().
> 
> v4: -Remove an unused variable 'ret'.


This patch has been applied to the wpan tree and will be
part of the next pull request to net. Thanks!

regards
Stefan Schmidt


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-10-07 18:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-07  3:30 [PATCH] [v4] ieee802154: ca8210: Fix a potential UAF in ca8210_probe Dinghao Liu
2023-10-07  3:32 ` kernel test robot
2023-10-07 18:42 ` Stefan Schmidt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.