Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2515061imm; Mon, 28 May 2018 09:32:06 -0700 (PDT) X-Google-Smtp-Source: AB8JxZprEJVm2aY8mioBJIxH+3AGU9sGQF3wo8Cb5ql/wrby+/na1VxuElJ3isE2VWHfrmpJqzpR X-Received: by 2002:a62:8ac1:: with SMTP id o62-v6mr14237253pfk.141.1527525126787; Mon, 28 May 2018 09:32:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527525126; cv=none; d=google.com; s=arc-20160816; b=zBsjVVJWUpEX0I/ykgFZAsym//NLGYEBMuG6fnIDa1GFoogyvRVfREtedfRjKgvTEC A4iNLgZR9IdDitz2z1X4R9e6AdZ5P0KHkyalvjviNp7uVIjU160mJHHeuPWysd32Sa2k vudVOPw3R7ZAC7sdjhUr9sIXigRnoE+Yh+nA/fTyVBYhoR98MRxLs1wgAUlduEFXvctf 3KMnoGIcjvMBfbEMhTaQ1p83jjeR+kbxHjkpdxSjazDOoomXCIDWTrtAh0oVrX1lcufl BIYGwC46qCJ3MXvDnzeiI96KC4GWuOlzJK9mmhp6r159ovQefaxtS0IsDXozdHgfs0uF yCfg== 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=IJKQ9WOJcZYbqKVtP3tLwgtv3LCAw4Skw+wuwnXyyUI=; b=jeAqL9IcZvxs9Pxv9stnDEQ6aOAEXnDiHtAGdQqwFtl/72TObIDODfxey7vx9ZUvap zarp8aF1xv9mrBe4YuvTR2TYOKSc6drmCpHu5B+cUkL5PeKAZ3iBNNSIuegXCWXW62x8 rEg8L+EawNiQ63JKExoqDWrYQTidhU2yq+s7d+tvoB5CENh0B/D7NFrxgbPgQx9WTe2c fWAzH6WIdp00qAaFzDu2RTlPJaUpyLx7rulvNOgAIP5gO5duv23D7b7B75kxhSuoJFJM jaMSOsMbdwPW/CFHGbWB4xq6UkgARy9vnmoYiD4cQlUH0J2fbJDoaEszU/foQUE6sOeG YIPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=p9ZCsvck; 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 p91-v6si30550042plb.457.2018.05.28.09.31.48; Mon, 28 May 2018 09:32:06 -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=p9ZCsvck; 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 S935527AbeE1KJi (ORCPT + 99 others); Mon, 28 May 2018 06:09:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:57672 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935473AbeE1KJc (ORCPT ); Mon, 28 May 2018 06:09:32 -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 5CE39208B7; Mon, 28 May 2018 10:09:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527502171; bh=lRWrGBepaJz/jhnr7l08XTMc+L2ahpi/wyLq5wW06+s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p9ZCsvckHNRnboKsIuHzPOd8l5wbgUun1NC5rQCyy7QwWx2dpLUGE5czuDIjN8ADk hJUZdMN9UWr0rZAYNGqiD9Vdm52ye+MtMicq54ay4Mjnl173/rSfRXnLxemKGgllwA JDmmFOp7Iylgrmr0QFTr4VN2UfNLSdStyJdIIA2U= 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 3.18 088/185] scsi: sd: Keep disk read-only when re-reading partition Date: Mon, 28 May 2018 12:02:09 +0200 Message-Id: <20180528100058.148193658@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100050.700971285@linuxfoundation.org> References: <20180528100050.700971285@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 3.18-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 @@ -2318,6 +2318,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); @@ -2358,7 +2359,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");