From patchwork Thu Jul 21 23:25:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Yan X-Patchwork-Id: 9242645 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 66467602F0 for ; Thu, 21 Jul 2016 23:25:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4DCD227F54 for ; Thu, 21 Jul 2016 23:25:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3E9AA27F93; Thu, 21 Jul 2016 23:25:53 +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 CCD9227F54 for ; Thu, 21 Jul 2016 23:25:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751815AbcGUXZv (ORCPT ); Thu, 21 Jul 2016 19:25:51 -0400 Received: from mail-pa0-f66.google.com ([209.85.220.66]:35812 "EHLO mail-pa0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751427AbcGUXZt (ORCPT ); Thu, 21 Jul 2016 19:25:49 -0400 Received: by mail-pa0-f66.google.com with SMTP id cf3so5901430pad.2; Thu, 21 Jul 2016 16:25:49 -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=hakvP66NqhJac2yr9CCwjWRxWi+10PsUdESK3srdgTQ=; b=jSQDJvjB+5YCr9QJEwQzfo05l7C/KKp7db0jOo9oY0LMhORVGzV5b6U+kdYctyx6UC WfhUDdCN6igL/LRPAiH2FaTNsTkeqeFV5zzxVWzLryGM2FL94Y71DQqekI8kyyyPdCZD t/icylGIfrSOOaYjbNRpMwpMGD1x6eBRe15IicCN6pskYzZ6HCMmMZLJzdoyeTJOumfa 94dMB1EbVg5WrTYpJ4nyH+fy6G3ssmiGGXDLr7HreGaYbJUDsCjwQ9/8JBPKoS8j1ewQ YbI3PKEGBRkmApeHaFElo0CO8OpzT2ArIb4q3OPg1H3qcsdDL+WwXXZBBB2ROyqcB1sa Scyg== 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=hakvP66NqhJac2yr9CCwjWRxWi+10PsUdESK3srdgTQ=; b=IoyrTcBLDg/VNMpxddSTuKAz+4CckxH7flC6LxqWRoO+vI4LimaMXsqa7MBMizJfqe n7Sm+MbjSIIZYiBMCQTol0klfKqY0l8FGFwUIhdvbePheiohl1Y5HHTA/aXKI3Q32QoT tihsRhc0DVly+UsmnOglxHm7sAXF3R//E/dIYhE2cKpiG7S8rnvS2YnAuSC8p2sTaN7B zYZXoml8sl32FdSYHFyv1mfJXJr7eyJ2netL/qVMmgtdTpqkmVDCTp2LTxNajKHY5YmO 7gstfQnrQTufFtCpBeJ45A9FYdug3/Pe//FBX2AN/Kw5VGafA67oO61udfojm0cdUiE7 oyqQ== X-Gm-Message-State: AEkoousBllwNqswusHZD27Kt2VGPFy7CjaLy+wlfe4NiAsx+qJzPcLSwrp8LnFai0fI3fw== X-Received: by 10.66.162.4 with SMTP id xw4mr1205969pab.97.1469143548656; Thu, 21 Jul 2016 16:25:48 -0700 (PDT) Received: from localhost.localdomain ([2404:c805:e00:4700:ae22:bff:fe29:e60c]) by smtp.gmail.com with ESMTPSA id ra13sm14791899pac.29.2016.07.21.16.25.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Jul 2016 16:25:48 -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 v2 2/5] libata-scsi: fix read-only bits checking in ata_mselect_*() Date: Fri, 22 Jul 2016 07:25:42 +0800 Message-Id: <9bbf2b818f9ca1bb48f1eae31a0f3924a4fe0d9a.1469143271.git.tom.ty89@gmail.com> 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; }