Skip to contentSkip to conversation

scsi: sr: exclude CDC_MRW_W and CDC_RAM from writeable check

PATCH RESEND In review Daan De Meyer 2 participants 3 messages Apr 15 – Apr 22 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 scsi: sr: exclude CDC_MRW_W and CDC_RAM from writeable check

The writeable check in get_capabilities() includes CDC_MRW_W and CDC_RAM in its bitmask, but these capabilities are not determined from the MODE SENSE capabilities page. They require the SCSI GET CONFIGURATION command, which is only issued later by cdrom_open_write() at device open time.

Since cdi.mask is initialized to zero (all capabilities assumed present), CDC_MRW_W and CDC_RAM are left unmasked by default. This makes the writeable check always true when MODE SENSE succeeds, regardless of the drive's actual write capabilities as reported in the capabilities page.

Fix this by only checking CDC_DVD_RAM and CDC_CD_RW in the writeable condition, as these are the write capabilities actually determined from the MODE SENSE capabilities page. CDC_MRW_W and CDC_RAM will continue to be evaluated by cdrom_open_write() at open time via GET CONFIGURATION.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 drivers/scsi/sr.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/scsi/sr.c +7 -3
index 8ed002f82e36..0a6413b77dd3 100644
@@ -901,10 +901,14 @@ static int get_capabilities(struct scsi_cd *cd)
 		cd->cdi.mask |= CDC_CLOSE_TRAY; */
 
 	/*
-	 * if DVD-RAM, MRW-W or CD-RW, we are randomly writable
+	 * Check if the drive has write capabilities. Only consider
+	 * capabilities that are determined from the MODE SENSE capabilities
+	 * page here. CDC_MRW_W (MRW writing) and CDC_RAM (random writable)
+	 * require the SCSI GET CONFIGURATION command to determine, which
+	 * is issued later by cdrom_open_write() at device open time.
 	 */
-	if ((cd->cdi.mask & (CDC_DVD_RAM | CDC_MRW_W | CDC_RAM | CDC_CD_RW)) !=
-			(CDC_DVD_RAM | CDC_MRW_W | CDC_RAM | CDC_CD_RW)) {
+	if ((cd->cdi.mask & (CDC_DVD_RAM | CDC_CD_RW)) !=
+			(CDC_DVD_RAM | CDC_CD_RW)) {
 		cd->writeable = 1;
 	}
 
Signature · 1 line
2.53.0
#1 lore raw

Daan,

Quoted 5 lines

The writeable check in get_capabilities() includes CDC_MRW_W and CDC_RAM in its bitmask, but these capabilities are not determined from the MODE SENSE capabilities page. They require the SCSI GET CONFIGURATION command, which is only issued later by cdrom_open_write() at device open time.

Reviewing this involved quite a bit of digging through ancient specs...

I don't particularly like how that decision process is split between sr.c and cdrom.c.

My preference would be to defer setting the device writable state until after GET CONFIGURATION has been called in cdrom.c.

Signature · 1 line
Martin K. Petersen
#2 lore raw

Martin,

Quoted 2 lines

My preference would be to defer setting the device writable state until after GET CONFIGURATION has been called in cdrom.c.

This doesn't quite work because that means BLKROGET would return read-only for writable cd-rom devices until someone tried to open them RDWR which seems unintuitive. I've sent a v2
(https://lore.kernel.org/linux-scsi/[email protected]/T/#u)
that instead moves the GET CONFIGURATION probe earlier before we call register_cdrom() so that set_disk_ro() can be called inside register_cdrom() based on the mask.

Daan

Quoted 20 lines · Martin K. Petersen

Daan,

Quoted 5 lines

The writeable check in get_capabilities() includes CDC_MRW_W and CDC_RAM in its bitmask, but these capabilities are not determined from the MODE SENSE capabilities page. They require the SCSI GET CONFIGURATION command, which is only issued later by cdrom_open_write() at device open time.

Reviewing this involved quite a bit of digging through ancient specs...

I don't particularly like how that decision process is split between sr.c and cdrom.c.

My preference would be to defer setting the device writable state until after GET CONFIGURATION has been called in cdrom.c.

--
Martin K. Petersen