From: sashiko-bot@kernel.org
To: "Haoxiang Li" <haoxiang_li2024@163.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH] scsi: st: Free the reserved page array on probe failure
Date: Wed, 02 Dec 2026 04:19:41 +0000 [thread overview]
Message-ID: <sashiko-outbox-244839@kernel.org> (raw)
In-Reply-To: <20261202041412.4009678-1-haoxiang_li2024@163.com>
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] scsi: st: use-after-free in st_probe() [1]
--
commit bf382c81186020068666c0ef5a2d0f660a45bfd1
Author: Haoxiang Li <haoxiang_li2024@163.com>
scsi: st: Free the reserved page array on probe failure
This commit frees buffer->reserved_pages on the st_probe() error path
before freeing the tape buffer itself.
> diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
> index e9d41e3cc2dd3..77f4a66af2ec3 100644
> --- a/drivers/scsi/st.c
> +++ b/drivers/scsi/st.c
> @@ -4593,6 +4593,7 @@ static int st_probe(struct scsi_device *SDp)
> out_free_tape:
> kfree(tpnt);
> out_buffer_free:
> + kfree(buffer->reserved_pages);
> kfree(buffer);
> out:
> scsi_autopm_put_device(SDp);
[Severity: Critical]
This problem wasn't introduced by this patch, but can kfree(tpnt) at
out_free_tape cause a use-after-free [1] if a concurrent st_open()
acquires a reference to tpnt before probe failure cleanup completes?
st_probe() publishes tpnt in st_index_idr via idr_alloc() before allocating
tpnt->stats and calling create_cdevs(). If either step fails, a concurrent
opener can look up tpnt in st_index_idr and increment tpnt->kref before
out_idr_remove removes the entry, while out_free_tape frees tpnt
unconditionally instead of dropping its reference:
CPU0 CPU1
st_probe()
kref_init(&tpnt->kref)
idr_alloc(&st_index_idr, tpnt, ...)
create_cdevs(tpnt) // fails
st_open()
scsi_tape_get()
STp = idr_find(&st_index_idr, ...)
kref_get(&STp->kref)
remove_cdevs(tpnt)
idr_remove(&st_index_idr, ...)
kfree(tpnt)
filp->private_data = STp;
... <-- use-after-free
[1] https://sashiko.dev/#/bug/linux-9c29c2d3-7e87-4362-b5ae-ae4459b36d9f
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202041412.4009678-1-haoxiang_li2024@163.com?part=1
prev parent reply other threads:[~2026-12-02 4:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 4:14 [PATCH] scsi: st: Free the reserved page array on probe failure Haoxiang Li
2026-12-02 4: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=sashiko-outbox-244839@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=haoxiang_li2024@163.com \
--cc=linux-scsi@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.