Skip to contentSkip to conversation

hw/scsi/scsi-disk: MODE_PAGE_ALLS not allowed in MODE SELECT commands

PATCH In review Mauro Matteo Cascella 2 participants 2 messages Nov 5, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/scsi/scsi-disk: MODE_PAGE_ALLS not allowed in MODE SELECT commands

MODE_PAGE_ALLS causes an off-by-one error in mode_sense_page() when accessing the stack-allocated mode_sense_valid buffer. MODE_PAGE_ALLS is only valid for MODE SENSE commands. Do not process it in MODE SELECT commands.

Fixes: CVE-2021-3930
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=2020588

---
 hw/scsi/scsi-disk.c | 6 ++++++
 1 file changed, 6 insertions(+)
hw/scsi/scsi-disk.c +6 -0
index e8a547dbb7..5852e8dcfd 100644
@@ -1087,6 +1087,7 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf,
     uint8_t *p = *p_outbuf + 2;
     int length;
 
+    assert(page != MODE_PAGE_ALLS);
     if ((mode_sense_valid[page] & (1 << s->qdev.type)) == 0) {
         return -1;
     }
@@ -1428,6 +1429,11 @@ static int scsi_disk_check_mode_select(SCSIDiskState *s, int page,
         return -1;
     }
 
+    /* MODE_PAGE_ALLS is only valid for MODE SENSE commands */
+    if (page == MODE_PAGE_ALLS) {
+        return -1;
+    }
+
     p = mode_current;
     memset(mode_current, 0, inlen + 2);
     len = mode_sense_page(s, page, &p, 0);
Signature · 1 line
2.31.1
#1 lore raw
Quoted 4 lines · Mauro Matteo Cascella

MODE_PAGE_ALLS causes an off-by-one error in mode_sense_page() when accessing the stack-allocated mode_sense_valid buffer. MODE_PAGE_ALLS is only valid for MODE SENSE commands. Do not process it in MODE SELECT commands.

Quoted 4 lines

Fixes: CVE-2021-3930
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=2020588

See also:
https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 29 lines
---
 hw/scsi/scsi-disk.c | 6 ++++++
 1 file changed, 6 insertions(+)
hw/scsi/scsi-disk.c +6 -0
index e8a547dbb7..5852e8dcfd 100644
@@ -1087,6 +1087,7 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf,
     uint8_t *p = *p_outbuf + 2;
     int length;
 
+    assert(page != MODE_PAGE_ALLS);
     if ((mode_sense_valid[page] & (1 << s->qdev.type)) == 0) {
         return -1;
     }
@@ -1428,6 +1429,11 @@ static int scsi_disk_check_mode_select(SCSIDiskState *s, int page,
         return -1;
     }
 
+    /* MODE_PAGE_ALLS is only valid for MODE SENSE commands */
+    if (page == MODE_PAGE_ALLS) {
+        return -1;
+    }
+
     p = mode_current;
     memset(mode_current, 0, inlen + 2);
     len = mode_sense_page(s, page, &p, 0);