From: sashiko-bot@kernel.org
To: "Yang Xiuwei" <yangxiuwei@kylinos.cn>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v2 2/3] scsi: sd: fix special_vec mempool leak when scsi_alloc_sgtables() fails
Date: Tue, 07 Jul 2026 03:26:03 +0000 [thread overview]
Message-ID: <20260707032604.40E021F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260707030333.22245-3-yangxiuwei@kylinos.cn>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The special payload page can be freed into the wrong mempool if the device sector size changes while the command is in flight.
--
--- Patch [2]: [PATCH v2 2/3] scsi: sd: fix special_vec mempool leak when scsi_alloc_sgtables() fails ---
commit 39421d4b78837e533a8958996d1edabedfa78d22
Author: Yang Xiuwei <yangxiuwei@kylinos.cn>
scsi: sd: fix special_vec mempool leak when scsi_alloc_sgtables() fails
This commit fixes a mempool leak when scsi_alloc_sgtables() fails in
sd_setup_unmap_cmnd() or sd_setup_write_same{10,16}_cmnd(). It ensures
sd_uninit_command() is called on error, clearing RQF_SPECIAL_PAYLOAD
and freeing the payload page.
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index d18693d390b2f..8fed1cda9ac8c 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
> @@ -958,6 +958,21 @@ static unsigned char sd_setup_protect_cmnd(struct scsi_cmnd *scmd,
> return protect;
> }
>
> +static void sd_uninit_command(struct scsi_cmnd *cmd)
> +{
> + struct request *rq = scsi_cmd_to_rq(cmd);
> + struct scsi_device *sdp = cmd->device;
> +
> + if (!(rq->rq_flags & RQF_SPECIAL_PAYLOAD))
> + return;
> +
> + if (sdp->sector_size > PAGE_SIZE)
> + mempool_free(rq->special_vec.bv_page, sd_large_page_pool);
> + else
> + mempool_free(rq->special_vec.bv_page, sd_page_pool);
[Severity: High]
This isn't a bug introduced by this patch, but can this free the page to the
wrong mempool if the device sector size changes while the command is in flight?
sd_set_special_bvec() allocates the page based on the sector size at the time
of submission:
if (sector_size > PAGE_SIZE)
page = mempool_alloc(sd_large_page_pool, GFP_ATOMIC);
else
page = mempool_alloc(sd_page_pool, GFP_ATOMIC);
If sd_read_capacity() updates sdp->sector_size dynamically during a concurrent
rescan before the request queue is frozen, this cleanup path might read the
updated sector size. This could result in freeing an order-0 page into the
large page pool or vice versa, causing memory corruption upon subsequent
allocations from the pool.
> + rq->rq_flags &= ~RQF_SPECIAL_PAYLOAD;
> +}
> +
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260707030333.22245-1-yangxiuwei@kylinos.cn?part=2
next prev parent reply other threads:[~2026-07-07 3:26 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-07 3:03 [PATCH v2 0/3] scsi: sd: fix probe error cleanup, special_vec leak and sd_done() sense gate Yang Xiuwei
2026-07-07 3:03 ` [PATCH v2 1/3] scsi: sd: fix error handling in sd_probe() after large pool creation failure Yang Xiuwei
2026-07-07 3:30 ` sashiko-bot
2026-07-08 6:29 ` John Garry
2026-07-08 7:22 ` Yang Xiuwei
2026-07-08 7:57 ` John Garry
2026-07-07 3:03 ` [PATCH v2 2/3] scsi: sd: fix special_vec mempool leak when scsi_alloc_sgtables() fails Yang Xiuwei
2026-07-07 3:26 ` sashiko-bot [this message]
2026-07-08 6:32 ` John Garry
2026-07-07 3:03 ` [PATCH v2 3/3] scsi: sd: fix sd_done() sense handling condition Yang Xiuwei
2026-07-08 16:07 ` Bart Van Assche
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=20260707032604.40E021F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=yangxiuwei@kylinos.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox