Skip to contentSkip to conversation

8021q: fix a potential memory leak

PATCH In review [email protected] 3 participants 3 messages Jun 18, 2014 – Jun 21, 2014

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

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
index 9012b1c..75d4277 100644
@@ -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
Acked-by on v1 1/1
#1 lore raw
Quoted 18 lines · On Wed, 2014-06-18 at 13:46 +0800, [email protected] wrote:

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 +0 -0
index 9012b1c..75d4277 100644
@@ -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...

maintainer
#2 lore raw
In reply to [email protected]

From: [email protected]
Date: Wed, 18 Jun 2014 13:46:02 +0800

Quoted 7 lines

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.

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.