Linux ATA/IDE development
 help / color / mirror / Atom feed
* [PATCH] ata: libata-scsi: avoid READ CAPACITY 16 underflow
@ 2026-11-03 10:53 shao.mingyin
  2026-11-03 11:05 ` sashiko-bot
  0 siblings, 1 reply; 3+ messages in thread
From: shao.mingyin @ 2026-11-03 10:53 UTC (permalink / raw)
  To: dlemoal, cassel, linux-ide; +Cc: linux-kernel, stable

ata_scsiop_read_cap() starts with

	u64 last_lba = dev->n_sectors - 1;

ata_dev_configure() sets n_sectors to zero for security locked drives, to
prevent any I/O.  The READ CAPACITY 10 branch clamps the resulting
underflow to 0xffffffff (still wrong, but bounded), while READ CAPACITY 16
has no clamp and reports 0xffffffffffffffff, i.e. a capacity of about
8 ZiB, to the SCSI layer.

Use a zero last LBA when the device has no sectors.

Fixes: 61d79a8eb362 ("libata: Report disk alignment and physical block size")
Cc: stable@vger.kernel.org
Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
---
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index a61fb0331279..eaf86dc2cefc 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -2984,7 +2984,7 @@ static unsigned int ata_scsiop_read_cap(struct ata_device *dev,
 					struct scsi_cmnd *cmd, u8 *rbuf)
 {
 	u8 *scsicmd = cmd->cmnd;
-	u64 last_lba = dev->n_sectors - 1; /* LBA of the last block */
+	u64 last_lba = dev->n_sectors ? dev->n_sectors - 1 : 0; /* LBA of the last block */
 	u32 sector_size; /* physical sector size in bytes */
 	u8 log2_per_phys;
 	u16 lowest_aligned;

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

end of thread, other threads:[~2026-11-03 11:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-03 10:53 [PATCH] ata: libata-scsi: avoid READ CAPACITY 16 underflow shao.mingyin
2026-11-03 11:05 ` sashiko-bot
2026-11-03 11:59   ` shao.mingyin

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