From: Prasad J Pandit Date: Wed, 25 May 2016 12:25:10 +0000 (+0530) Subject: scsi: megasas: check 'read_queue_head' index value X-Git-Tag: v2.6.1~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=80eb9b8c4426c6dd145a39f4a44a6fa590de385d;p=thirdparty%2Fqemu.git scsi: megasas: check 'read_queue_head' index value While doing MegaRAID SAS controller command frame lookup, routine 'megasas_lookup_frame' uses 'read_queue_head' value as an index into 'frames[MEGASAS_MAX_FRAMES=2048]' array. Limit its value within array bounds to avoid any OOB access. Reported-by: Li Qiang Signed-off-by: Prasad J Pandit Message-Id: <1464179110-18593-1-git-send-email-ppandit@redhat.com> Reviewed-by: Alexander Graf Signed-off-by: Paolo Bonzini (cherry picked from commit b60bdd1f1ee1616b7a9aeeffb4088e1ce2710fb2) Signed-off-by: Michael Roth --- diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c index bf642d4ff31..cc66d361862 100644 --- a/hw/scsi/megasas.c +++ b/hw/scsi/megasas.c @@ -650,7 +650,9 @@ static int megasas_init_firmware(MegasasState *s, MegasasCmd *cmd) pa_hi = le32_to_cpu(initq->pi_addr_hi); s->producer_pa = ((uint64_t) pa_hi << 32) | pa_lo; s->reply_queue_head = ldl_le_pci_dma(pcid, s->producer_pa); + s->reply_queue_head %= MEGASAS_MAX_FRAMES; s->reply_queue_tail = ldl_le_pci_dma(pcid, s->consumer_pa); + s->reply_queue_tail %= MEGASAS_MAX_FRAMES; flags = le32_to_cpu(initq->flags); if (flags & MFI_QUEUE_FLAG_CONTEXT64) { s->flags |= MEGASAS_MASK_USE_QUEUE64;