From patchwork Thu Jul 21 23:34:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Yan X-Patchwork-Id: 9242669 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 17741602F0 for ; Thu, 21 Jul 2016 23:34:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B64A20410 for ; Thu, 21 Jul 2016 23:34:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0031E212BE; Thu, 21 Jul 2016 23:34:55 +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 A4FD820410 for ; Thu, 21 Jul 2016 23:34:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752259AbcGUXek (ORCPT ); Thu, 21 Jul 2016 19:34:40 -0400 Received: from mail-pa0-f67.google.com ([209.85.220.67]:33484 "EHLO mail-pa0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751951AbcGUXej (ORCPT ); Thu, 21 Jul 2016 19:34:39 -0400 Received: by mail-pa0-f67.google.com with SMTP id q2so5937569pap.0; Thu, 21 Jul 2016 16:34:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:from:to:cc:subject:date:in-reply-to:references; bh=hakvP66NqhJac2yr9CCwjWRxWi+10PsUdESK3srdgTQ=; b=Lw/jJYcRqRycq+kNP3QY3bokSR3dTl2Yj7kMVv6O2IBOust2RqAR+jkOTRGxk9J2cp 9lreDxoAp2MwDPO2v1tapIAzLQU2xAbbifQBi3Eo58g1+7Mp6P97bScs9V2MagsIbeJ/ ucUwLpmeseCj8aDBkUC+OHVAZit8nHxGBB1BkIHOEpb3Z0kYgrUHhyDKXSIcjeobXqTh i82AVlHnU0HKtKX7FdOgR7W+tmU850EdSs2WOWlZlV7cYOjEJ0nf/7pbMKDR3lwQW+zv zLb/t4DqqJb/4UDpxr5i5F8bmh6oeQXrtWrwWxufUgXTOLmkVA0Bw4s5rPxDWpiOl6Hs Xqhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:from:to:cc:subject:date:in-reply-to :references; bh=hakvP66NqhJac2yr9CCwjWRxWi+10PsUdESK3srdgTQ=; b=M9OWHmbGcRo7F32QqwaSYRi+VdfuPNKBDEZ4U/QuK0ZLKZ8rMgkI7i8Lff6CzNQzs5 GE2KctOeRgpJFrST1dW4qbgIM+C/W9XpTSg3ypz4MgpJkaz7zAz7Ub/AKsM8QqkGJIhm m0wa7cCkqELCf9Ayn46E84p0VsNZVHSnkDTLIiv1LTrhNCmOeWxN1uXLLtThR4i0l7ng lfZQOm7J5Oo/ZNHV+Tz6jUf2++qSg5F3TUJ3NAI7OzDEpcCes7m+n7KR6ORsOKzWstXz 2z46/l+cOFEbmlu5yndBkUACMv267MlYj3jyCcY3BZdzVOFG16u+aojU59YgVcq5baho Eqdw== X-Gm-Message-State: AEkoouscjYWtOjDhfbM/HswDoHX8TxKxJdZ4aoJHiQ+UzrJpj0EMJzk4XpA57cx2vAmrtg== X-Received: by 10.66.219.68 with SMTP id pm4mr1300163pac.19.1469144078235; Thu, 21 Jul 2016 16:34:38 -0700 (PDT) Received: from localhost.localdomain ([2404:c805:e00:4700:ae22:bff:fe29:e60c]) by smtp.gmail.com with ESMTPSA id g10sm14782600pfc.57.2016.07.21.16.34.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Jul 2016 16:34:37 -0700 (PDT) Message-ID: <57915c0d.0a6b620a.960cd.4d0f@mx.google.com> X-Google-Original-Message-ID: <20160721233430.844-1-me> 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 v2 2/5] libata-scsi: fix read-only bits checking in ata_mselect_*() Date: Fri, 22 Jul 2016 07:34:30 +0800 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. Made it check every byte but mask the changeable bit. Signed-off-by: Tom Yan diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index eb5e8ff..4a4e6f1 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -3611,7 +3611,7 @@ static int ata_mselect_caching(struct ata_queued_cmd *qc, struct ata_taskfile *tf = &qc->tf; struct ata_device *dev = qc->dev; char mpage[CACHE_MPAGE_LEN]; - u8 wce; + u8 wce, mask; int i; /* @@ -3632,8 +3632,11 @@ 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; - if (mpage[i + 2] != buf[i]) { + mask = 0xfb; + else + mask = 0xff; + + if ((mpage[i + 2] & mask) != (buf[i] & mask)) { *fp = i; return -EINVAL; } @@ -3666,7 +3669,7 @@ static int ata_mselect_control(struct ata_queued_cmd *qc, { struct ata_device *dev = qc->dev; char mpage[CONTROL_MPAGE_LEN]; - u8 d_sense; + u8 d_sense, mask; int i; /* @@ -3687,8 +3690,11 @@ 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; - if (mpage[2 + i] != buf[i]) { + mask = 0xfb; + else + mask = 0xff; + + if ((mpage[2 + i] & mask) != (buf[i] & mask)) { *fp = i; return -EINVAL; }