linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tom.ty89@gmail.com
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 <tom.ty89@gmail.com>
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	[thread overview]
Message-ID: <9bbf2b818f9ca1bb48f1eae31a0f3924a4fe0d9a.1469143271.git.tom.ty89@gmail.com> (raw)
In-Reply-To: <accc8ca07073cd0292b62903acac956f5f5eff74.1469143271.git.tom.ty89@gmail.com>

From: Tom Yan <tom.ty89@gmail.com>

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 <tom.ty89@gmail.com>

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;
 		}
-- 
2.9.0

  parent reply	other threads:[~2016-07-21 23:25 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-21 18:41 [PATCH resend 1/5] libata-scsi: minor cleanup in ata_mselect_*() tom.ty89
2016-07-21 18:41 ` [PATCH resend 2/5] libata-scsi: fix read-only bits checking " tom.ty89
2016-07-21 18:41   ` [PATCH resend 3/5] libata-scsi: fix overflow in mode page copy tom.ty89
2016-07-21 18:41     ` [PATCH resend 4/5] libata-scsi: have all checks done before calling ata_mselect_*() tom.ty89
2016-07-21 18:41       ` [PATCH resend 5/5] libata-scsi: fix MODE SELECT translation for Control mode page tom.ty89
2016-07-21 21:26         ` Tejun Heo
2016-07-21 21:50           ` Tom Yan
2016-07-25 18:30             ` Tejun Heo
2016-07-27 21:00               ` Tom Yan
2016-08-10  3:38         ` Tejun Heo
2016-07-21 21:17     ` [PATCH resend 3/5] libata-scsi: fix overflow in mode page copy Tejun Heo
2016-07-21 21:39       ` Tom Yan
2016-07-21 21:42         ` Tejun Heo
     [not found]           ` <accc8ca07073cd0292b62903acac956f5f5eff74.1469143747.git.tom.ty89@gmail.com>
     [not found]             ` <9bbf2b818f9ca1bb48f1eae31a0f3924a4fe0d9a.1469143747.git.tom.ty89@gmail.com>
2016-07-21 23:29               ` [PATCH resend v2 3/5] libata-scsi: use u8 array to store " tom.ty89
2016-07-22  9:59                 ` Sergei Shtylyov
2016-07-22 18:22                   ` Tom Yan
2016-07-22 18:34                     ` [PATCH resend v3 " tom.ty89
2016-08-09 20:13                       ` Tejun Heo
2016-07-21 23:35           ` [PATCH resend v2 " tom.ty89
2016-07-21 23:20   ` [PATCH resend 2/5] libata-scsi: fix read-only bits checking in ata_mselect_*() Tom Yan
     [not found]     ` <accc8ca07073cd0292b62903acac956f5f5eff74.1469143271.git.tom.ty89@gmail.com>
2016-07-21 23:25       ` tom.ty89 [this message]
2016-07-21 23:34     ` [PATCH resend v2 " tom.ty89
2016-07-21 18:45 ` [PATCH resend 1/5] libata-scsi: minor cleanup " Sergei Shtylyov
2016-07-21 18:51   ` Tom Yan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9bbf2b818f9ca1bb48f1eae31a0f3924a4fe0d9a.1469143271.git.tom.ty89@gmail.com \
    --to=tom.ty89@gmail.com \
    --cc=arnd@arndb.de \
    --cc=hare@suse.de \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-next@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sergei.shtylyov@cogentembedded.com \
    --cc=sfr@canb.auug.org.au \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).