netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] korina: Read buffer overflow
@ 2009-08-07 15:33 Roel Kluin
  2009-08-08  0:48 ` Phil Sutter
  0 siblings, 1 reply; 13+ messages in thread
From: Roel Kluin @ 2009-08-07 15:33 UTC (permalink / raw)
  To: netdev, Andrew Morton, David S. Miller, n0-1, florian

If the loop breaks with an i of 0, then we read lp->rd_ring[-1].

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
Should we clean up like this? please review

diff --git a/drivers/net/korina.c b/drivers/net/korina.c
index b4cf602..b965b2b 100644
--- a/drivers/net/korina.c
+++ b/drivers/net/korina.c
@@ -754,7 +754,7 @@ static void korina_alloc_ring(struct net_device *dev)
 {
 	struct korina_private *lp = netdev_priv(dev);
 	struct sk_buff *skb;
-	int i;
+	int i, j;
 
 	/* Initialize the transmit descriptors */
 	for (i = 0; i < KORINA_NUM_TDS; i++) {
@@ -771,7 +771,7 @@ static void korina_alloc_ring(struct net_device *dev)
 	for (i = 0; i < KORINA_NUM_RDS; i++) {
 		skb = dev_alloc_skb(KORINA_RBSIZE + 2);
 		if (!skb)
-			break;
+			goto err_free;
 		skb_reserve(skb, 2);
 		lp->rx_skb[i] = skb;
 		lp->rd_ring[i].control = DMA_DESC_IOD |
@@ -790,6 +790,12 @@ static void korina_alloc_ring(struct net_device *dev)
 	lp->rx_chain_head = 0;
 	lp->rx_chain_tail = 0;
 	lp->rx_chain_status = desc_empty;
+err_free:
+	for (j = 0; j < i; j++) {
+		lp->rd_ring[j].control = 0;
+		dev_kfree_skb_any(lp->rx_skb[j]);
+		lp->rx_skb[j] = NULL;
+	}
 }
 
 static void korina_free_ring(struct net_device *dev)

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2009-08-13 23:27 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-07 15:33 [PATCH] korina: Read buffer overflow Roel Kluin
2009-08-08  0:48 ` Phil Sutter
2009-08-08 13:14   ` roel kluin
2009-08-08 16:45     ` Phil Sutter
2009-08-09  0:06       ` Phil Sutter
2009-08-12 22:15         ` Phil Sutter
2009-08-12 22:22           ` [PATCH 1/2] korina: fix printk formatting, add final info line Phil Sutter
2009-08-12 22:52             ` [PATCH 2/2] korina: add error-handling to korina_alloc_ring Phil Sutter
2009-08-13 23:27               ` David Miller
2009-08-13 23:27             ` [PATCH 1/2] korina: fix printk formatting, add final info line David Miller
     [not found]       ` <1249776388-4626-1-git-send-email-n0-1@freewrt.org>
2009-08-09  0:06         ` [PATCH 1/3] " Phil Sutter
     [not found]         ` <1249776388-4626-2-git-send-email-n0-1@freewrt.org>
2009-08-09  0:06           ` [PATCH 2/3] korina: add error-handling to korina_alloc_ring Phil Sutter
     [not found]           ` <1249776388-4626-3-git-send-email-n0-1@freewrt.org>
2009-08-09  0:06             ` [PATCH 3/3] korina: convert to net_device_ops Phil Sutter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).