Received: by 10.223.185.116 with SMTP id b49csp7472745wrg; Thu, 1 Mar 2018 06:10:21 -0800 (PST) X-Google-Smtp-Source: AG47ELtGD41q9HToe9mt9FYJ5NRyzT57Pz1jcBYpMlRf70VxB1EcYZQ5AxtRK4ILtEsgRme/WSCl X-Received: by 2002:a17:902:6b04:: with SMTP id o4-v6mr2092038plk.260.1519913420997; Thu, 01 Mar 2018 06:10:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519913420; cv=none; d=google.com; s=arc-20160816; b=vrXBsZcppF8jjAcwz7ZLnRVuQCBvsWS63HVsCXe6s9UeqIVZtyfNDLfcem4XetgfjI OhWyxvJ8rVg4eaqtK6EGXnJSIznsdkvd6otgD/SStWg5mHxMhxiphCwSfFXRwJznD6ee RQIy9sD5Ca02x/EqNnBj0mU0lfl4/y0zbEItLCEJD9zIPvOucT2TQexDOqEiOMUGC54G 3oZAyoFOGOFFTwbJU8d4KKMzbHDN5j6PGb/BbXkhwmamfWBPF7PTqSptNwtzOAS6AkoX nZplnUoJshCUacutmfs1x7qMthL7vsAPIwy/eTu/s/DVqylyuVpa+mdFnWXPrSD8F9h/ dvng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:feedback-id:message-id:date:subject:cc:to :from:dkim-signature:dkim-signature:arc-authentication-results; bh=1YGbU/uIlODzUZu0TqUyv9XuS+RoKAjvbFV2pJRKIbw=; b=evlVxw2IDbThZzWID6ycY6QsQJUMOJGsEuQCl9UQ/DxbU/pHl15J1qOBNIXjI5UXQV d/+dgxTtDFEgsKwQ3y5rILmbtJJ4yiEqSKth/lgPRZwbjDr/ROAfQp282z/GX3nfTG6l NyQoL4lsUl1MPIL1c8NfIckqehxTkCZrWvnwHa/tFpZmvEzthewO0UgAqlegr1vn2FuJ oj9FRbmbc1sVQG0OmfSecvkVk/JyUx4BfsbO5KQ45/ty/jIldmx1WS7WRUcfhUmb/6yj 82/XqJ4ZA0w0DOS7bwTUKG+DThDFd1OyWAB3E0ZSpSM4Yz9jJaO18TwZYUkQlLJs4Mib K92w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@jcline.org header.s=rdybrs3533vx7mghocfwl3vdwgpl2v5u header.b=QuIEo1Rx; dkim=pass header.i=@amazonses.com header.s=224i4yxa5dv7c2xz3womw6peuasteono header.b=Yavmi0QX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a13si3020786pfn.314.2018.03.01.06.09.59; Thu, 01 Mar 2018 06:10:20 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@jcline.org header.s=rdybrs3533vx7mghocfwl3vdwgpl2v5u header.b=QuIEo1Rx; dkim=pass header.i=@amazonses.com header.s=224i4yxa5dv7c2xz3womw6peuasteono header.b=Yavmi0QX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1031134AbeCAOIM (ORCPT + 99 others); Thu, 1 Mar 2018 09:08:12 -0500 Received: from a8-57.smtp-out.amazonses.com ([54.240.8.57]:52818 "EHLO a8-57.smtp-out.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030876AbeCAOIL (ORCPT ); Thu, 1 Mar 2018 09:08:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=rdybrs3533vx7mghocfwl3vdwgpl2v5u; d=jcline.org; t=1519913290; h=From:To:Cc:Subject:Date:Message-Id; bh=vtZRQCbLYt4AyztzalS6I3Rf54lSbXzyg8fYRVdf+hw=; b=QuIEo1RxRFgGDNQmZqla47FEL3KZoJPtGljgOqJeTBVZC8/3xDeDs2k7DYYSsghJ Ydo2RJVtxTyW/3nWvioiuBZ6oU4FFyNr452ACunTAIsyxEOeO5g1ChyHEQGZvImyj68 zgDiNeCLHt/5EjuowAUq274DGRL75i7ZOEeHIN0g= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=224i4yxa5dv7c2xz3womw6peuasteono; d=amazonses.com; t=1519913290; h=From:To:Cc:Subject:Date:Message-Id:Feedback-ID; bh=vtZRQCbLYt4AyztzalS6I3Rf54lSbXzyg8fYRVdf+hw=; b=Yavmi0QXjETZPm/ecU8xbqycnbjDYPmRZoey7uaeg9/6gq/hgvxgJaeoTFx4e7J0 MaAFgVJvAwBEKkASHmkNivYYqd3oRM/vXlhq8AW9dqG0r3ltnelFZ2NZBdwlA4g1iCW ag27e5MhPgAFbY2HCrxdH7Cy86bpQ/OD7p3iR3dA= X-Virus-Scanned: amavisd-new at jcline.org From: Jeremy Cline To: "James E . J . Bottomley" , "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Jeremy Cline Subject: [PATCH] scsi: sd: Keep disk read-only when re-reading partition Date: Thu, 1 Mar 2018 14:08:10 +0000 Message-ID: <01000161e1e448a5-d54e05d2-58f2-4480-b05b-67185d4ffae7-000000@email.amazonses.com> X-Mailer: git-send-email 2.16.2 X-SES-Outgoing: 2018.03.01-54.240.8.57 Feedback-ID: 1.us-east-1.z18Isoc/FaoPOvCyJyi1mnTt8STwoRuibXVNoUcvG6g=:AmazonSES Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Jeremy Cline --- drivers/scsi/sd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index bff21e636ddd..7a3a66a7890f 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -2595,6 +2595,7 @@ sd_read_write_protect_flag(struct scsi_disk *sdkp, unsigned char *buffer) int res; struct scsi_device *sdp = sdkp->device; struct scsi_mode_data data; + int disk_ro = get_disk_ro(sdkp->disk); int old_wp = sdkp->write_prot; set_disk_ro(sdkp->disk, 0); @@ -2634,7 +2635,8 @@ sd_read_write_protect_flag(struct scsi_disk *sdkp, unsigned char *buffer) sd_first_printk(KERN_WARNING, sdkp, "Test WP failed, assume Write Enabled\n"); } else { - sdkp->write_prot = ((data.device_specific & 0x80) != 0); + sdkp->write_prot = ((data.device_specific & 0x80) != 0) || + disk_ro; set_disk_ro(sdkp->disk, sdkp->write_prot); if (sdkp->first_scan || old_wp != sdkp->write_prot) { sd_printk(KERN_NOTICE, sdkp, "Write Protect is %s\n", -- 2.16.2