$OpenBSD: patch-hw_e1000_c,v 1.4 2012/02/02 22:07:33 sthen Exp $

Bounds packet size against buffer size, otherwise we can write beyond
the buffer and corrupt memory.   CVE-2012-0029.

http://git.qemu.org/?p=qemu.git;a=commitdiff;h=65f82df0d7a71ce1b10cd4c5ab08888d176ac840

--- hw/e1000.c.orig	Thu Feb  2 20:07:37 2012
+++ hw/e1000.c	Thu Feb  2 20:11:43 2012
@@ -466,6 +466,8 @@ process_tx_desc(E1000State *s, struct e1000_tx_desc *d
             bytes = split_size;
             if (tp->size + bytes > msh)
                 bytes = msh - tp->size;
+
+            bytes = MIN(sizeof(tp->data) - tp->size, bytes);
             pci_dma_read(&s->dev, addr, tp->data + tp->size, bytes);
             if ((sz = tp->size + bytes) >= hdr && tp->size < hdr)
                 memmove(tp->header, tp->data, hdr);
@@ -481,6 +483,7 @@ process_tx_desc(E1000State *s, struct e1000_tx_desc *d
         // context descriptor TSE is not set, while data descriptor TSE is set
         DBGOUT(TXERR, "TCP segmentaion Error\n");
     } else {
+        split_size = MIN(sizeof(tp->data) - tp->size, split_size);
         pci_dma_read(&s->dev, addr, tp->data + tp->size, split_size);
         tp->size += split_size;
     }
