render / rpms / qemu

Forked from rpms/qemu 9 months ago
Clone

Blame 0006-net-rocker-fix-an-incorrect-array-bounds-check.patch

b24b7f
From: Prasad J Pandit <pjp@fedoraproject.org>
b24b7f
Date: Mon, 28 Dec 2015 16:24:08 +0530
b24b7f
Subject: [PATCH] net: rocker: fix an incorrect array bounds check
b24b7f
b24b7f
While processing transmit(tx) descriptors in 'tx_consume' routine
b24b7f
the switch emulator suffers from an off-by-one error, if a
b24b7f
descriptor was to have more than allowed(ROCKER_TX_FRAGS_MAX=16)
b24b7f
fragments. Fix an incorrect bounds check to avoid it.
b24b7f
b24b7f
Reported-by: Qinghao Tang <luodalongde@gmail.com>
b24b7f
Cc: qemu-stable@nongnu.org
b24b7f
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
b24b7f
Signed-off-by: Jason Wang <jasowang@redhat.com>
b24b7f
(cherry picked from commit 007cd223de527b5f41278f2d886c1a4beb3e67aa)
b24b7f
---
b24b7f
 hw/net/rocker/rocker.c | 8 ++++----
b24b7f
 1 file changed, 4 insertions(+), 4 deletions(-)
b24b7f
b24b7f
diff --git a/hw/net/rocker/rocker.c b/hw/net/rocker/rocker.c
b24b7f
index c57f1a6..2e77e50 100644
b24b7f
--- a/hw/net/rocker/rocker.c
b24b7f
+++ b/hw/net/rocker/rocker.c
b24b7f
@@ -232,6 +232,9 @@ static int tx_consume(Rocker *r, DescInfo *info)
b24b7f
         frag_addr = rocker_tlv_get_le64(tlvs[ROCKER_TLV_TX_FRAG_ATTR_ADDR]);
b24b7f
         frag_len = rocker_tlv_get_le16(tlvs[ROCKER_TLV_TX_FRAG_ATTR_LEN]);
b24b7f
 
b24b7f
+        if (iovcnt >= ROCKER_TX_FRAGS_MAX) {
b24b7f
+            goto err_too_many_frags;
b24b7f
+        }
b24b7f
         iov[iovcnt].iov_len = frag_len;
b24b7f
         iov[iovcnt].iov_base = g_malloc(frag_len);
b24b7f
         if (!iov[iovcnt].iov_base) {
b24b7f
@@ -244,10 +247,7 @@ static int tx_consume(Rocker *r, DescInfo *info)
b24b7f
             err = -ROCKER_ENXIO;
b24b7f
             goto err_bad_io;
b24b7f
         }
b24b7f
-
b24b7f
-        if (++iovcnt > ROCKER_TX_FRAGS_MAX) {
b24b7f
-            goto err_too_many_frags;
b24b7f
-        }
b24b7f
+        iovcnt++;
b24b7f
     }
b24b7f
 
b24b7f
     if (iovcnt) {