scsi: sd: Keep disk read-only when re-reading partition
authorJeremy Cline <jeremy@jcline.org>
Tue, 6 Mar 2018 21:47:32 +0000 (21:47 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 25 May 2018 14:13:08 +0000 (16:13 +0200)
commit466a2b7ac9fb99ddc0ff1771c31194d9855997d2
tree5390b214b602d9f642006b1d7bf821d10c3dfd85
parent4a8907dc9fa9d54c4a4a09a386ec453d3c1128db
scsi: sd: Keep disk read-only when re-reading partition

[ Upstream commit 20bd1d026aacc5399464f8328f305985c493cde3 ]

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>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/scsi/sd.c