Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1156431imm; Wed, 13 Jun 2018 14:27:16 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKslkFA8x1HufWo6waRqG/5oHD77wl9n+0GP0hDCxo8xeFzKXpen0wbp1rrfekSqHyxrLnh X-Received: by 2002:a17:902:3343:: with SMTP id a61-v6mr6715835plc.241.1528925236150; Wed, 13 Jun 2018 14:27:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528925236; cv=none; d=google.com; s=arc-20160816; b=K7vxX+JAcwZMS41o4L0R+CNIyfvFhMEW/kqTzWZWh8FtyoC0RWcgrSjD/5C79EsdmB OMJ+oN8XJwmYGKRzg551qMI3kWeej8S4eLWYBQdZGKcVDzJXMFivJ7az/OGF55GXIBE5 w5lkDlVIJU/IdsEDvbdwjWnwEf2om0WNIFdcaLlBaSeCXbScwi2COiswttf6Y1uJFcON dV7Urrxq6fJZlX1gtC05xWs1E/sbx5C5u7WshsT3E6aYcc3PeVcEP23jok3W+uRq0cMp 4AYIUAMAhMl//iTY8cE+LSQQ8/m2ivtYpq3x2PQawqLPSDgQ9JGJLb0gjIsD1LJ5IGdN tuiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:date:cc:to:from:subject :message-id:arc-authentication-results; bh=O2GAsriZczaN6uS20wfwFqh2ivO44NzniM57n/EWRqc=; b=0gFTIOa5rgoOEWeKSw2u57eB7lDQZ6TkeL+m/L6b+Jhomfd1+OXm/TlHsBZx0KMdIS OUDTQnajxyJ9dXR9bhP/8cX+kQ4VIG/TNhR6EieJB3qoUwLq1bST/R2chKpZUiftT65Y pz6Cr5v4ULXEiijUWXxSM2T8g+mHgKzsen7ybWIsw2t6Dmog6tzDjaesSPTCPfyUQ/o6 ozxUkikCVanc3NGa+OTYZumgvJlPsHJh1NkBvPIC7EPwlYWt554RYqxUYjKc4+1K4O42 fxJYxwS1oD0n4+bPt7IWMbG7SW+2I/cG1YBTgzQ0AfbmsC917aSlKvzU5R7CKYgKKXW7 xLLg== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=codethink.co.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r11-v6si3609777pfe.145.2018.06.13.14.27.02; Wed, 13 Jun 2018 14:27:16 -0700 (PDT) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=codethink.co.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936046AbeFMVZR (ORCPT + 99 others); Wed, 13 Jun 2018 17:25:17 -0400 Received: from imap1.codethink.co.uk ([176.9.8.82]:51405 "EHLO imap1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935846AbeFMVZP (ORCPT ); Wed, 13 Jun 2018 17:25:15 -0400 Received: from [148.252.241.226] (helo=xylophone) by imap1.codethink.co.uk with esmtpsa (Exim 4.84_2 #1 (Debian)) id 1fTDGQ-0001T1-V7; Wed, 13 Jun 2018 22:25:11 +0100 Message-ID: <1528925110.2289.175.camel@codethink.co.uk> Subject: Re: [PATCH 4.4 128/268] scsi: sd: Keep disk read-only when re-reading partition From: Ben Hutchings To: Jeremy Cline , "Martin K. Petersen" Cc: stable@vger.kernel.org, Li Ning , Sasha Levin , Greg Kroah-Hartman , LKML Date: Wed, 13 Jun 2018 22:25:10 +0100 In-Reply-To: <20180528100216.627623125@linuxfoundation.org> References: <20180528100202.045206534@linuxfoundation.org> <20180528100216.627623125@linuxfoundation.org> Organization: Codethink Ltd. Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.22.6-1+deb9u1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2018-05-28 at 12:01 +0200, Greg Kroah-Hartman wrote: > 4.4-stable review patch.  If anyone has any objections, please let me know. > > ------------------ > > From: Jeremy Cline > > [ 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. It seems to me that this change is likely to cause a regression: if a SCSI device switches from read-only to read-write state then a subsequent rescan won't automatically change the block device to read- write state. The administrator will have to use the blockdev command too. Even if this change in behaviour is acceptable, this commit does not implement it consistently. The function starts by clearing the ro flag and this commit only changes one of the three exit paths to preserve it. (The log message about Write Protect status also reports the underlying SCSI device flag and not the combined ro flag, but maybe that was intentional.) I think this commit should be reverted, both in stable and upstream. A proper fix would involve splitting the ro flag into two flags—one controlled by user-space and one read from the device—with the effective read-only status being the logical-or of those two. Ben. > Reported-by: Li Ning > Signed-off-by: Jeremy Cline > Signed-off-by: Martin K. Petersen > Signed-off-by: Sasha Levin > Signed-off-by: Greg Kroah-Hartman > --- >  drivers/scsi/sd.c |    3 ++- >  1 file changed, 2 insertions(+), 1 deletion(-) > > --- a/drivers/scsi/sd.c > +++ b/drivers/scsi/sd.c > @@ -2395,6 +2395,7 @@ sd_read_write_protect_flag(struct scsi_d >   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); > @@ -2435,7 +2436,7 @@ sd_read_write_protect_flag(struct scsi_d >     "Test WP failed, assume Write Enabled\n"); >   } else { >   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) { >   sd_printk(KERN_NOTICE, sdkp, "Write Protect is %s\n", >    sdkp->write_prot ? "on" : "off"); -- Ben Hutchings, Software Developer   Codethink Ltd https://www.codethink.co.uk/ Dale House, 35 Dale Street Manchester, M1 2HF, United Kingdom