]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commit
scsi: sd: Fix potential NULL pointer dereference
authorDamien Le Moal <damien.lemoal@opensource.wdc.com>
Wed, 1 Jun 2022 06:25:43 +0000 (15:25 +0900)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 26 Aug 2022 08:52:51 +0000 (10:52 +0200)
commitf0e0465805d50d7361542a6b5f6ea7fef761419f
tree08718a969aaebdce20dacff20182b1fc25d33494
parent59fca598c9dc7f80de98d46330e9058667c21c12
scsi: sd: Fix potential NULL pointer dereference

BugLink: https://bugs.launchpad.net/bugs/1982968
[ Upstream commit 05fbde3a77a4f1d62e4c4428f384288c1f1a0be5 ]

If sd_probe() sees an early error before sdkp->device is initialized,
sd_zbc_release_disk() is called. This causes a NULL pointer dereference
when sd_is_zoned() is called inside that function. Avoid this by removing
the call to sd_zbc_release_disk() in sd_probe() error path.

This change is safe and does not result in zone information memory leakage
because the zone information for a zoned disk is allocated only when
sd_revalidate_disk() is called, at which point sdkp->disk_dev is fully set,
resulting in sd_disk_release() being called when needed to cleanup a disk
zone information using sd_zbc_release_disk().

Link: https://lore.kernel.org/r/20220601062544.905141-2-damien.lemoal@opensource.wdc.com
Fixes: 89d947561077 ("sd: Implement support for ZBC devices")
Reported-by: Dongliang Mu <mudongliangabcd@gmail.com>
Suggested-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
drivers/scsi/sd.c