Skip to content

Commit 3cd582e

Browse files
aloktiwakuba-moo
authored andcommitted
net: airoha: fix potential use-after-free in airoha_npu_get()
np->name was being used after calling of_node_put(np), which releases the node and can lead to a use-after-free bug. Previously, of_node_put(np) was called unconditionally after of_find_device_by_node(np), which could result in a use-after-free if pdev is NULL. This patch moves of_node_put(np) after the error check to ensure the node is only released after both the error and success cases are handled appropriately, preventing potential resource issues. Fixes: 23290c7 ("net: airoha: Introduce Airoha NPU support") Signed-off-by: Alok Tiwari <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 531d0d3 commit 3cd582e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/net/ethernet/airoha/airoha_npu.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,13 @@ struct airoha_npu *airoha_npu_get(struct device *dev, dma_addr_t *stats_addr)
401401
return ERR_PTR(-ENODEV);
402402

403403
pdev = of_find_device_by_node(np);
404-
of_node_put(np);
405404

406405
if (!pdev) {
407406
dev_err(dev, "cannot find device node %s\n", np->name);
407+
of_node_put(np);
408408
return ERR_PTR(-ENODEV);
409409
}
410+
of_node_put(np);
410411

411412
if (!try_module_get(THIS_MODULE)) {
412413
dev_err(dev, "failed to get the device driver module\n");

0 commit comments

Comments
 (0)