8021q: fix a potential memory leak
Subsystems (2)
PATCH 1/1 8021q: fix a potential memory leak
From: Li RongQing <[email protected]>
skb_cow called in vlan_reorder_header does not free the skb when it failed, and vlan_reorder_header returns NULL to reset original skb when it is called in vlan_untag, lead to a memory leak.
--- net/8021q/vlan_core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/8021q/vlan_core.c +4 -1
@@ -114,8 +114,11 @@ EXPORT_SYMBOL(vlan_dev_vlan_proto);static struct sk_buff *vlan_reorder_header (struct sk_buff *skb) { -if (skb_cow (skb,skb_headroom (skb)) <0 ) +if (skb_cow (skb,skb_headroom (skb)) <0 ) { +kfree_skb (skb);return NULL ; + } +memmove (skb->data -ETH_HLEN , skb->data -VLAN_ETH_HLEN ,2 *ETH_ALEN ); skb->mac_header +=VLAN_HLEN ;return skb;
Signature · 1 line
1.7.10.4
Quoted 18 lines · On Wed, 2014-06-18 at 13:46 +0800, [email protected] wrote:
From: Li RongQing <[email protected]>
skb_cowcalled invlan_reorder_headerdoes not free the skb when it failed, andvlan_reorder_headerreturns NULL to reset original skb when it is called invlan_untag, lead to a memory leak.Signed-off-by Li RongQing <[email protected]>--- net/8021q/vlan_core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)net/8021q/vlan_core.c +0
-0@@ -114,8 +114,11 @@ EXPORT_SYMBOL(vlan_dev_vlan_proto);static struct sk_buff *vlan_reorder_header (struct sk_buff *skb)
net/8021q/vlan_core.c EXPORT_SYMBOL(vlan_dev_vlan_proto); · line 124
Quoted 10 lines
net/8021q/vlan_core.c +4
-1{ -if (skb_cow (skb,skb_headroom (skb)) <0 ) +if (skb_cow (skb,skb_headroom (skb)) <0 ) { +kfree_skb (skb);return NULL ; + } +memmove (skb->data -ETH_HLEN , skb->data -VLAN_ETH_HLEN ,2 *ETH_ALEN ); skb->mac_header +=VLAN_HLEN ;return skb;
Good catch.
Note that the 'goto err_free;' in caller is misleading as well, as skb is NULL.
vlan_reorder_header() could return an error code instead of a skb...
David Miller
maintainerFrom: [email protected]
Date: Wed, 18 Jun 2014 13:46:02 +0800
Quoted 7 lines
From: Li RongQing <[email protected]>
skb_cowcalled invlan_reorder_headerdoes not free the skb when it failed, andvlan_reorder_headerreturns NULL to reset original skb when it is called invlan_untag, lead to a memory leak.Signed-off-by Li RongQing <[email protected]>
Applied and queued up for -stable, thanks.
And I agree with Eric that we could define this to return error codes since 'skb' never changes so returning skb vs. NULL is rather awkward.