Skip to contentSkip to conversation

aoe [1/2]: explicitly set minimum packet length to ETH_ZLEN

PATCH In review Ed L. Cashin 6 participants 12 messages Sep 26, 2005 – Sep 27, 2005

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 aoe [1/2]: explicitly set minimum packet length to ETH_ZLEN

Explicitly set the minimum packet length to ETH_ZLEN.

drivers/block/aoe/aoecmd.c +3 -0
Index: 2.6.14-rc2-aoe/drivers/block/aoe/aoecmd.c
===================================================================
@@ -20,6 +20,9 @@
 {
 	struct sk_buff *skb;
 
+	if (len < ETH_ZLEN)
+		len = ETH_ZLEN;
+
 	skb = alloc_skb(len, GFP_ATOMIC);
 	if (skb) {
 		skb->nh.raw = skb->mac.raw = skb->data;
Signature · 1 line
  Ed L. Cashin <[email protected]>
#1 lore raw

"Ed L. Cashin" <[email protected]> writes:

...

Quoted 7 lines

Explicitly set the minimum packet length to ETH_ZLEN.

Index: 2.6.14-rc2-aoe/drivers/block/aoe/aoecmd.c
===================================================================

drivers/block/aoe/aoecmd.c line 26

Quoted 7 lines
drivers/block/aoe/aoecmd.c +3 -0
@@ -20,6 +20,9 @@
 {
 	struct sk_buff *skb;
 
+	if (len < ETH_ZLEN)
+		len = ETH_ZLEN;
+
 	skb = alloc_skb(len, GFP_ATOMIC);

This change fixes some strange problems observed on a system that was using the e1000 network driver. Is the network driver supposed to ensure that ethernet packets are up to spec, at least 60 bytes long?

Signature · 1 line
  Ed L Cashin <[email protected]>
#2 lore raw
Quoted 13 lines · Ed L Cashin

"Ed L. Cashin" <[email protected]> writes:

...

Quoted 10 lines

Explicitly set the minimum packet length to ETH_ZLEN.

Index: 2.6.14-rc2-aoe/drivers/block/aoe/aoecmd.c
===================================================================

drivers/block/aoe/aoecmd.c +0 -0
@@ -20,6 +20,9 @@
 {
 	struct sk_buff *skb;
 
Quoted 8 lines

drivers/block/aoe/aoecmd.c line 26

Quoted 4 lines
drivers/block/aoe/aoecmd.c +3 -0
+	if (len < ETH_ZLEN)
+		len = ETH_ZLEN;
+
 	skb = alloc_skb(len, GFP_ATOMIC);

This change fixes some strange problems observed on a system that was using the e1000 network driver. Is the network driver supposed to ensure that ethernet packets are up to spec, at least 60 bytes long?

I haven't chased through the code in detail - will this change ensure that all ETH_ZLEN bytes are initialized? We had a bunch of drivers a few years ago that set the length to the legal min, but then only copied some smaller number of bytes in, resulting in leakage of kernel memory contents....

#3 lore raw
Quoted 23 lines · On Mon, 26 Sep 2005 [email protected] wrote:
Quoted 13 lines · Ed L Cashin

"Ed L. Cashin" <[email protected]> writes:

...

Quoted 10 lines

Explicitly set the minimum packet length to ETH_ZLEN.

Index: 2.6.14-rc2-aoe/drivers/block/aoe/aoecmd.c
===================================================================

drivers/block/aoe/aoecmd.c +0 -0
@@ -20,6 +20,9 @@
 {
 	struct sk_buff *skb;
 
Quoted 8 lines

drivers/block/aoe/aoecmd.c line 26

Quoted 4 lines
drivers/block/aoe/aoecmd.c +3 -0
+	if (len < ETH_ZLEN)
+		len = ETH_ZLEN;
+
 	skb = alloc_skb(len, GFP_ATOMIC);

This change fixes some strange problems observed on a system that was using the e1000 network driver. Is the network driver supposed to ensure that ethernet packets are up to spec, at least 60 bytes long?

Quoted 4 lines

I haven't chased through the code in detail - will this change ensure that all ETH_ZLEN bytes are initialized? We had a bunch of drivers a few years ago that set the length to the legal min, but then only copied some smaller number of bytes in, resulting in leakage of kernel memory contents....

Good point.

On Ed's other question (which I have already trashed -- sorry), I am familiar with some NICs that automatically pad packets to ensure min packet size packets, and they know to do so with a safe data pattern. However, it's been a few years since I worked on NIC drivers, so I don't know the current state of affairs.

Signature · 1 line
~Randy
#4 lore raw
In reply to [email protected]

[email protected] writes:

...

Quoted 4 lines

I haven't chased through the code in detail - will this change ensure that all ETH_ZLEN bytes are initialized? We had a bunch of drivers a few years ago that set the length to the legal min, but then only copied some smaller number of bytes in, resulting in leakage of kernel memory contents....

No, it looks like alloc_skb just kmallocs the data, so I'd need to follow up with something like this:

linux/drivers/block/aoe/aoecmd.c +1 -0
diff -rN -u old-aoe-2.6-stand/linux/drivers/block/aoe/aoecmd.c new-aoe-2.6-stand/linux/drivers/block/aoe/aoecmd.c
@@ -26,6 +26,7 @@
 
 	skb = alloc_skb(len, GFP_ATOMIC);
 	if (skb) {
+		memset(skb->head, 0, skb->end - skb->head);
 		skb->nh.raw = skb->mac.raw = skb->data;
 		skb->dev = if_dev;
 		skb->protocol = __constant_htons(ETH_P_AOE);
Signature · 1 line
  Ed L Cashin <[email protected]>
#5 lore raw

From: Ed L Cashin <[email protected]>
Date: Mon, 26 Sep 2005 18:28:39 -0400

Quoted 2 lines

No, it looks like alloc_skb just kmallocs the data, so I'd need to follow up with something like this:

You should explicitly initialize the data areas of the SKB as you "push" and "put" to allocate space in the data buffer, not right after alloc_skb() and before you've allocate any space.

#6 lore raw
Quoted 9 lines · David S. Miller

From: Ed L Cashin <[email protected]>
Date: Mon, 26 Sep 2005 18:28:39 -0400

Quoted 2 lines

No, it looks like alloc_skb just kmallocs the data, so I'd need to follow up with something like this:

You should explicitly initialize the data areas of the SKB as you "push" and "put" to allocate space in the data buffer, not right after alloc_skb() and before you've allocate any space.

Sure, we can do that. I will resend these patches.

Signature · 1 line
  Ed L Cashin <[email protected]>
#7 lore raw
In reply to Ed L Cashin
Quoted 13 lines · Ed L Cashin

"Ed L. Cashin" <[email protected]> writes:

...

Quoted 10 lines

Explicitly set the minimum packet length to ETH_ZLEN.

Index: 2.6.14-rc2-aoe/drivers/block/aoe/aoecmd.c
===================================================================

drivers/block/aoe/aoecmd.c +0 -0
@@ -20,6 +20,9 @@
 {
 	struct sk_buff *skb;
 
Quoted 8 lines

drivers/block/aoe/aoecmd.c line 26

Quoted 4 lines
drivers/block/aoe/aoecmd.c +3 -0
+	if (len < ETH_ZLEN)
+		len = ETH_ZLEN;
+
 	skb = alloc_skb(len, GFP_ATOMIC);

This change fixes some strange problems observed on a system that was using the e1000 network driver. Is the network driver supposed to ensure that ethernet packets are up to spec, at least 60 bytes long?

I belive that 802.3 defines that a packet should be of at least 64 octets. I belive most ethernet controllers should consider anything smaller as a runt, but as usual, YMMV.

Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
#8 lore raw
In reply to Ed L Cashin
Quoted 5 lines · Ed L Cashin
Quoted 1 line

skb = alloc_skb(len, GFP_ATOMIC);

This change fixes some strange problems observed on a system that was using the e1000 network driver. Is the network driver supposed to ensure that ethernet packets are up to spec, at least 60 bytes long?

The network driver is supposed to pad frames if the hardware cannot and to blank the spare bits. If it isn't occurring please try and trace down the offender.

#9 lore raw
Quoted 9 lines · Alan Cox
Quoted 5 lines · Ed L Cashin
Quoted 1 line

skb = alloc_skb(len, GFP_ATOMIC);

This change fixes some strange problems observed on a system that was using the e1000 network driver. Is the network driver supposed to ensure that ethernet packets are up to spec, at least 60 bytes long?

The network driver is supposed to pad frames if the hardware cannot and to blank the spare bits.

Ah ha.

Quoted 2 lines

If it isn't occurring please try and trace down
the offender.

My colleague Sam observed problems with the e1000 driver in the 2.6.11.4-21.9-smp kernel from Suse 9.3 and also the e1000 driver in 2.6.12-1.1398_FC4smp from Fedora Core 4.

The problems aren't fully characterized, but AoE ATA read packets appeared to be getting dropped and/or corrupted.

When using the tg3 driver instead of e1000 the problems went away, and making the aoe driver alloc_skb with a minimum length of ETH_ZLEN also made the problems go away.

Signature · 1 line
  Ed L Cashin <[email protected]>
#10 lore raw

PATCH 1/1 aoe [2/2]: use get_unaligned for possibly unaligned accesses in ATA id buffer

In reply to Ed L. Cashin

Use get_unaligned for possibly-unaligned multi-byte accesses to the ATA device identify response buffer.

drivers/block/aoe/aoecmd.c +8 -7
Index: 2.6.14-rc2-aoe/drivers/block/aoe/aoecmd.c
===================================================================
@@ -8,6 +8,7 @@
 #include <linux/blkdev.h>
 #include <linux/skbuff.h>
 #include <linux/netdevice.h>
+#include <asm/unaligned.h>
 #include "aoe.h"
 
 #define TIMERTICK (HZ / 10)
@@ -314,16 +315,16 @@
 	u16 n;
 
 	/* word 83: command set supported */
-	n = le16_to_cpup((__le16 *) &id[83<<1]);
+	n = le16_to_cpu(get_unaligned((__le16 *) &id[83<<1]));
 
 	/* word 86: command set/feature enabled */
-	n |= le16_to_cpup((__le16 *) &id[86<<1]);
+	n |= le16_to_cpu(get_unaligned((__le16 *) &id[86<<1]));
 
 	if (n & (1<<10)) {	/* bit 10: LBA 48 */
 		d->flags |= DEVFL_EXT;
 
 		/* word 100: number lba48 sectors */
-		ssize = le64_to_cpup((__le64 *) &id[100<<1]);
+		ssize = le64_to_cpu(get_unaligned((__le64 *) &id[100<<1]));
 
 		/* set as in ide-disk.c:init_idedisk_capacity */
 		d->geo.cylinders = ssize;
@@ -334,12 +335,12 @@
 		d->flags &= ~DEVFL_EXT;
 
 		/* number lba28 sectors */
-		ssize = le32_to_cpup((__le32 *) &id[60<<1]);
+		ssize = le32_to_cpu(get_unaligned((__le32 *) &id[60<<1]));
 
 		/* NOTE: obsolete in ATA 6 */
-		d->geo.cylinders = le16_to_cpup((__le16 *) &id[54<<1]);
-		d->geo.heads = le16_to_cpup((__le16 *) &id[55<<1]);
-		d->geo.sectors = le16_to_cpup((__le16 *) &id[56<<1]);
+		d->geo.cylinders = le16_to_cpu(get_unaligned((__le16 *) &id[54<<1]));
+		d->geo.heads = le16_to_cpu(get_unaligned((__le16 *) &id[55<<1]));
+		d->geo.sectors = le16_to_cpu(get_unaligned((__le16 *) &id[56<<1]));
 	}
 	d->ssize = ssize;
 	d->geo.start = 0;
Signature · 1 line
  Ed L. Cashin <[email protected]>