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..rdma.core." or "idpf..rdma.vdev." 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") Signed-off-by: Changyul Lee --- 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(-) diff --git a/drivers/net/ethernet/intel/idpf/idpf_idc.c b/drivers/net/ethernet/intel/idpf/idpf_idc.c index b6cd1c25ae5d..9d3c55854477 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_idc.c +++ b/drivers/net/ethernet/intel/idpf/idpf_idc.c @@ -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 -- 2.43.0