net: use skb_cow_head() to deal with cloned skbs
Subsystems (5)
cover net: use skb_cow_head() to deal with cloned skbs
James Hughes found an issue with smsc95xx driver. Same problematic code is found in other drivers.
Eric Dumazet (6):
smsc75xx: use skb_cow_head() to deal with cloned skbs
cx82310_eth: use skb_cow_head() to deal with cloned skbs
sr9700: use skb_cow_head() to deal with cloned skbs
lan78xx: use skb_cow_head() to deal with cloned skbs
ch9200: use skb_cow_head() to deal with cloned skbs
kaweth: use skb_cow_head() to deal with cloned skbs
drivers/net/usb/ch9200.c | 9 ++------- drivers/net/usb/cx82310_eth.c | 7 ++----- drivers/net/usb/kaweth.c | 18 ++++++------------ drivers/net/usb/lan78xx.c | 9 ++------- drivers/net/usb/smsc75xx.c | 8 ++------ drivers/net/usb/sr9700.c | 9 ++------- 6 files changed, 16 insertions(+), 44 deletions(-)
Signature · 1 line
2.12.2.816.g2cccc81164-goog
PATCH 1/6 smsc75xx: use skb_cow_head() to deal with cloned skbs
We need to ensure there is enough headroom to push extra header, but we also need to check if we are allowed to change headers.
skb_cow_head() is the proper helper to deal with this.
--- drivers/net/usb/smsc75xx.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/net/usb/smsc75xx.c +2 -6
@@ -2203,13 +2203,9 @@ static struct sk_buff *smsc75xx_tx_fixup(struct usbnet *dev, {u32 tx_cmd_a, tx_cmd_b; -if (skb_headroom (skb) <SMSC75XX_TX_OVERHEAD ) { -struct sk_buff *skb2 = -skb_copy_expand (skb,SMSC75XX_TX_OVERHEAD ,0 , flags); +if (skb_cow_head (skb,SMSC75XX_TX_OVERHEAD )) {dev_kfree_skb_any (skb); - skb = skb2; -if (!skb) -return NULL ; +return NULL ; } tx_cmd_a = (u32)(skb->len &TX_CMD_A_LEN ) |TX_CMD_A_FCS ;
Signature · 1 line
2.12.2.816.g2cccc81164-goog
PATCH 2/6 cx82310_eth: use skb_cow_head() to deal with cloned skbs
In reply to Eric DumazetWe need to ensure there is enough headroom to push extra header, but we also need to check if we are allowed to change headers.
skb_cow_head() is the proper helper to deal with this.
--- drivers/net/usb/cx82310_eth.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/usb/cx82310_eth.c +2 -5
@@ -293,12 +293,9 @@ static struct sk_buff *cx82310_tx_fixup(struct usbnet *dev, struct sk_buff *skb, {int len = skb->len; -if (skb_headroom (skb) <2 ) { -struct sk_buff *skb2 =skb_copy_expand (skb,2 ,0 , flags); +if (skb_cow_head (skb,2 )) {dev_kfree_skb_any (skb); - skb = skb2; -if (!skb) -return NULL ; +return NULL ; }skb_push (skb,2 );
Signature · 1 line
2.12.2.816.g2cccc81164-goog
PATCH 3/6 sr9700: use skb_cow_head() to deal with cloned skbs
In reply to Eric DumazetWe need to ensure there is enough headroom to push extra header, but we also need to check if we are allowed to change headers.
skb_cow_head() is the proper helper to deal with this.
--- drivers/net/usb/sr9700.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/net/usb/sr9700.c +2 -7
@@ -456,14 +456,9 @@ static struct sk_buff *sr9700_tx_fixup(struct usbnet *dev, struct sk_buff *skb, len = skb->len; -if (skb_headroom (skb) <SR_TX_OVERHEAD ) { -struct sk_buff *skb2; - - skb2 =skb_copy_expand (skb,SR_TX_OVERHEAD ,0 , flags); +if (skb_cow_head (skb,SR_TX_OVERHEAD )) {dev_kfree_skb_any (skb); - skb = skb2; -if (!skb) -return NULL ; +return NULL ; }__skb_push (skb,SR_TX_OVERHEAD );
Signature · 1 line
2.12.2.816.g2cccc81164-goog
PATCH 4/6 lan78xx: use skb_cow_head() to deal with cloned skbs
In reply to Eric DumazetWe need to ensure there is enough headroom to push extra header, but we also need to check if we are allowed to change headers.
skb_cow_head() is the proper helper to deal with this.
--- drivers/net/usb/lan78xx.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/net/usb/lan78xx.c +2 -7
@@ -2607,14 +2607,9 @@ static struct sk_buff *lan78xx_tx_prep(struct lan78xx_net *dev, {u32 tx_cmd_a, tx_cmd_b; -if (skb_headroom (skb) <TX_OVERHEAD ) { -struct sk_buff *skb2; - - skb2 =skb_copy_expand (skb,TX_OVERHEAD ,0 , flags); +if (skb_cow_head (skb,TX_OVERHEAD )) {dev_kfree_skb_any (skb); - skb = skb2; -if (!skb) -return NULL ; +return NULL ; }if (lan78xx_linearize (skb) <0 )
Signature · 1 line
2.12.2.816.g2cccc81164-goog
PATCH 5/6 ch9200: use skb_cow_head() to deal with cloned skbs
In reply to Eric DumazetWe need to ensure there is enough headroom to push extra header, but we also need to check if we are allowed to change headers.
skb_cow_head() is the proper helper to deal with this.
--- drivers/net/usb/ch9200.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/net/usb/ch9200.c +2 -7
@@ -254,14 +254,9 @@ static struct sk_buff *ch9200_tx_fixup(struct usbnet *dev, struct sk_buff *skb, tx_overhead =0x40 ; len = skb->len; -if (skb_headroom (skb) < tx_overhead) { -struct sk_buff *skb2; - - skb2 =skb_copy_expand (skb, tx_overhead,0 , flags); +if (skb_cow_head (skb, tx_overhead)) {dev_kfree_skb_any (skb); - skb = skb2; -if (!skb) -return NULL ; +return NULL ; }__skb_push (skb, tx_overhead);
Signature · 1 line
2.12.2.816.g2cccc81164-goog
PATCH 6/6 kaweth: use skb_cow_head() to deal with cloned skbs
In reply to Eric DumazetWe can use skb_cow_head() to properly deal with clones, especially the ones coming from TCP stack that allow their head being modified. This avoids a copy.
--- drivers/net/usb/kaweth.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
drivers/net/usb/kaweth.c +6 -12
@@ -803,18 +803,12 @@ static netdev_tx_t kaweth_start_xmit(struct sk_buff *skb, }/* We now decide whether we can put our special header into the sk_buff */ -if (skb_cloned (skb) ||skb_headroom (skb) <2 ) { -/* no such luck - we make our own */ -struct sk_buff *copied_skb; - copied_skb =skb_copy_expand (skb,2 ,0 ,GFP_ATOMIC ); -dev_kfree_skb_irq (skb); - skb = copied_skb; -if (!copied_skb) { - kaweth->stats.tx_errors++; -netif_start_queue (net); -spin_unlock_irq (&kaweth->device_lock); -return NETDEV_TX_OK ; - } +if (skb_cow_head (skb,2 )) { + kaweth->stats.tx_errors++; +netif_start_queue (net); +spin_unlock_irq (&kaweth->device_lock); +dev_kfree_skb_any (skb); +return NETDEV_TX_OK ; } private_header = (__le16 *)__skb_push (skb,2 );
Signature · 1 line
2.12.2.816.g2cccc81164-goog
David Miller
maintainerFrom: Eric Dumazet <[email protected]>
Date: Wed, 19 Apr 2017 09:59:20 -0700
Quoted 2 lines
James Hughes found an issue with smsc95xx driver. Same problematic code is found in other drivers.
Series applied, thanks Eric.