ethernet: add sanity check before memory dereferencing
Subsystems (2)
PATCH 1/1 ethernet: add sanity check before memory dereferencing
add sanity check before memory dereferencing
Some callers of eth_type_trans() only can assure the length of the packets passed to it is not less than ETH_HLEN. We'd better check the packets length before dereferencing skb->data.
----
net/ethernet/eth.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
net/ethernet/eth.c +1 -4
@@ -158,7 +158,6 @@ EXPORT_SYMBOL(eth_rebuild_header);__be16 eth_type_trans (struct sk_buff *skb,struct net_device *dev) {struct ethhdr *eth; -unsigned char *rawp; skb->dev = dev;skb_reset_mac_header (skb);
@@ -199,15 +198,13 @@ __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev)if (ntohs (eth->h_proto) >=1536 )return eth->h_proto; - rawp = skb->data; -/* * This is a magic hack to spot IPX packets. Older Novell breaks * the protocol design and runs IPX over 802.3 without an 802.2 LLC * layer. We look for FFFF which isn't a used 802.2 SSAP/DSAP. This * won't work for fault tolerant netware but does for the rest. */ -if (*(unsigned short *)rawp ==0xFFFF ) +if (skb->len >=2 && *(unsigned short *)(skb->data) ==0xFFFF )return htons (ETH_P_802_3 );/*
David Miller
maintainerFrom: Changli Gao <[email protected]>
Date: Tue, 4 May 2010 11:33:48 +0800
Quoted 7 lines
add sanity check before memory dereferencing
Some callers of
eth_type_trans()only can assure the length of the packets passed to it is not less thanETH_HLEN. We'd better check the packets length before dereferencingskb->data.Signed-off-by Changli Gao <[email protected]>
We can deference skb->data for at least 16 bytes or so past the end of the valid packet data area however we want.
It might give garbage values, but it will not cause a fault or any kind.
We want to remove checks here, not add new ones Changli.