From patchwork Thu Jul 21 18:41:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Yan X-Patchwork-Id: 9242323 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BECEE60871 for ; Thu, 21 Jul 2016 18:43:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B1E581FF10 for ; Thu, 21 Jul 2016 18:43:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A3FA4268AE; Thu, 21 Jul 2016 18:43:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 50282268AE for ; Thu, 21 Jul 2016 18:43:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752651AbcGUSmh (ORCPT ); Thu, 21 Jul 2016 14:42:37 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:36672 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752410AbcGUSmd (ORCPT ); Thu, 21 Jul 2016 14:42:33 -0400 Received: by mail-pf0-f193.google.com with SMTP id y134so5870149pfg.3; Thu, 21 Jul 2016 11:42:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+ZnP40mXe3h88Fs10WPFoo+tPjcm4YPfVE785KuHR2A=; b=KrRuLNdDDpiErgetgAslDNVaKQySEtHFE8+gFmxlvIbgLHeMnYlRmDffiY1EellSiZ xt2X3HJlfFwhuWnhd/u6Fxs8fOIoW73Vu9T0c++dwYWiZwuIKCGyQc4DdNWWzQzSq5LI 5hmCwyYfiLiGjxsKMIamrdTnGEkMdzhL8gj3tAG+2YE/NgckoaWbT6e6UYABWfE3KALP bmZP7RmJi7KjqDMwOvY8OATHgIwGq7ZSaPiJpuRYVS0JVUYo8anzFLmSrzY0LNJ6ccXr 9Hup7j4rXWzqIgdW02Yoon254Z6hSZI/tceGBIh+mBWzn7z3v0ywCs7MP/kcQPZI2t4U RUaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+ZnP40mXe3h88Fs10WPFoo+tPjcm4YPfVE785KuHR2A=; b=ZvPCdZNIDIomIfK8AK8BSsbulDuEATa88AliCxKGjW6tU2MC/Njj+SkPOc92oSF11x yTygbCD/8AWVCVO5zfTF+nMpowoBAdzrBXR+4k6xK2UpIj8EATBgw/ISItqZMwIHEJB3 Ba0iQVMWi5vsTPrP0Vjf/xbjnM+dchdJxK2etyYLvwuHvY+rpYs0OlkeuiXNKXhLDicI YcW2nplkTQJL3VSfwnoeN2wlbyHqcjTxPJKypncW5kJFwXL1PoQp9R7w63e43A/xRz9O duQNsq3vJT+i0YqEJo0HhUROtWkPwiZGN9BkF+veIzLl62WF04Sk/w22EpviGloq96LV osvQ== X-Gm-Message-State: ALyK8tLoJFM2MbY2WI4uhddGwa6nGLpNsruErSnaXRCX51ZrfEElPjxdwkvBqSiCsqi+mQ== X-Received: by 10.98.95.5 with SMTP id t5mr75164517pfb.103.1469126553006; Thu, 21 Jul 2016 11:42:33 -0700 (PDT) Received: from localhost.localdomain ([2404:c805:e00:4700:ae22:bff:fe29:e60c]) by smtp.gmail.com with ESMTPSA id j7sm14002691paa.30.2016.07.21.11.42.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Jul 2016 11:42:32 -0700 (PDT) From: tom.ty89@gmail.com X-Google-Original-From: me To: tj@kernel.org, hare@suse.de, sergei.shtylyov@cogentembedded.com, arnd@arndb.de Cc: sfr@canb.auug.org.au, linux-ide@vger.kernel.org, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-next@vger.kernel.org, Tom Yan Subject: [PATCH resend 2/5] libata-scsi: fix read-only bits checking in ata_mselect_*() Date: Fri, 22 Jul 2016 02:41:51 +0800 Message-Id: X-Mailer: git-send-email 2.9.0 In-Reply-To: References: Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Tom Yan Commit 7780081c1f04 ("libata-scsi: Set information sense field for invalid parameter") changed how ata_mselect_*() make sure read-only bits are not modified. The new implementation introduced a bug that the read-only bits in the byte that has a changeable bit will not be checked. Added the necessary check, with comments explaining the heuristic. Signed-off-by: Tom Yan diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index eb5e8ff..ac90676 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -3631,8 +3631,18 @@ static int ata_mselect_caching(struct ata_queued_cmd *qc, */ ata_msense_caching(dev->id, mpage, false); for (i = 0; i < CACHE_MPAGE_LEN - 2; i++) { - if (i == 0) - continue; + /* Check the first byte */ + if (i == 0) { + /* except the WCE bit */ + if ((mpage[i + 2] & 0xfb) != (buf[i] & 0xfb)) { + *fp = i; + return -EINVAL; + } else { + continue; + } + } + + /* Check the remaining bytes */ if (mpage[i + 2] != buf[i]) { *fp = i; return -EINVAL; @@ -3686,8 +3696,18 @@ static int ata_mselect_control(struct ata_queued_cmd *qc, */ ata_msense_control(dev, mpage, false); for (i = 0; i < CONTROL_MPAGE_LEN - 2; i++) { - if (i == 0) - continue; + /* Check the first byte */ + if (i == 0) { + /* except the D_SENSE bit */ + if ((mpage[i + 2] & 0xfb) != (buf[i] & 0xfb)) { + *fp = i; + return -EINVAL; + } else { + continue; + } + } + + /* Check the remaining bytes */ if (mpage[2 + i] != buf[i]) { *fp = i; return -EINVAL;