mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	scsi: sd: Keep disk read-only when re-reading partition
If the read-only flag is true on a SCSI disk, re-reading the partition table sets the flag back to false. To observe this bug, you can run: 1. blockdev --setro /dev/sda 2. blockdev --rereadpt /dev/sda 3. blockdev --getro /dev/sda This commit reads the disk's old state and combines it with the device disk-reported state rather than unconditionally marking it as RW. Reported-by: Li Ning <lining916740672@icloud.com> Signed-off-by: Jeremy Cline <jeremy@jcline.org> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
This commit is contained in:
		
							parent
							
								
									6a2cf8d366
								
							
						
					
					
						commit
						20bd1d026a
					
				
					 1 changed files with 2 additions and 1 deletions
				
			
		| 
						 | 
					@ -2624,6 +2624,7 @@ sd_read_write_protect_flag(struct scsi_disk *sdkp, unsigned char *buffer)
 | 
				
			||||||
	int res;
 | 
						int res;
 | 
				
			||||||
	struct scsi_device *sdp = sdkp->device;
 | 
						struct scsi_device *sdp = sdkp->device;
 | 
				
			||||||
	struct scsi_mode_data data;
 | 
						struct scsi_mode_data data;
 | 
				
			||||||
 | 
						int disk_ro = get_disk_ro(sdkp->disk);
 | 
				
			||||||
	int old_wp = sdkp->write_prot;
 | 
						int old_wp = sdkp->write_prot;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	set_disk_ro(sdkp->disk, 0);
 | 
						set_disk_ro(sdkp->disk, 0);
 | 
				
			||||||
| 
						 | 
					@ -2664,7 +2665,7 @@ sd_read_write_protect_flag(struct scsi_disk *sdkp, unsigned char *buffer)
 | 
				
			||||||
			  "Test WP failed, assume Write Enabled\n");
 | 
								  "Test WP failed, assume Write Enabled\n");
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		sdkp->write_prot = ((data.device_specific & 0x80) != 0);
 | 
							sdkp->write_prot = ((data.device_specific & 0x80) != 0);
 | 
				
			||||||
		set_disk_ro(sdkp->disk, sdkp->write_prot);
 | 
							set_disk_ro(sdkp->disk, sdkp->write_prot || disk_ro);
 | 
				
			||||||
		if (sdkp->first_scan || old_wp != sdkp->write_prot) {
 | 
							if (sdkp->first_scan || old_wp != sdkp->write_prot) {
 | 
				
			||||||
			sd_printk(KERN_NOTICE, sdkp, "Write Protect is %s\n",
 | 
								sd_printk(KERN_NOTICE, sdkp, "Write Protect is %s\n",
 | 
				
			||||||
				  sdkp->write_prot ? "on" : "off");
 | 
									  sdkp->write_prot ? "on" : "off");
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue