Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2017616imm; Thu, 24 May 2018 04:35:29 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrG1UysC7gwpnkhuRJGY3YrBCC9q42b9l46a78kJt2NSQNWSkDjx3D/VJ0gdMA2W0IvPcC8 X-Received: by 2002:a62:c205:: with SMTP id l5-v6mr6896494pfg.6.1527161729773; Thu, 24 May 2018 04:35:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527161729; cv=none; d=google.com; s=arc-20160816; b=LX3kO80+2ibVI/f6gkOKnfTnW45/PTJJ8c/c8Y7bmf2ThKE6/qGh1P185PJgB0m1Zd nZS1csGWOPZdVPDasH1eEImDZYzbfbUoMneUIaCCs8zppw223fz0A7BzrdjwWWRX4pPQ 56QBMbgGZV+Of0sGzE1WL6p141Bidgv+mvhF+er3Hi+Fd3boKp7qXySsnA+JX4q+r+KD Wy2d4qwVmv6O7GeT1MvYGxkMCfpuqr4t/Y/xj6ACKCUCpKWWAtsh3pHaJUA9zvcxqSXh R6lXkgearF7qSHXOLx0GBU01eEAeFlKf1GOeCL01B+vX5JDBMB3m7RjnPbgmmJolCa1W CbGw== 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=oJCJrj9BevASfad3n3PNKfsRSk8BqkUocYX50/Jdar0=; b=ixCMbznV4SfiZygXl+9tI0AoODNBlNjCCrv5kwihTwsapYIRklbdJi9/ZrTbrCWNcp 5U/MsXmaUTpvr6ltrdtQj88sVWSO12z/VeAL+id10MlrQJ2h89rg77M+uBln2iHQ5zP6 G/Od9dsiIo24KiN31CPg58XDF+YiU8EHpkoJx+s4XX1PuthPkzfiduFdtx2rWJZ6Afa+ mLbFfPRTYZc64lQ7K8jHbl2JrogLW9Q+ALjmkBCSacxiGTi/8WBnYq22WhVkWBx0MqSx QV9zLF5G5/96nocmV0hE+Ne/lZzCKbr3YZ9Z3ZH6C/lH5VenFNWJkPzWaO0lmAOJBgoJ Fr5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vldDcmut; 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 j2-v6si20077226pff.184.2018.05.24.04.35.15; Thu, 24 May 2018 04:35:29 -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=vldDcmut; 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 S1033143AbeEXLeo (ORCPT + 99 others); Thu, 24 May 2018 07:34:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:41242 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967182AbeEXJuS (ORCPT ); Thu, 24 May 2018 05:50:18 -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 CD9B120847; Thu, 24 May 2018 09:50:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155418; bh=ldMfRKDAAaFCkd+D8LaFGdR6U9wrAJ/I7n6WhNMRcy8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vldDcmut2/QJB61LJG9hu2nA+9FmlZ6c6nY+sW3JVIuZmVq80ZxoObu18a11n6EeD xGgVPcXE9MjH05ZMosxymjkqccauFvIvTOb61SsJYQo6he+K07YLInXwtDlx2LwlWf DexQdPJXx35wInJOZiswMVjy4T04Ykjj8hE6sPsQ= 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.9 61/96] scsi: sd: Keep disk read-only when re-reading partition Date: Thu, 24 May 2018 11:38:44 +0200 Message-Id: <20180524093608.968221280@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093605.602125311@linuxfoundation.org> References: <20180524093605.602125311@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.9-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 @@ -2401,6 +2401,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); @@ -2441,7 +2442,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");