Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1966258imm; Thu, 24 May 2018 03:43:47 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr7+SqCxzKornQ8oVvbCf/wuEI+PjuoJsPmQchF/HalI+ATXgw1cMXpIwIZIwszb90TI6rc X-Received: by 2002:a17:902:229:: with SMTP id 38-v6mr6847790plc.384.1527158627528; Thu, 24 May 2018 03:43:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527158627; cv=none; d=google.com; s=arc-20160816; b=spjObSe4bRKWbMIdKdwYyhKoytG1wlYzaa7lDQxQNmfTUWfkNc66Ik0iYRgOEDNsLZ h5Saqi9mTnF48tTz3+cVUrhvM59y0X65jhQbwDrw/1/mMONvBRa26mKXq0Qb1Q0ucBpU cnnTbBTKOG5IHci0zwF2KuAQWz5X/oXGPF+vUcYD4aJGfnuIe4DUCXixN3a7xNcYLnWI OL6DIhMZNDGcoHktq4qDEvfU2rVi3ByCM31qYVDPMBBiGhcc3PjEc/ReoaELHxYr4LvV JIAIr0igXNIv8fI18HRWYW4Sqo53XC+eq8xv/u8AlcziyIe8TbU2D53yRV8f2Pn84Kvn zjnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=JyJwox/fdV9F264BfhUzZIKr78Yfec57U5toqMfE3D0=; b=bUBoQtsvTac62cdIxKaosyXrIEzxN3fKFwTrb5v2puCOJCgv9nOa+9FWiF7EcNyfNW HVb5CTBTtwWUyCmOREtOGA3zUYf3dC4VPGodQV4eeL4F9SkEYyaiD08MtwpYWKV9BOIq nwcK58NsaRIdOWiP4gk0AYQddF9nnlhSeMpqDc9IB/SsOQFZ7t9XJ7DzJd0PcvW+fB+a GHrwpjqY6Hp0KefeNTV1AwZUxeQeE0U7GCX6xwaWQbtj2Sb4nimQSydsa0WuKHDAf4Oh JROlFED8kxUAiZQfJ+mFUvnUMlKUYKSnZU4DW43VP6FacVqytDZuJn7lzk9QWmEje6JP qPHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=w1rwlG5d; 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 t189-v6si16901559pgc.163.2018.05.24.03.43.32; Thu, 24 May 2018 03:43:47 -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; dkim=pass header.i=@kernel.org header.s=default header.b=w1rwlG5d; 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 S1030610AbeEXJ61 (ORCPT + 99 others); Thu, 24 May 2018 05:58:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:38120 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030590AbeEXJ6T (ORCPT ); Thu, 24 May 2018 05:58:19 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 31E212088E; Thu, 24 May 2018 09:58:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155898; bh=I9KsV1Tug8eWquNPW5UTcwWLIg/M8Ll1DAd6NM/w+i0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=w1rwlG5dUU3eXqSE2q7ZYjx8pG2+obJunH+w8hhxMc7zZO5uef7A6bwIpO+QrZWWs oNgurZLvKXVIlglZ9JuUHOSsVp3eZzIVKtwXLQdWJMInUTnk0Upht7F8mHj4DoUgE3 gAYdAnTK0l3UjfaAa0XU6JtK4eLhv0H2ehjYXTGo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Li Ning , Jeremy Cline , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.14 113/165] scsi: sd: Keep disk read-only when re-reading partition Date: Thu, 24 May 2018 11:38:39 +0200 Message-Id: <20180524093626.593183238@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093621.979359379@linuxfoundation.org> References: <20180524093621.979359379@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-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. 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 @@ -2608,6 +2608,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); @@ -2648,7 +2649,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");