Subject: Re: [PATCH] SMC911X: Fix using of dereferenced skb after netif_rx

From: Wang Chen <[email-masked]>
Date: Tue, 04 Dec 2007 10:01:37 +0800

Peter Korsgaard said the following on 2007-12-3 21:47:
>>>>>> "Wang" == Wang Chen <[email-masked]> writes:
> 
> Hi,
> 
>  Wang> +	len = skb->len;
>  Wang>  	netif_rx(skb);
>  dev-> stats.rx_packets++;
>  Wang> -	dev->stats.rx_bytes += skb->len;
>  Wang> +	dev->stats.rx_bytes += len;
> 
> Why not simply update the stats before calling netif_rx as the return
> value isn't checked anyway?
> 

Even the return value of netif_rx isn't checked, dev->stats maybe
changed in netif_rx. But fortunately dev->stats isn't changed in
netif_rx.
So, I agree. 
Here is the new patch.

Signed-off-by: Wang Chen <[email-masked]>
---
 smc911x.c |    2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)

--- linux-2.6.24.rc3.org/drivers/net/smc911x.c	2007-11-19 12:38:05.000000000 +0800
+++ linux-2.6.24.rc3/drivers/net/smc911x.c	2007-12-04 09:59:06.000000000 +0800
@@ -1299,9 +1299,9 @@ smc911x_rx_dma_irq(int dma, void *data)
 	PRINT_PKT(skb->data, skb->len);
 	dev->last_rx = jiffies;
 	skb->protocol = eth_type_trans(skb, dev);
-	netif_rx(skb);
 	dev->stats.rx_packets++;
 	dev->stats.rx_bytes += skb->len;
+	netif_rx(skb);
 
 	spin_lock_irqsave(&lp->lock, flags);
 	pkts = (SMC_GET_RX_FIFO_INF() & RX_FIFO_INF_RXSUSED_) >> 16;