aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGertjan van Wingerde <gwingerde@kpnplanet.nl>2008-06-06 16:54:28 -0400
committerJohn W. Linville <linville@tuxdriver.com>2008-06-14 12:17:57 -0400
commita26cbc650846b74dd7f46dd877fd30c472df14a1 (patch)
treea31d96161b36ea6be4d84f1ad23c056f4b3323b7
parent239c249d06b0c68ae06b10d9d6ad1f8e7f39452b (diff)
rt2x00: Fix double usage of skb->cb in USB RX path.
It is not safe to use the skb->cb area for both the rxd and skb_frame_desc data at the same time, while they occupy an overlapping piece of memory. This can lead to hard to trace crashes as pointers within skb_frame_desc are pointing into nowhere, or the rxd data is overwritten with non-sense. Fix it by copying the rxd to a small buffer on the stack. Signed-off-by: Gertjan van Wingerde <gwingerde@kpnplanet.nl> Signed-off-by: Ivo van Doorn <IvDoorn@gmail.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
-rw-r--r--drivers/net/wireless/rt2x00/rt2500usb.c10
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00usb.c8
-rw-r--r--drivers/net/wireless/rt2x00/rt73usb.c10
3 files changed, 9 insertions, 19 deletions
diff --git a/drivers/net/wireless/rt2x00/rt2500usb.c b/drivers/net/wireless/rt2x00/rt2500usb.c
index 1bfb68a920a..9851cefaabf 100644
--- a/drivers/net/wireless/rt2x00/rt2500usb.c
+++ b/drivers/net/wireless/rt2x00/rt2500usb.c
@@ -1156,14 +1156,10 @@ static void rt2500usb_fill_rxdone(struct queue_entry *entry,
1156 u32 word1; 1156 u32 word1;
1157 1157
1158 /* 1158 /*
1159 * Copy descriptor to the skb->cb array, this has 2 benefits: 1159 * Copy descriptor to the skbdesc->desc buffer, making it safe from moving of
1160 * 1) Each descriptor word is 4 byte aligned. 1160 * frame data in rt2x00usb.
1161 * 2) Descriptor is safe from moving of frame data in rt2x00usb.
1162 */ 1161 */
1163 skbdesc->desc_len = 1162 memcpy(skbdesc->desc, rxd, skbdesc->desc_len);
1164 min_t(u16, entry->queue->desc_size, sizeof(entry->skb->cb));
1165 memcpy(entry->skb->cb, rxd, skbdesc->desc_len);
1166 skbdesc->desc = entry->skb->cb;
1167 rxd = (__le32 *)skbdesc->desc; 1163 rxd = (__le32 *)skbdesc->desc;
1168 1164
1169 /* 1165 /*
diff --git a/drivers/net/wireless/rt2x00/rt2x00usb.c b/drivers/net/wireless/rt2x00/rt2x00usb.c
index 33833bc6d66..68d87f09e05 100644
--- a/drivers/net/wireless/rt2x00/rt2x00usb.c
+++ b/drivers/net/wireless/rt2x00/rt2x00usb.c
@@ -267,6 +267,7 @@ static void rt2x00usb_interrupt_rxdone(struct urb *urb)
267 struct sk_buff *skb; 267 struct sk_buff *skb;
268 struct skb_frame_desc *skbdesc; 268 struct skb_frame_desc *skbdesc;
269 struct rxdone_entry_desc rxdesc; 269 struct rxdone_entry_desc rxdesc;
270 u8 rxd[32];
270 271
271 if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags) || 272 if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags) ||
272 !test_and_clear_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags)) 273 !test_and_clear_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags))
@@ -286,16 +287,13 @@ static void rt2x00usb_interrupt_rxdone(struct urb *urb)
286 skbdesc = get_skb_frame_desc(entry->skb); 287 skbdesc = get_skb_frame_desc(entry->skb);
287 memset(skbdesc, 0, sizeof(*skbdesc)); 288 memset(skbdesc, 0, sizeof(*skbdesc));
288 skbdesc->entry = entry; 289 skbdesc->entry = entry;
290 skbdesc->desc = rxd;
291 skbdesc->desc_len = entry->queue->desc_size;
289 292
290 memset(&rxdesc, 0, sizeof(rxdesc)); 293 memset(&rxdesc, 0, sizeof(rxdesc));
291 rt2x00dev->ops->lib->fill_rxdone(entry, &rxdesc); 294 rt2x00dev->ops->lib->fill_rxdone(entry, &rxdesc);
292 295
293 /* 296 /*
294 * Trim the skb to the correct size.
295 */
296 skb_trim(entry->skb, rxdesc.size);
297
298 /*
299 * Allocate a new sk buffer to replace the current one. 297 * Allocate a new sk buffer to replace the current one.
300 * If allocation fails, we should drop the current frame 298 * If allocation fails, we should drop the current frame
301 * so we can recycle the existing sk buffer for the new frame. 299 * so we can recycle the existing sk buffer for the new frame.
diff --git a/drivers/net/wireless/rt2x00/rt73usb.c b/drivers/net/wireless/rt2x00/rt73usb.c
index 800a1e278d1..505a9f5e09e 100644
--- a/drivers/net/wireless/rt2x00/rt73usb.c
+++ b/drivers/net/wireless/rt2x00/rt73usb.c
@@ -1428,14 +1428,10 @@ static void rt73usb_fill_rxdone(struct queue_entry *entry,
1428 u32 word1; 1428 u32 word1;
1429 1429
1430 /* 1430 /*
1431 * Copy descriptor to the skb->cb array, this has 2 benefits: 1431 * Copy descriptor to the skbdesc->desc buffer, making it safe from moving of
1432 * 1) Each descriptor word is 4 byte aligned. 1432 * frame data in rt2x00usb.
1433 * 2) Descriptor is safe from moving of frame data in rt2x00usb.
1434 */ 1433 */
1435 skbdesc->desc_len = 1434 memcpy(skbdesc->desc, rxd, skbdesc->desc_len);
1436 min_t(u16, entry->queue->desc_size, sizeof(entry->skb->cb));
1437 memcpy(entry->skb->cb, rxd, skbdesc->desc_len);
1438 skbdesc->desc = entry->skb->cb;
1439 rxd = (__le32 *)skbdesc->desc; 1435 rxd = (__le32 *)skbdesc->desc;
1440 1436
1441 /* 1437 /*