[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 42/76] scsi-generic: avoid possible out-of-bounds acc
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 42/76] scsi-generic: avoid possible out-of-bounds access to r->buf |
Date: |
Tue, 5 Feb 2019 19:14:52 +0100 |
Whenever the allocation length of a SCSI request is shorter than the size of the
VPD page list, page_idx is used blindly to index into r->buf. Even though
the stores in the insertion sort are protected against overflows, the same is
not
true of the reads and the final store of 0xb0.
This basically does the same thing as commit 57dbb58d80 ("scsi-generic: avoid
out-of-bounds access to VPD page list", 2018-11-06), except that here the
allocation length can be chosen by the guest. Note that according to the SCSI
standard, the contents of the PAGE LENGTH field are not altered based
on the allocation length.
The code was introduced by commit 6c219fc8a1 ("scsi-generic: keep VPD
page list sorted", 2018-11-06) but the overflow was already possible before.
Reported-by: Kevin Wolf <address@hidden>
Fixes: a71c775b24ebc664129eb1d9b4c360590353efd5
Signed-off-by: Paolo Bonzini <address@hidden>
---
hw/scsi/scsi-generic.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c
index 7237b41..42700e8 100644
--- a/hw/scsi/scsi-generic.c
+++ b/hw/scsi/scsi-generic.c
@@ -182,7 +182,7 @@ static void scsi_handle_inquiry_reply(SCSIGenericReq *r,
SCSIDevice *s)
/* Also take care of the opt xfer len. */
stl_be_p(&r->buf[12],
MIN_NON_ZERO(max_transfer, ldl_be_p(&r->buf[12])));
- } else if (s->needs_vpd_bl_emulation && page == 0x00) {
+ } else if (s->needs_vpd_bl_emulation && page == 0x00 && r->buflen >=
4) {
/*
* Now we're capable of supplying the VPD Block Limits
* response if the hardware can't. Add it in the INQUIRY
@@ -193,18 +193,20 @@ static void scsi_handle_inquiry_reply(SCSIGenericReq *r,
SCSIDevice *s)
* and will use it to proper setup the SCSI device.
*
* VPD page numbers must be sorted, so insert 0xb0 at the
- * right place with an in-place insert. After the initialization
- * part of the for loop is executed, the device response is
- * at r[0] to r[page_idx - 1].
+ * right place with an in-place insert. When the while loop
+ * begins the device response is at r[0] to r[page_idx - 1].
*/
- for (page_idx = lduw_be_p(r->buf + 2) + 4;
- page_idx > 4 && r->buf[page_idx - 1] >= 0xb0;
- page_idx--) {
+ page_idx = lduw_be_p(r->buf + 2) + 4;
+ page_idx = MIN(page_idx, r->buflen);
+ while (page_idx > 4 && r->buf[page_idx - 1] >= 0xb0) {
if (page_idx < r->buflen) {
r->buf[page_idx] = r->buf[page_idx - 1];
}
+ page_idx--;
+ }
+ if (page_idx < r->buflen) {
+ r->buf[page_idx] = 0xb0;
}
- r->buf[page_idx] = 0xb0;
stw_be_p(r->buf + 2, lduw_be_p(r->buf + 2) + 1);
}
}
--
1.8.3.1
- [Qemu-devel] [PULL 24/76] Revert "i386: Add CPUID bit for PCONFIG", (continued)
- [Qemu-devel] [PULL 24/76] Revert "i386: Add CPUID bit for PCONFIG", Paolo Bonzini, 2019/02/05
- [Qemu-devel] [PULL 19/76] hw/i386/pc: use PVH option rom, Paolo Bonzini, 2019/02/05
- [Qemu-devel] [PULL 26/76] contrib/elf2dmp: fix elf.h including, Paolo Bonzini, 2019/02/05
- [Qemu-devel] [PULL 12/76] elf-ops.h: Add get_elf_note_type(), Paolo Bonzini, 2019/02/05
- [Qemu-devel] [PULL 21/76] hw/i386/pc: enable PVH only for machine type >= 4.0, Paolo Bonzini, 2019/02/05
- [Qemu-devel] [PULL 27/76] contrib/elf2dmp: use GLib in ELF processing, Paolo Bonzini, 2019/02/05
- [Qemu-devel] [PULL 29/76] contrib/elf2dmp: fix structures definitions, Paolo Bonzini, 2019/02/05
- [Qemu-devel] [PULL 28/76] contrib/elf2dmp: use GLib in PDB processing, Paolo Bonzini, 2019/02/05
- [Qemu-devel] [PULL 32/76] monitor: do not use QTAILQ_FOREACH_SAFE across critical sections, Paolo Bonzini, 2019/02/05
- [Qemu-devel] [PULL 38/76] i386: allow to load initrd below 4 GB for recent linux, Paolo Bonzini, 2019/02/05
- [Qemu-devel] [PULL 42/76] scsi-generic: avoid possible out-of-bounds access to r->buf,
Paolo Bonzini <=
- [Qemu-devel] [PULL 37/76] i386: import & use bootparam.h, Paolo Bonzini, 2019/02/05
- [Qemu-devel] [PULL 47/76] vfio: move conditional up to hw/Makefile.objs, Paolo Bonzini, 2019/02/05
- [Qemu-devel] [PULL 14/76] pvh: Boot uncompressed kernel using direct boot ABI, Paolo Bonzini, 2019/02/05
- [Qemu-devel] [PULL 31/76] configure: enable elf2dmp build for Windows hosts, Paolo Bonzini, 2019/02/05
- [Qemu-devel] [PULL 16/76] linuxboot_dma: remove duplicate definitions of FW_CFG, Paolo Bonzini, 2019/02/05
- [Qemu-devel] [PULL 04/76] vhost-user-test: skip if there is no memory at address 0, Paolo Bonzini, 2019/02/05
- [Qemu-devel] [PULL 45/76] arm: disable CONFIG_SERIAL_ISA, Paolo Bonzini, 2019/02/05
- [Qemu-devel] [PULL 44/76] qemu-options: Remove deprecated "-virtioconsole" option, Paolo Bonzini, 2019/02/05