bonding: COW before overwriting the destination MAC address
Subsystems (3)
PATCH v2 2/2 bonding: COW before overwriting the destination MAC address
When there is a ptype handler holding a clone of this skb, whose destination MAC addresse is overwritten, the owner of this handler may get a corrupted packet.
---
v2: fix the bug in the previous one. Thank him.
drivers/net/bonding/bond_main.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/bonding/bond_main.c +6 -2
@@ -1511,9 +1511,13 @@ static struct sk_buff *bond_handle_frame(struct sk_buff *skb)if (bond_dev->priv_flags &IFF_MASTER_ALB && bond_dev->priv_flags &IFF_BRIDGE_PORT && skb->pkt_type ==PACKET_HOST ) { -u16 *dest = (u16 *)eth_hdr (skb)->h_dest; -memcpy (dest, bond_dev->dev_addr,ETH_ALEN ); +if (unlikely (skb_cow_head (skb, + skb->data -skb_mac_header (skb)))) { +kfree_skb (skb); +return NULL ; + } +memcpy (eth_hdr (skb)->h_dest, bond_dev->dev_addr,ETH_ALEN ); }return skb;
Quoted 19 lines · Changli Gao
When there is a ptype handler holding a clone of this skb, whose destination MAC addresse is overwritten, the owner of this handler may get a corrupted packet.
Signed-off-by Changli Gao <[email protected]>---
v2: fix the bug in the previous one. Thank him.drivers/net/bonding/bond_main.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/net/bonding/bond_main.c +0
-1@@ -1511,9 +1511,13 @@ static struct sk_buff *bond_handle_frame(struct sk_buff *skb)if (bond_dev->priv_flags &IFF_MASTER_ALB && bond_dev->priv_flags &IFF_BRIDGE_PORT && skb->pkt_type ==PACKET_HOST ) { -u16 *dest = (u16 *)eth_hdr (skb)->h_dest;
drivers/net/bonding/bond_main.c static struct sk_buff *bond_handle_frame(struct sk_buff *skb) · line 1523
Quoted 10 lines
drivers/net/bonding/bond_main.c +6
-1-memcpy (dest, bond_dev->dev_addr,ETH_ALEN ); +if (unlikely (skb_cow_head (skb, + skb->data -skb_mac_header (skb)))) { +kfree_skb (skb); +return NULL ; + } +memcpy (eth_hdr (skb)->h_dest, bond_dev->dev_addr,ETH_ALEN ); }return skb;
Thats minor, but using :
u16 *dest = eth_hdr(skb)->h_dest;
memcpy(dest, ptr, ETH_ALEN);
Is better because compiler knows both destination and source are at least aligned on shorts.
On some arches, it helps to not using 6 bytes copy, but 3 shorts.
Quoted 5 lines · Eric Dumazet
Thats minor, but using :
Quoted 10 lines
u16 *dest = eth_hdr(skb)->h_dest;
memcpy(dest, ptr, ETH_ALEN);Is better because compiler knows both destination and source are at least aligned on shorts.
On some arches, it helps to not using 6 bytes copy, but 3 shorts.
Is it still true if ptr isn't aligned on shorts? And net_device.dev_addr is an unsigned char *pointer. Thanks.
Signature · 2 lines
Regards, Changli Gao([email protected])
Quoted 13 lines · Changli Gao
Quoted 12 lines · Eric Dumazet
Thats minor, but using :
u16 *dest = eth_hdr(skb)->h_dest;
memcpy(dest, ptr, ETH_ALEN);Is better because compiler knows both destination and source are at least aligned on shorts.
Quoted 7 lines
Quoted 3 lines
On some arches, it helps to not using 6 bytes copy, but 3 shorts.
Is it still true if ptr isn't aligned on shorts? And net_device.dev_addr is an unsigned char *pointer. Thanks.
dev_addr[] was aligned to word boundaries (because of natural structure alignment), but the recent changes made it a char *pointer, so gcc is not able to make this true anymore.
This could change if dev_addr was a pointer to struct netdev_hw_addr
From: Changli Gao <[email protected]>
Date: Thu, 3 Mar 2011 15:07:14 +0800
Quoted 5 lines
When there is a ptype handler holding a clone of this skb, whose destination MAC addresse is overwritten, the owner of this handler may get a corrupted packet.
Signed-off-by Changli Gao <[email protected]>
Applied.