Message ID | 20241209170330.113179-4-kovalev@altlinux.org (mailing list archive) |
---|---|
State | Not Applicable |
Headers | show |
Series | scsi: Backport fixes for CVE-2021-47182 | expand |
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);