From: sashiko-bot@kernel.org
To: "Wentao Liang" <vulab@iscas.ac.cn>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH] scsi: mpi3mr: Fix tgtdev reference count in mpi3mr_pcietopochg_evt_bh()
Date: Thu, 17 Sep 2026 15:19:10 +0000 [thread overview]
Message-ID: <20260917151910.DBCBE1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260917150301.2158080-1-vulab@iscas.ac.cn>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] scsi: mpi3mr: memory leak of tgtdev on PCIe removal due to removed kref put
- [High] scsi: mpi3mr: incomplete fix leaves double-put UAF vulnerability in SAS and status handlers
--
commit a438077929efbcec320166774a755489ffa128b2
Author: Wentao Liang <vulab@iscas.ac.cn>
scsi: mpi3mr: Fix tgtdev reference count in mpi3mr_pcietopochg_evt_bh()
This patch drops an extra put in the PCIe topology change event handler
that previously dropped the reference twice. This is intended to fix a
premature release of the target device kref.
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
> index 991e29a8d382f..d6414d0186183 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_os.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
> @@ -2053,7 +2053,6 @@ static void mpi3mr_pcietopochg_evt_bh(struct mpi3mr_ioc *mrioc,
> if (tgtdev->host_exposed)
> mpi3mr_remove_tgtdev_from_host(mrioc, tgtdev);
> mpi3mr_tgtdev_del_from_list(mrioc, tgtdev, false);
> - mpi3mr_tgtdev_put(tgtdev);
[Severity: High]
Does removing this explicit put leak the tgtdev structure?
The device structure tgtdev is initialized with a refcount of 1 upon
allocation, and a second reference is taken when it is added to the internal
list. In mpi3mr_pcietopochg_evt_bh(), mpi3mr_tgtdev_del_from_list() drops the
list reference.
By removing this explicit put, doesn't the object end up with a stranded
refcount of 1 after the event handler drops its loop-local handle reference
at the end of the iteration? This appears to result in a permanent memory
leak on standard hardware hotplug paths.
> break;
> default:
> break;
[Severity: High]
Does this fix leave the same double-put vulnerability in the SAS and status
handlers?
The patch aims to fix a premature reference release by removing the explicit
put in the PCIe topology handler. However, looking at the source, the exact
same reference-dropping sequence remains in mpi3mr_sastopochg_evt_bh() and
mpi3mr_devstatuschg_evt_bh(). For example:
mpi3mr_devstatuschg_evt_bh() {
...
if (cleanup) {
mpi3mr_tgtdev_del_from_list(mrioc, tgtdev, false);
mpi3mr_tgtdev_put(tgtdev);
}
...
}
If a device fails to be removed from the list (e.g., state is not
MPI3MR_DEV_REMOVE_HS_STARTED), these handlers unconditionally drop the base
reference while the object remains in the list.
Later, when the device is actually removed from the list (such as during
mpi3mr_refresh_tgtdevs()), wouldn't the refcount drop to 0 prematurely,
causing a use-after-free during the subsequent put? Should these other
equivalent handlers be updated to properly address this sequence as well?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260917150301.2158080-1-vulab@iscas.ac.cn?part=1
prev parent reply other threads:[~2026-09-17 15:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-17 15:03 [PATCH] scsi: mpi3mr: Fix tgtdev reference count in mpi3mr_pcietopochg_evt_bh() Wentao Liang
2026-09-17 15:19 ` sashiko-bot [this message]
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=20260917151910.DBCBE1F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=vulab@iscas.ac.cn \
/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.