Skip to contentSkip to conversation

idpf: free the RDMA auxiliary device ID after deleting the device

PATCH In review Changyul Lee 2 participants 2 messages Nov 18 – Nov 23

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 idpf: free the RDMA auxiliary device ID after deleting the device

idpf_unplug_aux_dev() returns the ID to idpf_idc_ida before auxiliary_device_delete() removes the device. If another idpf device plugs an RDMA auxiliary device in between, it can get the same ID, and its auxiliary_device_add() fails with -EEXIST because the old "idpf.<vendor>.rdma.core.<id>" or "idpf.<vendor>.rdma.vdev.<id>" device is still registered. RDMA is then not set up on that device.

Free the ID after auxiliary_device_delete(). It still has to be freed before auxiliary_device_uninit(), whose release callback frees adev.

Fixes 65637c3a1811 ("idpf: fix UAF in RDMA core aux dev deinitialization")

---
Found with a static analysis tool we are developing.

Compile-tested only, with x86_64_defconfig plus IDPF and W=1.

 drivers/net/ethernet/intel/idpf/idpf_idc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_idc.c +1 -2
index b6cd1c25ae5d..9d3c55854477 100644
@@ -253,9 +253,8 @@ static void idpf_unplug_aux_dev(struct auxiliary_device *adev)
 	if (!adev)
 		return;
 
-	ida_free(&idpf_idc_ida, adev->id);
-
 	auxiliary_device_delete(adev);
+	ida_free(&idpf_idc_ida, adev->id);
 	auxiliary_device_uninit(adev);
 }
 

base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb

Signature · 1 line
2.43.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Changyul Lee

idpf_unplug_aux_dev() returns the ID to idpf_idc_ida before auxiliary_device_delete() removes the device. If another idpf device plugs an RDMA auxiliary device in between, it can get the same ID, and its auxiliary_device_add() fails with -EEXIST because the old "idpf.<vendor>.rdma.core.<id>" or "idpf.<vendor>.rdma.vdev.<id>" device is still registered. RDMA is then not set up on that device.

Free the ID after auxiliary_device_delete(). It still has to be freed before auxiliary_device_uninit(), whose release callback frees adev.

Quoted 6 lines
Fixes 65637c3a1811 ("idpf: fix UAF in RDMA core aux dev deinitialization")

---
Found with a static analysis tool we are developing.

Compile-tested only, with x86_64_defconfig plus IDPF and W=1.