Skip to content

Commit f990874

Browse files
dinghaoliuStefan-Schmidt
authored andcommitted
ieee802154: ca8210: Fix a potential UAF in ca8210_probe
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: ded845a ("ieee802154: Add CA8210 IEEE 802.15.4 device driver") Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn> Message-ID: <20231007033049.22353-1-dinghao.liu@zju.edu.cn> Signed-off-by: Stefan Schmidt <stefan@datenfreihafen.org>
1 parent a2e5255 commit f990874

1 file changed

Lines changed: 3 additions & 14 deletions

File tree

drivers/net/ieee802154/ca8210.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2740,7 +2740,6 @@ static int ca8210_register_ext_clock(struct spi_device *spi)
27402740
struct device_node *np = spi->dev.of_node;
27412741
struct ca8210_priv *priv = spi_get_drvdata(spi);
27422742
struct ca8210_platform_data *pdata = spi->dev.platform_data;
2743-
int ret = 0;
27442743

27452744
if (!np)
27462745
return -EFAULT;
@@ -2757,18 +2756,8 @@ static int ca8210_register_ext_clock(struct spi_device *spi)
27572756
dev_crit(&spi->dev, "Failed to register external clk\n");
27582757
return PTR_ERR(priv->clk);
27592758
}
2760-
ret = of_clk_add_provider(np, of_clk_src_simple_get, priv->clk);
2761-
if (ret) {
2762-
clk_unregister(priv->clk);
2763-
dev_crit(
2764-
&spi->dev,
2765-
"Failed to register external clock as clock provider\n"
2766-
);
2767-
} else {
2768-
dev_info(&spi->dev, "External clock set as clock provider\n");
2769-
}
27702759

2771-
return ret;
2760+
return of_clk_add_provider(np, of_clk_src_simple_get, priv->clk);
27722761
}
27732762

27742763
/**
@@ -2780,8 +2769,8 @@ static void ca8210_unregister_ext_clock(struct spi_device *spi)
27802769
{
27812770
struct ca8210_priv *priv = spi_get_drvdata(spi);
27822771

2783-
if (!priv->clk)
2784-
return
2772+
if (IS_ERR_OR_NULL(priv->clk))
2773+
return;
27852774

27862775
of_clk_del_provider(spi->dev.of_node);
27872776
clk_unregister(priv->clk);

0 commit comments

Comments
 (0)