Linux SCSI subsystem development
 help / color / mirror / Atom feed
* [PATCH v1 0/4] scsi: sd: fix probe error cleanup, special_vec leak and sd_done() sense gate
@ 2026-06-23 10:01 Yang Xiuwei
  2026-06-23 10:01 ` [PATCH v1 1/4] scsi: sd: fix error handling in sd_probe() after large pool creation failure Yang Xiuwei
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Yang Xiuwei @ 2026-06-23 10:01 UTC (permalink / raw)
  To: martin.petersen, James.Bottomley
  Cc: hare, tom.leiming, p.raghav, dlemoal, sw.prabhu6, linux-scsi,
	Yang Xiuwei

This series fixes three resource-handling bugs in drivers/scsi/sd.c.

Patch 1/4 fixes sd_probe() when sd_large_pool_create() fails after
device_add(&disk_dev) has already registered the scsi_disk device in
sysfs. The old out_free_index path kfree()s sdkp while disk_dev remains
registered, leaking the sysfs node and risking use-after-free.

Patch 2/4 refactors probe error cleanup as suggested by Ming Lei: after
put_device() or device_unregister() has released sdkp through
scsi_disk_release(), set the local sdkp pointer to NULL and fall through
to out_put so put_disk() and any remaining kfree() are handled in one
place.

Patch 3/4 fixes a special_vec mempool leak in sd_setup_unmap_cmnd() and
sd_setup_write_same{10,16}_cmnd(). sd_set_special_bvec() may succeed
before scsi_alloc_sgtables() fails during command preparation; the SCSI
midlayer does not call uninit_command() in that case because
RQF_DONTPREP is not set yet.

Patch 4/4 fixes the sd_done() sense gate left incomplete by commit
464a00c9e0ad ("scsi: core: Kill DRIVER_SENSE"). Replacing
driver_byte(result) != DRIVER_SENSE with !scsi_status_is_check_condition()
while keeping the old OR-shaped gate allows CHECK CONDITION with invalid
or deferred sense to enter the sense_key switch with an uninitialized
sshdr.

None of these patches are considered stable material: probe failures and
invalid-sense paths are rare edge cases with no crash in common paths.

Yang Xiuwei (4):
  scsi: sd: fix error handling in sd_probe() after large pool creation
    failure
  scsi: sd: unify sd_probe() error cleanup through out_put
  scsi: sd: fix special_vec mempool leak when scsi_alloc_sgtables()
    fails
  scsi: sd: fix sd_done() sense handling condition

 drivers/scsi/sd.c | 65 +++++++++++++++++++++++++++++------------------
 1 file changed, 40 insertions(+), 25 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2026-06-29  5:03 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-23 10:01 [PATCH v1 0/4] scsi: sd: fix probe error cleanup, special_vec leak and sd_done() sense gate Yang Xiuwei
2026-06-23 10:01 ` [PATCH v1 1/4] scsi: sd: fix error handling in sd_probe() after large pool creation failure Yang Xiuwei
2026-06-26 21:52   ` Damien Le Moal
2026-06-23 10:01 ` [PATCH v1 2/4] scsi: sd: unify sd_probe() error cleanup through out_put Yang Xiuwei
2026-06-26 21:54   ` Damien Le Moal
2026-06-29  1:16     ` Yang Xiuwei
2026-06-29  5:03       ` Damien Le Moal
2026-06-23 10:01 ` [PATCH v1 3/4] scsi: sd: fix special_vec mempool leak when scsi_alloc_sgtables() fails Yang Xiuwei
2026-06-23 10:20   ` sashiko-bot
2026-06-26 21:57   ` Damien Le Moal
2026-06-23 10:01 ` [PATCH v1 4/4] scsi: sd: fix sd_done() sense handling condition Yang Xiuwei
2026-06-23 10:18   ` sashiko-bot
2026-06-26 22:07   ` Damien Le Moal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox