From dc0d93d4140d4e46a7e588079fd5d7c6c16abfe7 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Sat, 27 Nov 2021 12:55:28 +0100 Subject: [PATCH] 5.15-stable patches added patches: scsi-sd-fix-sd_do_mode_sense-buffer-length-handling.patch --- ...do_mode_sense-buffer-length-handling.patch | 37 +++++++++++++++++++ queue-5.15/series | 1 + 2 files changed, 38 insertions(+) create mode 100644 queue-5.15/scsi-sd-fix-sd_do_mode_sense-buffer-length-handling.patch create mode 100644 queue-5.15/series diff --git a/queue-5.15/scsi-sd-fix-sd_do_mode_sense-buffer-length-handling.patch b/queue-5.15/scsi-sd-fix-sd_do_mode_sense-buffer-length-handling.patch new file mode 100644 index 00000000000..c500ad5b7e2 --- /dev/null +++ b/queue-5.15/scsi-sd-fix-sd_do_mode_sense-buffer-length-handling.patch @@ -0,0 +1,37 @@ +From c749301ebee82eb5e97dec14b6ab31a4aabe37a6 Mon Sep 17 00:00:00 2001 +From: Damien Le Moal +Date: Fri, 20 Aug 2021 16:02:55 +0900 +Subject: scsi: sd: Fix sd_do_mode_sense() buffer length handling + +From: Damien Le Moal + +commit c749301ebee82eb5e97dec14b6ab31a4aabe37a6 upstream. + +For devices that explicitly asked for MODE SENSE(10) use, make sure that +scsi_mode_sense() is called with a buffer of at least 8 bytes so that the +sense header fits. + +Link: https://lore.kernel.org/r/20210820070255.682775-4-damien.lemoal@wdc.com +Signed-off-by: Damien Le Moal +Signed-off-by: Martin K. Petersen +Signed-off-by: Greg Kroah-Hartman +--- + drivers/scsi/sd.c | 7 +++++++ + 1 file changed, 7 insertions(+) + +--- a/drivers/scsi/sd.c ++++ b/drivers/scsi/sd.c +@@ -2607,6 +2607,13 @@ sd_do_mode_sense(struct scsi_disk *sdkp, + 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 8 bytes 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); diff --git a/queue-5.15/series b/queue-5.15/series new file mode 100644 index 00000000000..b38aefcf03e --- /dev/null +++ b/queue-5.15/series @@ -0,0 +1 @@ +scsi-sd-fix-sd_do_mode_sense-buffer-length-handling.patch -- 2.47.3