rt2x00: fix possible memory corruption in case of invalid rxdesc.size
authorStanislaw Gruszka <stf_xl@wp.pl>
Sun, 19 Jun 2011 17:46:02 +0000 (19:46 +0200)
committerJohn W. Linville <linville@tuxdriver.com>
Wed, 22 Jun 2011 20:09:44 +0000 (16:09 -0400)
Sometimes rxdesc descriptor provided by hardware contains invalid
(random) data. For example rxdesc.size can be bigger than actual
size of the buffer. When this happen rt2x00crypto_rx_insert_iv()
corrupt memory doing memmove outside of buffer boundaries.

Signed-off-by: Stanislaw Gruszka <stf_xl@wp.pl>
Acked-by: Ivo van Doorn <IvDoorn@gmail.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
drivers/net/wireless/rt2x00/rt2x00dev.c

index 939821b4af2ff5b768913cc0809b05695801285c..0955c941317fd7d7ff049b18ade0a3be8c3bd89f 100644 (file)
@@ -582,6 +582,18 @@ void rt2x00lib_rxdone(struct queue_entry *entry)
        memset(&rxdesc, 0, sizeof(rxdesc));
        rt2x00dev->ops->lib->fill_rxdone(entry, &rxdesc);
 
+       /*
+        * Check for valid size in case we get corrupted descriptor from
+        * hardware.
+        */
+       if (unlikely(rxdesc.size == 0 ||
+                    rxdesc.size > entry->queue->data_size)) {
+               WARNING(rt2x00dev, "Wrong frame size %d max %d.\n",
+                       rxdesc.size, entry->queue->data_size);
+               dev_kfree_skb(entry->skb);
+               goto renew_skb;
+       }
+
        /*
         * The data behind the ieee80211 header must be
         * aligned on a 4 byte boundary.
@@ -642,6 +654,7 @@ void rt2x00lib_rxdone(struct queue_entry *entry)
 
        ieee80211_rx_ni(rt2x00dev->hw, entry->skb);
 
+renew_skb:
        /*
         * Replace the skb with the freshly allocated one.
         */