Skip to contentSkip to conversation

net: dsa: skb_put_padto() already frees nskb

PATCH In review Florian Fainelli 3 participants 5 messages Aug 21, 2017 – Aug 22, 2017

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

PATCH 1/1 net: dsa: skb_put_padto() already frees nskb

skb_put_padto() already frees the passed sk_buff reference upon error, so calling kfree_skb() on it again is not necessary.

Detected by CoverityScan, CID#1416687 ("USE_AFTER_FREE")

Fixes e71cb9e00922 ("net: dsa: ksz: fix skb freeing")
---
 net/dsa/tag_ksz.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
net/dsa/tag_ksz.c +1 -3
index de66ca8e6201..107172c82107 100644
@@ -60,10 +60,8 @@ static struct sk_buff *ksz_xmit(struct sk_buff *skb, struct net_device *dev)
 					 skb_transport_header(skb) - skb->head);
 		skb_copy_and_csum_dev(skb, skb_put(nskb, skb->len));
 
-		if (skb_put_padto(nskb, nskb->len + padlen)) {
-			kfree_skb(nskb);
+		if (skb_put_padto(nskb, nskb->len + padlen))
 			return NULL;
-		}
 
 		kfree_skb(skb);
 	}
Signature · 1 line
2.9.3
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Florian Fainelli

skb_put_padto() already frees the passed sk_buff reference upon error, so calling kfree_skb() on it again is not necessary.

Detected by CoverityScan, CID#1416687 ("USE_AFTER_FREE")

Fixes e71cb9e00922 ("net: dsa: ksz: fix skb freeing")

Andrew

#2 lore raw
In reply to Florian Fainelli

Florian,

Quoted 35 lines

-----Original Message-----
From: Florian Fainelli [mailto:[email protected]]
Sent: Monday, August 21, 2017 3:42 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Woojung Huh - C21699; Florian Fainelli
Subject: [PATCH net] net: dsa: skb_put_padto() already frees nskb

skb_put_padto() already frees the passed sk_buff reference upon error, so calling kfree_skb() on it again is not necessary.

Detected by CoverityScan, CID#1416687 ("USE_AFTER_FREE")

Fixes e71cb9e00922 ("net: dsa: ksz: fix skb freeing")
---
 net/dsa/tag_ksz.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
net/dsa/tag_ksz.c +1 -3
index de66ca8e6201..107172c82107 100644
@@ -60,10 +60,8 @@ static struct sk_buff *ksz_xmit(struct sk_buff *skb,
 struct net_device *dev)
 					 skb_transport_header(skb) - skb-
 >head);
 		skb_copy_and_csum_dev(skb, skb_put(nskb, skb->len));
 
-		if (skb_put_padto(nskb, nskb->len + padlen)) {
-			kfree_skb(nskb);
+		if (skb_put_padto(nskb, nskb->len + padlen))
 			return NULL;
-		}
 

net/dsa/tag_ksz.c static struct sk_buff *ksz_xmit(struct sk_buff *skb, struct net_device *dev)

Quoted 3 lines
net/dsa/tag_ksz.c +0 -1
 		kfree_skb(skb);
 	}
--

Because skb_put_padto() frees skb when it fails, below lines in e71cb9e00922 ("net: dsa: ksz: fix skb freeing") will be an issue to.

	if (skb_tailroom(skb) >= padlen + KSZ_INGRESS_TAG_LEN) {

+ if (skb_put_padto(skb, skb->len + padlen))
+ return NULL;
+

When it fails skb will be freed twice in skb_put_padto() and caller of dsa_slave_xmit().

Woojung

#3 lore raw
Quoted 49 lines · On 08/21/2017 03:15 PM, [email protected] wrote:

Florian,

Quoted 35 lines

-----Original Message-----
From: Florian Fainelli [mailto:[email protected]]
Sent: Monday, August 21, 2017 3:42 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Woojung Huh - C21699; Florian Fainelli
Subject: [PATCH net] net: dsa: skb_put_padto() already frees nskb

skb_put_padto() already frees the passed sk_buff reference upon error, so calling kfree_skb() on it again is not necessary.

Detected by CoverityScan, CID#1416687 ("USE_AFTER_FREE")

Fixes e71cb9e00922 ("net: dsa: ksz: fix skb freeing")
---
 net/dsa/tag_ksz.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
net/dsa/tag_ksz.c +1 -3
index de66ca8e6201..107172c82107 100644
@@ -60,10 +60,8 @@ static struct sk_buff *ksz_xmit(struct sk_buff *skb,
 struct net_device *dev)
 					 skb_transport_header(skb) - skb-
 > head);
 		skb_copy_and_csum_dev(skb, skb_put(nskb, skb->len));
 
-		if (skb_put_padto(nskb, nskb->len + padlen)) {
-			kfree_skb(nskb);
+		if (skb_put_padto(nskb, nskb->len + padlen))
 			return NULL;
-		}
 

net/dsa/tag_ksz.c static struct sk_buff *ksz_xmit(struct sk_buff *skb, struct net_device *dev)

Quoted 3 lines
net/dsa/tag_ksz.c +0 -1
 		kfree_skb(skb);
 	}
--

Because skb_put_padto() frees skb when it fails, below lines in e71cb9e00922 ("net: dsa: ksz: fix skb freeing") will be an issue to.

	if (skb_tailroom(skb) >= padlen + KSZ_INGRESS_TAG_LEN) {
(quoted diff) +3 -0
+		if (skb_put_padto(skb, skb->len + padlen))
+			return NULL;
+
Quoted 2 lines

When it fails skb will be freed twice in skb_put_padto() and caller of dsa_slave_xmit().

You are right, I am not sure what is the best way to fix tag_ksz.c other than somehow open coding skb_put_padto() minus the freeing on error part?

Signature · 1 line
Florian
#4 lore raw
Quoted 9 lines
Quoted 1 line

Because skb_put_padto() frees skb when it fails, below lines in

e71cb9e00922

Quoted 7 lines

("net: dsa: ksz: fix skb freeing") will be an issue to.

	if (skb_tailroom(skb) >= padlen + KSZ_INGRESS_TAG_LEN) {
(quoted diff) +3 -0
+		if (skb_put_padto(skb, skb->len + padlen))
+			return NULL;
+
Quoted 5 lines
Quoted 2 lines

When it fails skb will be freed twice in skb_put_padto() and caller of dsa_slave_xmit().

You are right, I am not sure what is the best way to fix tag_ksz.c other than somehow open coding skb_put_padto() minus the freeing on error part?

Agree. May need to go back to 1st submission without skb_put_padto(). Will check more if any other ideas.

Thanks.
Woojung