pds_core: fix auxiliary device add/del races
Subsystems (3)
PATCH 1/1 pds_core: fix auxiliary device add/del races
Two paths add or delete the same slot (pf->vfs[vf_id].padev): a VF's pdsc_reset_done() and the PF's devlink enable_vnet/disable_vnet handler. They serialize on config_lock, but neither guards the slot under it correctly.
add() registers and stores a new auxiliary device without first checking the slot, so a second add of an already-populated slot leaks the first device. del() makes that check outside config_lock, so two concurrent dels can both pass it; the first clears the slot, and the second dereferences a NULL pointer.
Check and update the slot under config_lock in both paths.
--- drivers/net/ethernet/amd/pds_core/auxbus.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/net/ethernet/amd/pds_core/auxbus.c +14 -3
@@ -177,17 +177,21 @@ void pdsc_auxbus_dev_del(struct pdsc *cf, struct pdsc *pf, {struct pds_auxiliary_dev *padev; -if (!*pd_ptr) -return ; -mutex_lock (&pf->config_lock); +/* A concurrent del may have already torn this device down and +* cleared it. +*/ padev = *pd_ptr; +if (!padev) + goto out_unlock; +pds_client_unregister (pf, padev->client_id);auxiliary_device_delete (&padev->aux_dev);auxiliary_device_uninit (&padev->aux_dev); *pd_ptr =NULL ; +out_unlock:mutex_unlock (&pf->config_lock); }
@@ -210,6 +214,13 @@ int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf,mutex_lock (&pf->config_lock); +/* Nothing to do if the aux device is already present. This also +* guards against a second add overwriting *pd_ptr and leaking the +* first, symmetric with the check in pdsc_auxbus_dev_del(). +*/ +if (*pd_ptr) + goto out_unlock; + mask =BIT_ULL (PDSC_S_FW_DEAD ) |BIT_ULL (PDSC_S_STOPPING_DRIVER );if (cf->state & mask) {
Signature · 1 line
2.43.0
Quoted 52 lines · Nikhil P. Rao
Two paths add or delete the same slot (pf->vfs[vf_id].padev): a VF's
pdsc_reset_done()and the PF's devlink enable_vnet/disable_vnet handler. They serialize onconfig_lock, but neither guards the slot under it correctly.
add()registers and stores a new auxiliary device without first checking the slot, so a second add of an already-populated slot leaks the first device.del()makes that check outsideconfig_lock, so two concurrent dels can both pass it; the first clears the slot, and the second dereferences a NULL pointer.Check and update the slot under
config_lockin both paths.Fixes b699bdc720c0 ("pds_core: specify auxiliary_device to be created")Reported-by [email protected] # Running on a local machineSigned-off-by Nikhil P. Rao <[email protected]>Reviewed-by Brett Creeley <[email protected]>--- drivers/net/ethernet/amd/pds_core/auxbus.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)drivers/net/ethernet/amd/pds_core/auxbus.c +7
-3@@ -177,17 +177,21 @@ void pdsc_auxbus_dev_del(struct pdsc *cf, struct pdsc *pf, {struct pds_auxiliary_dev *padev; -if (!*pd_ptr) -return ; -mutex_lock (&pf->config_lock); +/* A concurrent del may have already torn this device down and +* cleared it. +*/ padev = *pd_ptr; +if (!padev) + goto out_unlock; +pds_client_unregister (pf, padev->client_id);auxiliary_device_delete (&padev->aux_dev);auxiliary_device_uninit (&padev->aux_dev); *pd_ptr =NULL ; +out_unlock:mutex_unlock (&pf->config_lock); }
drivers/net/ethernet/amd/pds_core/auxbus.c int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf, · line 220
Quoted 7 lines
drivers/net/ethernet/amd/pds_core/auxbus.c +4
-0@@ -210,6 +214,13 @@ int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf,mutex_lock (&pf->config_lock); +/* Nothing to do if the aux device is already present. This also +* guards against a second add overwriting *pd_ptr and leaking the +* first, symmetric with the check in pdsc_auxbus_dev_del(). +*/
Are these AI-generated-appearing comments really necessary? Anyway, it is your driver.
Quoted 10 lines
drivers/net/ethernet/amd/pds_core/auxbus.c +3
-1+if (*pd_ptr) + goto out_unlock; + mask =BIT_ULL (PDSC_S_FW_DEAD ) |BIT_ULL (PDSC_S_STOPPING_DRIVER );if (cf->state & mask) { --2.43.0
Quoted 31 lines · Pavan Chebbi
Quoted 30 lines · Nikhil P. Rao
Two paths add or delete the same slot (pf->vfs[vf_id].padev): a VF's
pdsc_reset_done()and the PF's devlink enable_vnet/disable_vnet handler. They serialize onconfig_lock, but neither guards the slot under it correctly.
add()registers and stores a new auxiliary device without first checking the slot, so a second add of an already-populated slot leaks the first device.del()makes that check outsideconfig_lock, so two concurrent dels can both pass it; the first clears the slot, and the second dereferences a NULL pointer.Check and update the slot under
config_lockin both paths.Fixes b699bdc720c0 ("pds_core: specify auxiliary_device to be created")Reported-by [email protected] # Running on a local machineSigned-off-by Nikhil P. Rao <[email protected]>Reviewed-by Brett Creeley <[email protected]>--- drivers/net/ethernet/amd/pds_core/auxbus.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)drivers/net/ethernet/amd/pds_core/auxbus.c +0
-0@@ -177,17 +177,21 @@ void pdsc_auxbus_dev_del(struct pdsc *cf, struct pdsc *pf, {struct pds_auxiliary_dev *padev;
Quoted 8 lines
drivers/net/ethernet/amd/pds_core/auxbus.c void pdsc_auxbus_dev_del(struct pdsc *cf, struct pdsc *pf, · line 184
Quoted 8 lines
drivers/net/ethernet/amd/pds_core/auxbus.c +3
-3-if (!*pd_ptr) -return ; -mutex_lock (&pf->config_lock); +/* A concurrent del may have already torn this device down and +* cleared it. +*/
I don't know if this one is AI-generated, but it looked good to me; I appreciate the comment that it is specifically supposed to guard against a scenario. Though arguably it's a common enough pattern that it may not need it.
Quoted 17 lines
Quoted 17 lines
drivers/net/ethernet/amd/pds_core/auxbus.c +4
-0padev = *pd_ptr; +if (!padev) + goto out_unlock; +pds_client_unregister (pf, padev->client_id);auxiliary_device_delete (&padev->aux_dev);auxiliary_device_uninit (&padev->aux_dev); *pd_ptr =NULL ; +out_unlock:mutex_unlock (&pf->config_lock); }@@ -210,6 +214,13 @@ int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf,mutex_lock (&pf->config_lock);
Quoted 8 lines
drivers/net/ethernet/amd/pds_core/auxbus.c int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf, · line 220
Quoted 4 lines
drivers/net/ethernet/amd/pds_core/auxbus.c +4
-0+/* Nothing to do if the aux device is already present. This also +* guards against a second add overwriting *pd_ptr and leaking the +* first, symmetric with the check in pdsc_auxbus_dev_del(). +*/ Are these AI-generated-appearing comments really necessary? Anyway, it is your driver.
Reviewed-by Pavan Chebbi <[email protected]>
This is a bit flippant, but if the kernel is going to send all of our patches through an AI, we can at least be nice to the AI the mailing list uses and reduce its credit usage by embedding comments from our AI in it so it doesn't have to figure things out every time. :p
But I get your point, this one in particular seems gratuitous, and the language it uses is recognizably AI-generated which is off-putting to me, too, though maybe I'm also just sensitive to them. I think we review these comments with the view that unless they're wrong, they're harmless to leave in; but instead we should view these added comments more critically.
- Eric
Quoted 11 lines
Quoted 11 lines
drivers/net/ethernet/amd/pds_core/auxbus.c +3
-1+if (*pd_ptr) + goto out_unlock; + mask =BIT_ULL (PDSC_S_FW_DEAD ) |BIT_ULL (PDSC_S_STOPPING_DRIVER );if (cf->state & mask) { --2.43.0
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 5 lines · On Tue, 14 Jul 2026 21:07:45 +0000 you wrote:
Two paths add or delete the same slot (pf->vfs[vf_id].padev): a VF's
pdsc_reset_done()and the PF's devlink enable_vnet/disable_vnet handler. They serialize onconfig_lock, but neither guards the slot under it correctly.
Quoted 7 lines
add()registers and stores a new auxiliary device without first checking the slot, so a second add of an already-populated slot leaks the first device.del()makes that check outsideconfig_lock, so two concurrent dels can both pass it; the first clears the slot, and the second dereferences a NULL pointer.[...]
Here is the summary with links:
- [net] pds_core: fix auxiliary device add/del races
https://git.kernel.org/netdev/net/c/bfa33cd513c7
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html