mirror-linux/drivers/scsi
Daan De Meyer 0898a81762 cdrom, scsi: sr: propagate read-only status to block layer via set_disk_ro()
The cdrom core never calls set_disk_ro() for a registered device, so
BLKROGET on a CD-ROM device always returns 0 (writable), even when the
drive has no write capabilities and writes will inevitably fail. This
causes problems for userspace that relies on BLKROGET to determine
whether a block device is read-only. For example, systemd's loop device
setup uses BLKROGET to decide whether to create a loop device with
LO_FLAGS_READ_ONLY. Without the read-only flag, writes pass through the
loop device to the CD-ROM and fail with I/O errors. systemd-fsck
similarly checks BLKROGET to decide whether to run fsck in no-repair
mode (-n).

The write-capability bits in cdi->mask come from two different sources:
CDC_DVD_RAM and CDC_CD_RW are populated by the driver from the MODE
SENSE capabilities page (page 0x2A) before register_cdrom() is called,
while CDC_MRW_W and CDC_RAM require the MMC GET CONFIGURATION command
and were only probed by cdrom_open_write() at device open time. This
meant that any attempt to compute the writable state from the full
mask at probe time was incorrect, because the GET CONFIGURATION bits
were still unset (and cdi->mask is initialized such that capabilities
are assumed present).

Fix this by factoring the GET CONFIGURATION probing out of
cdrom_open_write() into a new exported helper,
cdrom_probe_write_features(), and having sr call it from sr_probe()
right after get_capabilities() has populated the MODE SENSE bits.
register_cdrom() then calls set_disk_ro() based on the full
write-capability mask (CDC_DVD_RAM | CDC_MRW_W | CDC_RAM | CDC_CD_RW)
so the block layer reflects the drive's actual write support. The
feature queries used (CDF_MRW and CDF_RWRT via GET CONFIGURATION with
RT=00) report drive-level capabilities that are persistent across
media, so a single probe before register_cdrom() is sufficient and the
redundant probe at open time is dropped.

With set_disk_ro() now accurate, the long-vestigial cd->writeable flag
in sr can go: get_capabilities() used to set cd->writeable based on
the same four mask bits, but because CDC_MRW_W and CDC_RAM default to
"capability present" in cdi->mask and aren't touched by MODE SENSE,
the condition that gated cd->writeable was always true, making it
unconditionally 1. Replace the corresponding gate in sr_init_command()
with get_disk_ro(cd->disk), which turns a previously no-op check into
a real one and also catches kernel-internal bio writers that bypass
blkdev_write_iter()'s bdev_read_only() check.

The sd driver (SCSI disks) does not have this problem because it
checks the MODE SENSE Write Protect bit and calls set_disk_ro()
accordingly. The sr driver cannot use the same approach because the
MMC specification does not define the WP bit in the MODE SENSE
device-specific parameter byte for CD-ROM devices.

Fixes: 1da177e4c3 ("Linux-2.6.12-rc2")
Signed-off-by: Daan De Meyer <daan@amutable.com>
Reviewed-by: Phillip Potter <phil@philpotter.co.uk>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Phillip Potter <phil@philpotter.co.uk>
Link: https://patch.msgid.link/20260427210139.1400-2-phil@philpotter.co.uk
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2026-04-27 15:52:51 -06:00
..
aacraid Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses 2026-02-22 08:26:33 -08:00
aic7xxx scsi: aic7xxx: Fix compiler warnings triggered by user space code 2026-04-02 21:18:12 -04:00
aic94xx Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
arcmsr scsi: Change the return type of the .queuecommand() callback 2026-01-23 21:32:34 -05:00
arm Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
be2iscsi Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses 2026-02-22 08:26:33 -08:00
bfa Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
bnx2fc ipv6: convert CONFIG_IPV6 to built-in only and clean up Kconfigs 2026-03-29 11:21:22 -07:00
bnx2i ipv6: convert CONFIG_IPV6 to built-in only and clean up Kconfigs 2026-03-29 11:21:22 -07:00
csiostor Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses 2026-02-22 08:26:33 -08:00
cxgbi ipv6: convert CONFIG_IPV6 to built-in only and clean up Kconfigs 2026-03-29 11:21:22 -07:00
device_handler Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
elx scsi: target: Use driver completion preference by default 2026-02-28 21:04:02 -05:00
esas2r scsi: esas2r: Fix __printf annotation on esas2r_log_master() 2026-03-27 16:29:50 -04:00
fcoe Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
fnic scsi: fnic: Make fnic_queuecommand() easier to analyze 2026-02-28 17:17:39 -05:00
hisi_sas Merge branch 7.0/scsi-fixes into 7.1/scsi-staging 2026-04-02 20:31:22 -04:00
ibmvscsi scsi: ibmvfc: Fix OOB access in ibmvfc_discover_targets_done() 2026-03-19 21:42:35 -04:00
ibmvscsi_tgt scsi: target: Use driver completion preference by default 2026-02-28 21:04:02 -05:00
isci scsi: isci: Avoid -Wflex-array-member-not-at-end warning 2025-10-20 12:00:11 -04:00
libfc Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
libsas Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
lpfc Merge patch series "Update lpfc to revision 15.0.0.0" 2026-04-02 21:35:53 -04:00
megaraid scsi: megaraid_sas: Protect more code with instance->reset_mutex 2026-02-28 17:17:45 -05:00
mpi3mr scsi: mpi3mr: Fix typo 2026-04-08 22:26:30 -04:00
mpt3sas Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses 2026-02-22 08:26:33 -08:00
mvsas Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
pcmcia Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
pm8001 Merge branch '7.0/scsi-queue' into 7.0/scsi-fixes 2026-02-23 13:39:58 -05:00
qedf Convert more 'alloc_obj' cases to default GFP_KERNEL arguments 2026-02-21 20:03:00 -08:00
qedi Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses 2026-02-22 08:26:33 -08:00
qla2xxx scsi: qla2xxx: Use nr_cpu_ids instead of NR_CPUS for qp_cpu_map allocation 2026-04-08 22:33:39 -04:00
qla4xxx Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
smartpqi Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses 2026-02-22 08:26:33 -08:00
snic Merge branch '7.0/scsi-queue' into 7.0/scsi-fixes 2026-02-23 13:39:58 -05:00
sym53c8xx_2 Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
.gitignore
3w-9xxx.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
3w-9xxx.h
3w-sas.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
3w-sas.h
3w-xxxx.c scsi: Change the return type of the .queuecommand() callback 2026-01-23 21:32:34 -05:00
3w-xxxx.h
53c700.c Convert more 'alloc_obj' cases to default GFP_KERNEL arguments 2026-02-21 20:03:00 -08:00
53c700.h
53c700.scr
53c700_d.h_shipped
BusLogic.c scsi: BusLogic: Replace deprecated strcpy() + strcat() in blogic_rdconfig() 2026-02-24 13:12:29 -05:00
BusLogic.h scsi: Change the return type of the .queuecommand() callback 2026-01-23 21:32:34 -05:00
FlashPoint.c
Kconfig scsi: iscsi_tcp: Remove unneeded selections of CRYPTO and CRYPTO_MD5 2026-04-08 21:41:39 -04:00
Makefile scsi: cxlflash: Remove driver 2025-02-03 18:04:55 -05:00
NCR5380.c scsi: Change the return type of the .queuecommand() callback 2026-01-23 21:32:34 -05:00
NCR5380.h scsi: NCR5380: Clean up indentation 2024-08-12 22:05:50 -04:00
a100u2w.c scsi: Change the return type of the .queuecommand() callback 2026-01-23 21:32:34 -05:00
a100u2w.h
a2091.c
a2091.h
a3000.c scsi: Switch back to struct platform_driver::remove() 2024-11-06 20:45:25 -05:00
a3000.h
a4000t.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
advansys.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
aha152x.c scsi: Change the return type of the .queuecommand() callback 2026-01-23 21:32:34 -05:00
aha152x.h
aha1542.c scsi: Change the return type of the .queuecommand() callback 2026-01-23 21:32:34 -05:00
aha1542.h
aha1740.c scsi: Change the return type of the .queuecommand() callback 2026-01-23 21:32:34 -05:00
aha1740.h
am53c974.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
atari_scsi.c scsi: Switch back to struct platform_driver::remove() 2024-11-06 20:45:25 -05:00
atp870u.c scsi: Change the return type of the .queuecommand() callback 2026-01-23 21:32:34 -05:00
atp870u.h
bvme6000_scsi.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
ch.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
constants.c
dc395x.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
dc395x.h
dmx3191d.c scsi: Constify struct pci_device_id 2024-12-09 21:59:52 -05:00
esp_scsi.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
esp_scsi.h scsi: esp: Fix variable typo 2025-01-02 13:42:35 -05:00
fdomain.c scsi: Change the return type of the .queuecommand() callback 2026-01-23 21:32:34 -05:00
fdomain.h
fdomain_isa.c
fdomain_pci.c scsi: Constify struct pci_device_id 2024-12-09 21:59:52 -05:00
g_NCR5380.c
gvp11.c
gvp11.h
hosts.c scsi: core: Revert "Fix a regression triggered by scsi_host_busy()" 2026-01-11 22:07:36 -05:00
hpsa.c Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses 2026-02-22 08:26:33 -08:00
hpsa.h scsi: hpsa: Enlarge controller and IRQ name buffers 2026-04-02 21:09:43 -04:00
hpsa_cmd.h
hptiop.c scsi: Change the return type of the .queuecommand() callback 2026-01-23 21:32:34 -05:00
hptiop.h
imm.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
imm.h
initio.c scsi: Change the return type of the .queuecommand() callback 2026-01-23 21:32:34 -05:00
initio.h
ipr.c Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses 2026-02-22 08:26:33 -08:00
ipr.h move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
ips.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
ips.h scsi: switch ->bios_param() to passing gendisk 2025-08-13 02:59:28 -04:00
iscsi_boot_sysfs.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
iscsi_tcp.c scsi: iscsi_tcp: update outdated comment for renamed iscsi_conn_set_callbacks() 2026-03-27 16:51:15 -04:00
iscsi_tcp.h scsi: iscsi_tcp: Switch to using the crc32c library 2025-02-12 22:05:10 -05:00
jazz_esp.c scsi: Switch back to struct platform_driver::remove() 2024-11-06 20:45:25 -05:00
lasi700.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
libiscsi.c scsi: Change the return type of the .queuecommand() callback 2026-01-23 21:32:34 -05:00
libiscsi_tcp.c scsi: iscsi_tcp: Switch to using the crc32c library 2025-02-12 22:05:10 -05:00
mac53c94.c Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses 2026-02-22 08:26:33 -08:00
mac53c94.h
mac_esp.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
mac_scsi.c scsi: Switch back to struct platform_driver::remove() 2024-11-06 20:45:25 -05:00
megaraid.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
megaraid.h scsi: Change the return type of the .queuecommand() callback 2026-01-23 21:32:34 -05:00
mesh.c scsi: Change the return type of the .queuecommand() callback 2026-01-23 21:32:34 -05:00
mesh.h
mvme16x_scsi.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
mvme147.c
mvme147.h
mvumi.c Convert more 'alloc_obj' cases to default GFP_KERNEL arguments 2026-02-21 20:03:00 -08:00
mvumi.h
myrb.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
myrb.h scsi: myrb: Simplify an alloc_ordered_workqueue() invocation 2024-08-22 21:28:56 -04:00
myrs.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
myrs.h scsi: myrs: Simplify an alloc_ordered_workqueue() invocation 2024-08-22 21:28:56 -04:00
ncr53c8xx.c scsi: Change the return type of the .queuecommand() callback 2026-01-23 21:32:34 -05:00
ncr53c8xx.h
nsp32.c scsi: Change the return type of the .queuecommand() callback 2026-01-23 21:32:34 -05:00
nsp32.h
nsp32_debug.c
nsp32_io.h
pmcraid.c Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses 2026-02-22 08:26:33 -08:00
pmcraid.h
ppa.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
ppa.h
ps3rom.c scsi: Change the return type of the .queuecommand() callback 2026-01-23 21:32:34 -05:00
qla1280.c scsi: Change the return type of the .queuecommand() callback 2026-01-23 21:32:34 -05:00
qla1280.h scsi: qla1280: Fix hw revision numbering for ISP1020/1040 2024-11-20 21:32:48 -05:00
qlogicfas.c
qlogicfas408.c scsi: Change the return type of the .queuecommand() callback 2026-01-23 21:32:34 -05:00
qlogicfas408.h scsi: Change the return type of the .queuecommand() callback 2026-01-23 21:32:34 -05:00
qlogicpti.c scsi: Change the return type of the .queuecommand() callback 2026-01-23 21:32:34 -05:00
qlogicpti.h
raid_class.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
script_asm.pl
scsi.c scsi: core: Support allocating a pseudo SCSI device 2025-11-12 17:02:31 -05:00
scsi_bsg.c scsi: bsg: fix buffer overflow in scsi_bsg_uring_cmd() 2026-04-10 06:41:26 -06:00
scsi_common.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
scsi_debug.c Convert more 'alloc_obj' cases to default GFP_KERNEL arguments 2026-02-21 20:03:00 -08:00
scsi_debugfs.c
scsi_debugfs.h
scsi_devinfo.c scsi: devinfo: Add BLIST_SKIP_IO_HINTS for Iomega ZIP 2026-02-28 18:18:05 -05:00
scsi_dh.c scsi: device_handler: Return error pointer in scsi_dh_attached_handler_name() 2025-12-08 22:04:38 -05:00
scsi_error.c for-7.0/block-20260206 2026-02-09 17:57:21 -08:00
scsi_ioctl.c block: remove the q argument from blk_rq_map_kern 2025-05-07 07:31:07 -06:00
scsi_lib.c scsi: core: Add 'serial' sysfs attribute for SCSI/SATA 2026-02-28 20:03:00 -05:00
scsi_lib_dma.c
scsi_lib_test.c scsi: core: Add passthrough tests for success and no failure definitions 2025-01-21 12:16:17 -05:00
scsi_logging.c scsi: core: Do not declare scsi_cmnd pointers const 2025-10-21 21:11:35 -04:00
scsi_logging.h
scsi_netlink.c
scsi_pm.c scsi: pm: Drop unneeded call to pm_runtime_mark_last_busy() 2025-11-12 20:56:38 -05:00
scsi_priv.h scsi: core: Introduce an enumeration type for the SCSI_MLQUEUE constants 2025-12-16 22:20:26 -05:00
scsi_proc.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
scsi_proto_test.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
scsi_sas_internal.h
scsi_scan.c Merge branch 7.0/scsi-fixes into 7.1/scsi-staging 2026-04-02 20:31:22 -04:00
scsi_sysctl.c scsi: logging: Fix scsi_logging_level bounds 2025-03-03 22:11:48 -05:00
scsi_sysfs.c scsi: core: Add 'serial' sysfs attribute for SCSI/SATA 2026-02-28 20:03:00 -05:00
scsi_trace.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
scsi_transport_api.h
scsi_transport_fc.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
scsi_transport_iscsi.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
scsi_transport_sas.c scsi: scsi_transport_sas: Fix the maximum channel scanning issue 2026-03-19 21:57:22 -04:00
scsi_transport_spi.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
scsi_transport_srp.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
scsicam.c scsi: switch ->bios_param() to passing gendisk 2025-08-13 02:59:28 -04:00
sd.c scsi: sd: fix missing put_disk() when device_add(&disk_dev) fails 2026-04-08 22:10:44 -04:00
sd.h block: introduce disk_report_zone() 2025-11-05 08:07:21 -07:00
sd_dif.c block: introduce pi_tuple_size field in blk_integrity 2025-07-01 14:00:15 +02:00
sd_trace.h
sd_zbc.c block: introduce disk_report_zone() 2025-11-05 08:07:21 -07:00
sense_codes.h
ses.c scsi: ses: Handle positive SCSI error from ses_recv_diag() 2026-03-19 21:33:28 -04:00
sg.c scsi: sg: Remove deprecated sg-big-buff 2026-02-28 20:25:04 -05:00
sgiwd93.c scsi: Switch back to struct platform_driver::remove() 2024-11-06 20:45:25 -05:00
sim710.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
sni_53c710.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
sr.c cdrom, scsi: sr: propagate read-only status to block layer via set_disk_ro() 2026-04-27 15:52:51 -06:00
sr.h cdrom, scsi: sr: propagate read-only status to block layer via set_disk_ro() 2026-04-27 15:52:51 -06:00
sr_ioctl.c minmax: scsi: fix mis-use of 'clamp()' in sr.c 2024-07-28 17:06:20 -07:00
sr_vendor.c
st.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
st.h scsi: st: Modify st.c to use the new scsi_error counters 2025-02-03 17:43:31 -05:00
st_options.h
stex.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
storvsc_drv.c scsi: storvsc: Handle PERSISTENT_RESERVE_IN truncation for Hyper-V vFC 2026-04-08 21:52:06 -04:00
sun3_scsi.c scsi: sun3: Mark driver struct with __refdata to prevent section mismatch 2024-11-06 21:06:44 -05:00
sun3_scsi_vme.c
sun3x_esp.c scsi: Switch back to struct platform_driver::remove() 2024-11-06 20:45:25 -05:00
sun_esp.c scsi: Switch back to struct platform_driver::remove() 2024-11-06 20:45:25 -05:00
virtio_scsi.c scsi: virtio_scsi: Kick event_list unconditionally 2026-03-27 16:42:08 -04:00
vmw_pvscsi.c Convert more 'alloc_obj' cases to default GFP_KERNEL arguments 2026-02-21 20:03:00 -08:00
vmw_pvscsi.h
wd33c93.c scsi: Change the return type of the .queuecommand() callback 2026-01-23 21:32:34 -05:00
wd33c93.h scsi: Change the return type of the .queuecommand() callback 2026-01-23 21:32:34 -05:00
wd719x.c scsi: Change the return type of the .queuecommand() callback 2026-01-23 21:32:34 -05:00
wd719x.h
xen-scsifront.c xen: branch for v7.0-rc3 2026-03-07 07:44:32 -08:00
zalon.c scsi: zalon: Remove trailing space after \n newline 2024-09-12 20:25:43 -04:00
zorro7xx.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
zorro_esp.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00