diff mbox

NULL Pointer Deference: NFS & Telnet

Message ID 1283962550.2748.92.camel@edumazet-laptop
State RFC, archived
Delegated to: David Miller
Headers show

Commit Message

Eric Dumazet Sept. 8, 2010, 4:15 p.m. UTC
Le mardi 07 septembre 2010 à 16:43 -0500, Arce, Abraham a écrit :
> Eric, David,
> 
> > From: Eric Dumazet [mailto:eric.dumazet@gmail.com]
> 
> [..]
> 
> > > By increasing the allocation length of our rx skbuff the corruption issue is
> > fixed... I have increased it by 2... Were we writing outside our boundaries of
> > skb data?
> > >
> >
> > Yes that makes sense, nr_frag is right after the packet (padded to L1
> > cache size)
> >
> > But please do the correct allocation ?
> >
> > Also, we dont need FCS ?
> 
> FCS -> CRC is enable in hardware, under ks8851_net_open()
> 
>  TXCR_TXCRC | /* add CRC */
> 
> How about the following patch? I am using added helper function:
> netdev_alloc_skb_ip_align()

Hmm, I prefer following patch (not tested), to really cope with
allocation errors (instead of crashing because of NULL dereference), and
allocate and skb of exactly the needed size.



--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Arce, Abraham Sept. 8, 2010, 11:27 p.m. UTC | #1
Thanks Eric,

> Le mardi 07 septembre 2010 à 16:43 -0500, Arce, Abraham a écrit :
> > > From: Eric Dumazet [mailto:eric.dumazet@gmail.com]

[..]

> > How about the following patch? I am using added helper function:
> > netdev_alloc_skb_ip_align()
> 
> Hmm, I prefer following patch (not tested), to really cope with
> allocation errors (instead of crashing because of NULL dereference), and
> allocate and skb of exactly the needed size.

Patch tested, 2 minor modifications:

 - Added an ending brace
 - Line size correction

It has been tested in a SDP OMAP4 ES1.0

- Filesystem over nfs
- Multiple file creation
- Throughput measurement

I'll send it as a new patch

 [PATCH] KS8851: Correct RX packet allocation

Best Regards
Abraham

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/net/ks8851.c b/drivers/net/ks8851.c
index b4fb07a..4a4038e 100644
--- a/drivers/net/ks8851.c
+++ b/drivers/net/ks8851.c
@@ -503,30 +503,31 @@  static void ks8851_rx_pkts(struct ks8851_net *ks)
 		ks8851_wrreg16(ks, KS_RXQCR,
 			       ks->rc_rxqcr | RXQCR_SDA | RXQCR_ADRFE);
 
-		if (rxlen > 0) {
-			skb = netdev_alloc_skb(ks->netdev, rxlen + 2 + 8);
-			if (!skb) {
-				/* todo - dump frame and move on */
+		if (rxlen > 4) {
+			unsigned int rxalign;
+			
+			rxlen -= 4;
+			rxalign = ALIGN(rxlen, 4);
+			skb = netdev_alloc_skb_ip_align(ks->netdev, rxalign);
+			if (skb) {
+
+				/* 4 bytes of status header + 4 bytes of garbage:
+				 * we put them before ethernet header, so that
+				 * they are copied, but ignored.
+				 */
+				rxpkt = skb_put(skb, rxlen) - 8;
+
+				ks8851_rdfifo(ks, rxpkt, rxalign + 8);
+
+				if (netif_msg_pktdata(ks))
+					ks8851_dbg_dumpkkt(ks, rxpkt);
+
+				skb->protocol = eth_type_trans(skb, ks->netdev);
+				netif_rx(skb);
+
+				ks->netdev->stats.rx_packets++;
+				ks->netdev->stats.rx_bytes += rxlen;
 			}
-
-			/* two bytes to ensure ip is aligned, and four bytes
-			 * for the status header and 4 bytes of garbage */
-			skb_reserve(skb, 2 + 4 + 4);
-
-			rxpkt = skb_put(skb, rxlen - 4) - 8;
-
-			/* align the packet length to 4 bytes, and add 4 bytes
-			 * as we're getting the rx status header as well */
-			ks8851_rdfifo(ks, rxpkt, ALIGN(rxlen, 4) + 8);
-
-			if (netif_msg_pktdata(ks))
-				ks8851_dbg_dumpkkt(ks, rxpkt);
-
-			skb->protocol = eth_type_trans(skb, ks->netdev);
-			netif_rx(skb);
-
-			ks->netdev->stats.rx_packets++;
-			ks->netdev->stats.rx_bytes += rxlen - 4;
 		}
 
 		ks8851_wrreg16(ks, KS_RXQCR, ks->rc_rxqcr);