diff mbox series

[v3,3/3] scsi: sd: fix sd_do_mode_sense() buffer length handling

Message ID 20210820070255.682775-4-damien.lemoal@wdc.com (mailing list archive)
State New, archived
Headers show
Series Fixes for scsi_mode_sense/select() | expand

Commit Message

Damien Le Moal Aug. 20, 2021, 7:02 a.m. UTC
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 mbox series

Patch

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);