]> git.proxmox.com Git - mirror_qemu.git/commitdiff
scsi-generic: avoid out-of-bounds access to VPD page list
authorPaolo Bonzini <pbonzini@redhat.com>
Mon, 22 Oct 2018 22:58:43 +0000 (00:58 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 6 Nov 2018 20:35:05 +0000 (21:35 +0100)
A device can report an excessive number of VPD pages when asked for a
list; this can cause an out-of-bounds access to buf in
scsi_generic_set_vpd_bl_emulation.  It should not happen, but
it is technically not incorrect so handle it: do not check any byte
past the allocation length that was sent to the INQUIRY command.

Reported-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
hw/scsi/scsi-generic.c

index aebb7cdd8249d86a56769170ebf1eebb8af42946..c5497bbea874e71253b51298d1ab3555808cd054 100644 (file)
@@ -538,7 +538,7 @@ static void scsi_generic_set_vpd_bl_emulation(SCSIDevice *s)
     }
 
     page_len = buf[3];
-    for (i = 4; i < page_len + 4; i++) {
+    for (i = 4; i < MIN(sizeof(buf), page_len + 4); i++) {
         if (buf[i] == 0xb0) {
             s->needs_vpd_bl_emulation = false;
             return;