public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Vasiliy Kovalev <kovalev@altlinux.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Sasha Levin <sashal@kernel.org>,
	stable@vger.kernel.org
Cc: "Martin K . Petersen" <martin.petersen@oracle.com>,
	"James E . J . Bottomley" <jejb@linux.ibm.com>,
	Damien Le Moal <damien.lemoal@wdc.com>,
	linux-scsi@vger.kernel.org, lvc-project@linuxtesting.org,
	kovalev@altlinux.org, nickel@altlinux.org, gerben@altlinux.org,
	dutyrok@altlinux.org
Subject: [PATCH 5.10.y 3/3] scsi: sd: Fix sd_do_mode_sense() buffer length handling
Date: Mon,  9 Dec 2024 20:03:30 +0300	[thread overview]
Message-ID: <20241209170330.113179-4-kovalev@altlinux.org> (raw)
In-Reply-To: <20241209170330.113179-1-kovalev@altlinux.org>

From: Damien Le Moal <damien.lemoal@wdc.com>

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 <damien.lemoal@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Vasiliy Kovalev <kovalev@altlinux.org>
---
 drivers/scsi/sd.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index f2dfd9853d3432..2f2ca287887603 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -2649,6 +2649,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 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);
-- 
2.33.8


  parent reply	other threads:[~2024-12-09 17:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-09 17:03 [PATCH v2 5.10.y 0/3] scsi: Backport fixes for CVE-2021-47182 Vasiliy Kovalev
2024-12-09 17:03 ` [PATCH 5.10.y 1/3] scsi: core: Fix scsi_mode_sense() buffer length handling Vasiliy Kovalev
2024-12-09 20:55   ` Sasha Levin
2024-12-09 17:03 ` [PATCH 5.10.y 2/3] scsi: core: Fix scsi_mode_select() " Vasiliy Kovalev
2024-12-09 20:55   ` Sasha Levin
2024-12-09 17:03 ` Vasiliy Kovalev [this message]
2024-12-09 20:55   ` [PATCH 5.10.y 3/3] scsi: sd: Fix sd_do_mode_sense() " Sasha Levin
2025-01-30 21:26 ` [PATCH v2 5.10.y 0/3] scsi: Backport fixes for CVE-2021-47182 Vasiliy Kovalev

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=20241209170330.113179-4-kovalev@altlinux.org \
    --to=kovalev@altlinux.org \
    --cc=damien.lemoal@wdc.com \
    --cc=dutyrok@altlinux.org \
    --cc=gerben@altlinux.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jejb@linux.ibm.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=martin.petersen@oracle.com \
    --cc=nickel@altlinux.org \
    --cc=sashal@kernel.org \
    --cc=stable@vger.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