public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/1] *** CD-ROM: LBA bound check in mmc_ioctl_cdrom_read_data ***
@ 2026-03-25  6:53 Felix Busch
  2026-03-25  7:44 ` [PATCH 1/1] CD-ROM: Additional LBA bound check Felix Busch
  0 siblings, 1 reply; 4+ messages in thread
From: Felix Busch @ 2026-03-25  6:53 UTC (permalink / raw)
  To: phil, James.Bottomley, martin.petersen
  Cc: linux-kernel, linux-scsi, Felix Busch

This introduces an upper-bound check for the Logical Block Address (LBA) in mmc_ioctl_cdrom_read_data 
within the CD-ROM driver. The change is motivated by two main reasons: first, there is currently no 
upper-bound check in place; second, adding this check can help improve execution performance.

There has already been a prior discussion on this topic about this check in mmc_ioctl_cdrom_read_data, 
but this patch follows a slight different approach, due a missunderstading in the SCSI-2 
documentation. (https://www.staff.uni-mainz.de/tacke/scsi/SCSI2-14.html)

Blocks are addressed here using a zero-based integer index. Therefore, it should be possible to check, 
that the LBA falls within the range 0 to N − 1, where N represents the total number of available blocks.

To get the number of blocks in mmc_ioctl_cdrom_read_data, a small inline function
has been added to access the capacity field of the scsi_cd struct, which already contains the
size in blocks available on the CD-ROM. The main reason for this addition is, that
it might be more performant accessing the value there, rather than recalculating the number 
of blocks again in mmc_ioctl_cdrom_read_data. Maybe there's another possibility of doing that, 
which I'm not aware of yet.

While examining the CD-ROM capacity, I noticed, that get_sectorsize changes the capacity value
by multiplying the current set value with four.
```
cd->capacity *= 4;
```
On the tested CD-ROM hardware, keeping this multiplication resulted in an incorrect CD-ROM capacity being reported.
With the line disabled, the capacity appears to be accurate. However, I'm not 100% sure whether this adjustment
may affect other hardware that rely on the original behavior.

One benefit of having an upper bound check for the LBA might be the execution duration of mmc_ioctl_cdrom_read_data.
With this check applied, mmc_ioctl_cdrom_read_data took an average of 0.2217 milliseconds, compared to 6.006 milliseconds
without the check. This performance improvement was observed specifically when the LBA exceeded the number of available
blocks, and the CD-ROM contained actual written data.

Thank you for your time.

Felix Busch (1):
CD-ROM: Additional LBA bound check

drivers/cdrom/cdrom.c |  7 +++++--
drivers/scsi/sr.c     | 12 +++++++++++-
include/linux/cdrom.h |  2 ++
3 files changed, 18 insertions(+), 3 deletions(-)

-- 
2.53.0


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

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

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-25  6:53 [PATCH 0/1] *** CD-ROM: LBA bound check in mmc_ioctl_cdrom_read_data *** Felix Busch
2026-03-25  7:44 ` [PATCH 1/1] CD-ROM: Additional LBA bound check Felix Busch
2026-03-25 12:55   ` James Bottomley
2026-03-26 18:11     ` Felix Busch

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