All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Guangshuo Li" <lgs201920130244@gmail.com>
Cc: linux-rdma@vger.kernel.org
Subject: Re: [PATCH] RDMA/irdma: avoid use-after-free in icrdma_remove
Date: Mon, 14 Sep 2026 13:02:33 +0000	[thread overview]
Message-ID: <20260914130233.D0DD41F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260914122840.1709743-1-lgs201920130244@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Double deinitialization and use-after-free bugs in probe error paths when device registration fails.
--

commit 0724e8fb174ff83ee96cc996862eceaebf99da69
Author: Guangshuo Li <lgs201920130244@gmail.com>

RDMA/irdma: avoid use-after-free in icrdma_remove

icrdma_remove() accesses iwdev after calling irdma_ib_unregister_device(),
which could lead to a use-after-free. This patch fixes the issue by
saving the iwdev->rf pointer before unregistering the device and using it
for the remaining cleanup.

> diff --git a/drivers/infiniband/hw/irdma/icrdma_if.c b/drivers/infiniband/hw/irdma/icrdma_if.c
> index 4b451d8482a48..f405ef761f843 100644
> --- a/drivers/infiniband/hw/irdma/icrdma_if.c
> +++ b/drivers/infiniband/hw/irdma/icrdma_if.c
> @@ -318,14 +318,15 @@ static void icrdma_remove(struct auxiliary_device *aux_dev)
>  		container_of(aux_dev, struct iidc_rdma_core_auxiliary_dev, adev);
>  	struct iidc_rdma_core_dev_info *cdev_info = idc_adev->cdev_info;
>  	struct irdma_device *iwdev = auxiliary_get_drvdata(aux_dev);
> -	u8 rdma_ver = iwdev->rf->rdma_ver;
> +	struct irdma_pci_f *rf = iwdev->rf;
> +	u8 rdma_ver = rf->rdma_ver;
>  
>  	ice_rdma_update_vsi_filter(cdev_info, iwdev->vsi_num, false);
>  	irdma_ib_unregister_device(iwdev);
> -	icrdma_deinit_interrupts(iwdev->rf, cdev_info);
> -	mutex_destroy(&iwdev->rf->ah_tbl_lock);
> +	icrdma_deinit_interrupts(rf, cdev_info);
> +	mutex_destroy(&rf->ah_tbl_lock);
>  
> -	kfree(iwdev->rf);
> +	kfree(rf);

[Severity: High]
This isn't a bug introduced by this patch, but I noticed a similar issue
in the device probe functions in this driver.

If irdma_ib_register_device() fails, the error paths perform manual
cleanup and then call ib_dealloc_device().

For example, in icrdma_probe():

err_init_interrupts:
	mutex_destroy(&rf->ah_tbl_lock);
	kfree(rf);
	ib_dealloc_device(&iwdev->ibdev);

Since irdma_ib_register_device() sets .dealloc_driver =
irdma_ib_dealloc_device before attempting registration, does calling
ib_dealloc_device() here invoke irdma_ib_dealloc_device() using the
freed rf pointer, leading to a use-after-free and double-free?

Does this same pattern cause a similar use-after-free in i40iw_open()
(in drivers/infiniband/hw/irdma/i40iw_if.c) and a redundant call to
irdma_rt_deinit_hw() in ig3rdma_vport_probe() (in
drivers/infiniband/hw/irdma/main.c) resulting in a double-free of
iwdev->vsi.pestat and double-destroy of iwdev->cleanup_wq?

>  
>  	pr_debug("INIT: Gen[%d] func[%d] device remove success\n",
>  		 rdma_ver, PCI_FUNC(cdev_info->pdev->devfn));

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260914122840.1709743-1-lgs201920130244@gmail.com?part=1

  reply	other threads:[~2026-09-14 13:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-14 12:28 [PATCH] RDMA/irdma: avoid use-after-free in icrdma_remove Guangshuo Li
2026-09-14 13:02 ` sashiko-bot [this message]
2026-09-22 13:13 ` Leon Romanovsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260914130233.D0DD41F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=lgs201920130244@gmail.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.