Skip to contentSkip to conversation

e1000: bounds packet size against buffer size

PATCH In review Anthony Liguori 4 participants 4 messages Jan 23, 2012 – Feb 2, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 e1000: bounds packet size against buffer size

Otherwise we can write beyond the buffer and corrupt memory. This is tracked as CVE-2012-0029.

---
 hw/e1000.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
hw/e1000.c +3 -0
index a29c944..86c5416 100644
@@ -466,6 +466,8 @@ process_tx_desc(E1000State *s, struct e1000_tx_desc *dp)
             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 *dp)
         // 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;
     }
Signature · 1 line
1.7.4.1
#1 lore raw
Quoted 2 lines · Anthony Liguori

Otherwise we can write beyond the buffer and corrupt memory. This is tracked as CVE-2012-0029.

The stable-1.0 branch looks vulnerable too, shouldn't this patch be backported?

Quoted 30 lines
---
 hw/e1000.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
hw/e1000.c +3 -0
index a29c944..86c5416 100644
@@ -466,6 +466,8 @@ process_tx_desc(E1000State *s, struct e1000_tx_desc *dp)
             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 *dp)
         // 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;
     }
Signature · 1 line
1.7.4.1
#2 lore raw
Quoted 6 lines · Stefano Stabellini
Quoted 2 lines · Anthony Liguori

Otherwise we can write beyond the buffer and corrupt memory. This is tracked as CVE-2012-0029.

The stable-1.0 branch looks vulnerable too, shouldn't this patch be backported?

This goes on since forever - for example, this patch applies to 0.12 too (modulo pci_dma_read() changes which makes the context differ). It applies cleanly to 1.0 stable.

/mjt

Quoted 31 lines
Quoted 30 lines
---
 hw/e1000.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
hw/e1000.c +3 -0
index a29c944..86c5416 100644
@@ -466,6 +466,8 @@ process_tx_desc(E1000State *s, struct e1000_tx_desc *dp)
             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 *dp)
         // 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;
     }
Signature · 1 line
1.7.4.1
#3 lore raw

Am 02.02.2012 16:24, schrieb Michael Tokarev:

Quoted 11 lines · Stefano Stabellini
Quoted 6 lines · Anthony Liguori
Quoted 2 lines

Otherwise we can write beyond the buffer and corrupt memory. This is tracked as CVE-2012-0029.

The stable-1.0 branch looks vulnerable too, shouldn't this patch be backported?

This goes on since forever - for example, this patch applies to 0.12 too (modulo pci_dma_read() changes which makes the context differ). It applies cleanly to 1.0 stable.

Therefore we should cc qemu-stable. :)

Andreas

Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
---
 hw/e1000.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
hw/e1000.c +3 -0
index a29c944..86c5416 100644
@@ -466,6 +466,8 @@ process_tx_desc(E1000State *s, struct e1000_tx_desc *dp)
             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 *dp)
         // 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;
     }
Signature · 1 line
1.7.4.1
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg