All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ana Bobillo <anabobillo3@gmail.com>
To: Tom Rini <trini@konsulko.com>
Cc: u-boot@lists.u-boot-project.org, Simon Glass <sjg@chromium.org>,
	Marek Vasut <marek.vasut+usb@mailbox.org>,
	Bin Meng <bmeng.cn@gmail.com>,
	Neil Armstrong <neil.armstrong@linaro.org>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Alexey Charkov <alchark@flipper.net>,
	Javier Martinez Canillas <javierm@redhat.com>
Subject: [PATCH v3 06/14] ide: Refuse an ATAPI block size atapi_read() cannot read
Date: Sun, 01 Nov 2026 07:02:13 +0000	[thread overview]
Message-ID: <01ead749-12ac-4dc3-83ae-eff40ce3ea7d@gmail.com> (raw)
In-Reply-To: <1ea4ecf3-70d8-4469-be94-1943ab8e3337@gmail.com>

From: Ana Bobillo <anabobillo3@gmail.com>

atapi_inquiry() takes the block size from the READ CAPACITY reply of an
ATAPI device as it is, while atapi_read() asks the device for, and moves
the buffer on by, ATAPI_READ_BLOCK_SIZE (2048) bytes for every block.
With any other block size the callers' buffers, which are sized by
blksz, do not match what atapi_read() writes into them: a 512-byte block
size makes a read of several blocks write past the end of the buffer.

Some CD drives report another block size although they read 2048-byte
blocks: 2340 (HP 4020i CD-Recorder), 2352 (Philips CD-Writers) or 0.
Take these as ATAPI_READ_BLOCK_SIZE, as Linux does in get_sectorsize(),
so that a drive reporting 0, which ide_probe() skipped until now, is
read with 2048-byte blocks too. Refuse any other value: a device
reporting one is left with a zero block size, which ide_probe() skips,
as for a drive without a medium. This refuses drives with 512-byte
blocks, such as ZIP drives, whose reads of more than one block already
overran the buffer; supporting them needs atapi_read() to use the block
size of the device.

Signed-off-by: Ana Bobillo <anabobillo3@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
(no changes since v2)

Changes in v2:
- Take 0, 2340 and 2352 as 2048, as Linux get_sectorsize() does (Simon)
- Say what is skipped in the message (Simon)

 drivers/block/ide.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index 44ce054bdf5..56e55bc8bc1 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -450,6 +450,7 @@ static void atapi_inquiry(struct blk_desc *desc)
 {
 	u8 ccb[12];	/* Command descriptor block */
 	u8 iobuf[64];	/* temp buf */
+	ulong blksz;
 	u8 c;
 	int device;
 
@@ -514,10 +515,28 @@ static void atapi_inquiry(struct blk_desc *desc)
 		  iobuf[0], iobuf[1], iobuf[2], iobuf[3],
 		  iobuf[4], iobuf[5], iobuf[6], iobuf[7]);
 
+	blksz = (ulong)iobuf[4] << 24 | (ulong)iobuf[5] << 16 |
+		(ulong)iobuf[6] << 8 | (ulong)iobuf[7];
+	/*
+	 * atapi_read() transfers ATAPI_READ_BLOCK_SIZE bytes per block. Some
+	 * CD drives report another size although they read 2048-byte blocks,
+	 * which Linux takes as 2048 in get_sectorsize(): do the same.
+	 */
+	switch (blksz) {
+	case 0:
+	case 2340:	/* HP 4020i CD-Recorder */
+	case 2352:	/* Philips CD-Writers */
+		blksz = ATAPI_READ_BLOCK_SIZE;
+		break;
+	case ATAPI_READ_BLOCK_SIZE:
+		break;
+	default:
+		printf("ATAPI block size %lu not supported, skipping\n", blksz);
+		return;
+	}
 	desc->lba = (ulong)iobuf[0] << 24 | (ulong)iobuf[1] << 16 |
 		(ulong)iobuf[2] << 8 | (ulong)iobuf[3];
-	desc->blksz = (ulong)iobuf[4] << 24 | (ulong)iobuf[5] << 16 |
-		(ulong)iobuf[6] << 8 | (ulong)iobuf[7];
+	desc->blksz = blksz;
 	desc->log2blksz = LOG2(desc->blksz);
 
 	/* ATAPI devices cannot use 48bit addressing (ATA/ATAPI v7) */

  parent reply	other threads:[~2026-11-01  7:02 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-01  7:01 [PATCH v3 00/14] block, disk: Check block sizes and partition tables of devices Ana Bobillo
2026-11-01  7:01 ` [PATCH v3 01/14] treewide: Use is_power_of_2() from linux/log2.h Ana Bobillo
2026-11-01  7:01 ` [PATCH v3 02/14] block: Add blk_valid_blksz() to check a block size Ana Bobillo
2026-11-01  7:01 ` [PATCH v3 03/14] usb: storage: Fix the capacity faked when READ CAPACITY fails Ana Bobillo
2026-11-01  7:01 ` [PATCH v3 04/14] usb: storage: Refuse a block size the block layer cannot use Ana Bobillo
2026-11-01  7:02 ` [PATCH v3 05/14] scsi: " Ana Bobillo
2026-11-01  7:02 ` Ana Bobillo [this message]
2026-11-01  7:02 ` [PATCH v3 07/14] nvme: Skip a namespace with an unsupported LBA data size Ana Bobillo
2026-11-01  7:02 ` [PATCH v3 08/14] block: Refuse a device with an unsupported block size Ana Bobillo
2026-11-01  7:02 ` [PATCH v3 09/14] disk: part_efi: Check the header and entry sizes of a GPT Ana Bobillo
2026-11-01  7:02 ` [PATCH v3 10/14] disk: part_dos: Walk the extended partition tables in a bounded loop Ana Bobillo
2026-11-01  7:02 ` [PATCH v3 11/14] disk: part_dos: Make room for a three-digit partition number in the UUID Ana Bobillo
2026-11-01  8:03   ` Heinrich Schuchardt
2026-11-01  8:43     ` Ana Bobillo
2026-11-01  7:02 ` [PATCH v3 12/14] efi_loader: Measure the GPT the partition driver uses Ana Bobillo
2026-11-01 14:59   ` Simon Glass
2026-11-01  7:03 ` [PATCH v3 13/14] efi_loader: Index the GPT entries directly in tcg2_measure_gpt_data() Ana Bobillo
2026-11-01 14:59   ` Simon Glass
2026-11-01  7:03 ` [PATCH v3 14/14] mmc: Always use a 512-byte block length Ana Bobillo
2026-11-01 15:01   ` Simon Glass

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=01ead749-12ac-4dc3-83ae-eff40ce3ea7d@gmail.com \
    --to=anabobillo3@gmail.com \
    --cc=alchark@flipper.net \
    --cc=bmeng.cn@gmail.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=javierm@redhat.com \
    --cc=marek.vasut+usb@mailbox.org \
    --cc=neil.armstrong@linaro.org \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.u-boot-project.org \
    --cc=xypron.glpk@gmx.de \
    /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.