bf445d
From: Prasad J Pandit <pjp@fedoraproject.org>
bf445d
Date: Fri, 20 Nov 2015 11:50:31 +0530
bf445d
Subject: [PATCH] net: pcnet: add check to validate receive data
bf445d
 size(CVE-2015-7504)
bf445d
bf445d
In loopback mode, pcnet_receive routine appends CRC code to the
bf445d
receive buffer. If the data size given is same as the buffer size,
bf445d
the appended CRC code overwrites 4 bytes after s->buffer. Added a
bf445d
check to avoid that.
bf445d
bf445d
Reported by: Qinghao Tang <luodalongde@gmail.com>
bf445d
Cc: qemu-stable@nongnu.org
bf445d
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
bf445d
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
bf445d
Signed-off-by: Jason Wang <jasowang@redhat.com>
bf445d
bf445d
(cherry picked from commit 837f21aacf5a714c23ddaadbbc5212f9b661e3f7)
bf445d
---
bf445d
 hw/net/pcnet.c | 8 +++++---
bf445d
 1 file changed, 5 insertions(+), 3 deletions(-)
bf445d
bf445d
diff --git a/hw/net/pcnet.c b/hw/net/pcnet.c
bf445d
index 68b9981..03a56b2 100644
bf445d
--- a/hw/net/pcnet.c
bf445d
+++ b/hw/net/pcnet.c
bf445d
@@ -1094,7 +1094,7 @@ ssize_t pcnet_receive(NetClientState *nc, const uint8_t *buf, size_t size_)
bf445d
                 uint32_t fcs = ~0;
bf445d
                 uint8_t *p = src;
bf445d
 
bf445d
-                while (p != &src[size-4])
bf445d
+                while (p != &src[size])
bf445d
                     CRC(fcs, *p++);
bf445d
                 crc_err = (*(uint32_t *)p != htonl(fcs));
bf445d
             }
bf445d
@@ -1243,8 +1243,10 @@ static void pcnet_transmit(PCNetState *s)
bf445d
         bcnt = 4096 - GET_FIELD(tmd.length, TMDL, BCNT);
bf445d
 
bf445d
         /* if multi-tmd packet outsizes s->buffer then skip it silently.
bf445d
-           Note: this is not what real hw does */
bf445d
-        if (s->xmit_pos + bcnt > sizeof(s->buffer)) {
bf445d
+         * Note: this is not what real hw does.
bf445d
+         * Last four bytes of s->buffer are used to store CRC FCS code.
bf445d
+         */
bf445d
+        if (s->xmit_pos + bcnt > sizeof(s->buffer) - 4) {
bf445d
             s->xmit_pos = -1;
bf445d
             goto txdone;
bf445d
         }