[PATCH net] net: airoha: fix potential use-after-free in airoha_npu_get()
Andrew Lunn
andrew at lunn.ch
Mon Jul 14 11:39:04 PDT 2025
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
More information about the Linux-mediatek
mailing list