All of lore.kernel.org
 help / color / mirror / Atom feed
From: Damien Le Moal <damien.lemoal@wdc.com>
To: linux-scsi@vger.kernel.org,
	"Martin K . Petersen" <martin.petersen@oracle.com>
Subject: [PATCH v3 3/3] scsi: sd: fix sd_do_mode_sense() buffer length handling
Date: Fri, 20 Aug 2021 16:02:55 +0900	[thread overview]
Message-ID: <20210820070255.682775-4-damien.lemoal@wdc.com> (raw)
In-Reply-To: <20210820070255.682775-1-damien.lemoal@wdc.com>

For devices that explicitly asked for MODE SENSE 10 use, make sure that
scsi_mode_sense() is called with a buffer of at least 8B so that mode
sense header fits.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 drivers/scsi/sd.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 920df3a04a7b..34faff96e165 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -2603,6 +2603,13 @@ sd_do_mode_sense(struct scsi_disk *sdkp, int dbd, int modepage,
 		 unsigned char *buffer, int len, struct scsi_mode_data *data,
 		 struct scsi_sense_hdr *sshdr)
 {
+	/*
+	 * If we must use MODE SENSE 10, make sure that the buffer length
+	 * is at least 8B so that the mode sense header fits.
+	 */
+	if (sdkp->device->use_10_for_ms && len < 8)
+		len = 8;
+
 	return scsi_mode_sense(sdkp->device, dbd, modepage, buffer, len,
 			       SD_TIMEOUT, sdkp->max_retries, data,
 			       sshdr);
-- 
2.31.1


  parent reply	other threads:[~2021-08-20  7:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-20  7:02 [PATCH v3 0/3] Fixes for scsi_mode_sense/select() Damien Le Moal
2021-08-20  7:02 ` [PATCH v3 1/3] scsi: fix scsi_mode_sense() buffer length handling Damien Le Moal
2021-08-20  7:02 ` [PATCH v3 2/3] scsi: fix scsi_mode_select() " Damien Le Moal
2021-08-20  7:02 ` Damien Le Moal [this message]
2021-09-29  4:15 ` [PATCH v3 0/3] Fixes for scsi_mode_sense/select() Martin K. Petersen
2021-09-29  6:02   ` Damien Le Moal
2021-10-05  4:34 ` Martin K. Petersen

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=20210820070255.682775-4-damien.lemoal@wdc.com \
    --to=damien.lemoal@wdc.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.