History

bnge: Fix NULL pointer dereference in aux device release

If allocation of auxr_dev fails during auxiliary device setup, the error path calls auxiliary_device_uninit(), which eventually invokes bnge_aux_dev_release(). The release callback unconditionally dereferences aux_priv->auxr_dev->pdev to retrieve the parent bnge_dev. Since auxr_dev has not yet been allocated on this failure path, the dereference results in a NULL pointer exception Retrieve the parent bnge_dev from the auxiliary device's parent instead of auxr_dev, and free auxr_dev only when it was successfully allocated. This allows the release callback to correctly clean up partially initialized auxiliary devices.

Alok Tiwari committed 3 months ago

Commit 1cb42981 parent 1f428e31 file · +6 −3Browse files

Unified · Split

drivers/net/ethernet/broadcom/bnge/bnge_auxr.c+6−3
@@ -141,12 +141,15 @@ static void bnge_aux_dev_release(struct device *dev) · 140 unmodified lines
141{141{
142 struct bnge_auxr_priv *aux_priv =142 struct bnge_auxr_priv *aux_priv =
143 container_of(dev, struct bnge_auxr_priv, aux_dev.dev);143 container_of(dev, struct bnge_auxr_priv, aux_dev.dev);
144 struct bnge_dev *bd = pci_get_drvdata(aux_priv->auxr_dev->pdev);144 struct bnge_auxr_dev *auxr_dev = aux_priv->auxr_dev;
145 struct bnge_dev *bd = pci_get_drvdata(to_pci_dev(dev->parent));
145 146
146 ida_free(&bnge_aux_dev_ids, aux_priv->id);147 ida_free(&bnge_aux_dev_ids, aux_priv->id);
147 kfree(aux_priv->auxr_dev->auxr_info);148 if (auxr_dev) {
149 kfree(auxr_dev->auxr_info);
150 kfree(auxr_dev);
151 }
148 bd->auxr_dev = NULL;152 bd->auxr_dev = NULL;
149 kfree(aux_priv->auxr_dev);
150 kfree(aux_priv);153 kfree(aux_priv);
151 bd->aux_priv = NULL;154 bd->aux_priv = NULL;
152}155}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t