linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: airoha: fix potential use-after-free in airoha_npu_get()
@ 2025-07-14 17:57 Alok Tiwari
  2025-07-14 18:39 ` Andrew Lunn
  0 siblings, 1 reply; 2+ messages in thread
From: Alok Tiwari @ 2025-07-14 17:57 UTC (permalink / raw)
  To: sayantan.nandy, lorenzo, andrew+netdev, davem, edumazet, kuba,
	pabeni, horms, netdev, linux-mediatek
  Cc: alok.a.tiwari, linux-arm-kernel

np->name was being used after calling of_node_put(np), which
releases the node and can lead to a use-after-free bug.
Store the name in a local variable before releasing the
node to avoid potential issues.

Fixes: 23290c7bc190 ("net: airoha: Introduce Airoha NPU support")
Signed-off-by: Alok Tiwari <alok.a.tiwari@oracle.com>
---
 drivers/net/ethernet/airoha/airoha_npu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/airoha/airoha_npu.c b/drivers/net/ethernet/airoha/airoha_npu.c
index 0e5b8c21b9aa8..30cd617232244 100644
--- a/drivers/net/ethernet/airoha/airoha_npu.c
+++ b/drivers/net/ethernet/airoha/airoha_npu.c
@@ -400,11 +400,12 @@ struct airoha_npu *airoha_npu_get(struct device *dev, dma_addr_t *stats_addr)
 	if (!np)
 		return ERR_PTR(-ENODEV);
 
+	const char *np_name = np->name;
 	pdev = of_find_device_by_node(np);
 	of_node_put(np);
 
 	if (!pdev) {
-		dev_err(dev, "cannot find device node %s\n", np->name);
+		dev_err(dev, "cannot find device node %s\n", np_name);
 		return ERR_PTR(-ENODEV);
 	}
 
-- 
2.46.0



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

* Re: [PATCH net] net: airoha: fix potential use-after-free in airoha_npu_get()
  2025-07-14 17:57 [PATCH net] net: airoha: fix potential use-after-free in airoha_npu_get() Alok Tiwari
@ 2025-07-14 18:39 ` Andrew Lunn
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Lunn @ 2025-07-14 18:39 UTC (permalink / raw)
  To: Alok Tiwari
  Cc: sayantan.nandy, lorenzo, andrew+netdev, davem, edumazet, kuba,
	pabeni, horms, netdev, linux-mediatek, linux-arm-kernel

On Mon, Jul 14, 2025 at 10:57:17AM -0700, Alok Tiwari wrote:
> np->name was being used after calling of_node_put(np), which
> releases the node and can lead to a use-after-free bug.
> Store the name in a local variable before releasing the
> node to avoid potential issues.

The description does not match the patch. You are not storing the
name, you are storing a pointer to the name.

> diff --git a/drivers/net/ethernet/airoha/airoha_npu.c b/drivers/net/ethernet/airoha/airoha_npu.c
> index 0e5b8c21b9aa8..30cd617232244 100644
> --- a/drivers/net/ethernet/airoha/airoha_npu.c
> +++ b/drivers/net/ethernet/airoha/airoha_npu.c
> @@ -400,11 +400,12 @@ struct airoha_npu *airoha_npu_get(struct device *dev, dma_addr_t *stats_addr)
>  	if (!np)
>  		return ERR_PTR(-ENODEV);
>  
> +	const char *np_name = np->name;
>  	pdev = of_find_device_by_node(np);
>  	of_node_put(np);
>  
>  	if (!pdev) {
> -		dev_err(dev, "cannot find device node %s\n", np->name);
> +		dev_err(dev, "cannot find device node %s\n", np_name);

What you don't describe in the commit message is why the pointer to
the name is valid. After the of_node_put(), the node could be freed,
and i would assume if the node has gone, the name has gone as well.

I think a better fix for this is to move the of_node_put(np) to later.

    Andrew

---
pw-bot: cr


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

end of thread, other threads:[~2025-07-14 18:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-14 17:57 [PATCH net] net: airoha: fix potential use-after-free in airoha_npu_get() Alok Tiwari
2025-07-14 18:39 ` Andrew Lunn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).