Skip to contentSkip to conversation

ipmr: Don't leak memory if fib lookup fails.

ipmr Ben Greear 2 participants 3 messages Jul 15, 2010 – Jul 16, 2010

Subsystems (3)
lore
Share & tools
lore

Ben Greear

author
#0 lore raw

This was detected using two mcast router tables. The pimreg for the second interface did not have a specific mrule, so packets received by it were handled by the default table, which had nothing configured.

This caused the ipmr_fib_lookup to fail, causing the memory leak.

---
:100644 100644 ed2f911... f112ad8... M net/ipv4/ipmr.c

 net/ipv4/ipmr.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
net/ipv4/ipmr.c +6 -2
index ed2f911..f112ad8 100644
@@ -442,8 +442,10 @@ static netdev_tx_t reg_vif_xmit(struct sk_buff *skb, struct net_device *dev)
 	int err;
 
 	err = ipmr_fib_lookup(net, &fl, &mrt);
-	if (err < 0)
+	if (err < 0) {
+		kfree_skb(skb);
 		return err;
+	}
 
 	read_lock(&mrt_lock);
 	dev->stats.tx_bytes += skb->len;
@@ -1729,8 +1731,10 @@ int ip_mr_input(struct sk_buff *skb)
 		goto dont_forward;
 
 	err = ipmr_fib_lookup(net, &skb_rtable(skb)->fl, &mrt);
-	if (err < 0)
+	if (err < 0) {
+		kfree_skb(skb);
 		return err;
+	}
 
 	if (!local) {
 		    if (IPCB(skb)->opt.router_alert) {
Signature · 1 line
1.6.2.5
author
#1 lore raw
Quoted 4 lines · Ben Greear

This was detected using two mcast router tables. The pimreg for the second interface did not have a specific mrule, so packets received by it were handled by the default table, which had nothing configured.

I just realized this should be applied against 2.6.35-pre, not 2.6.34.

Thanks,
Ben

Quoted 37 lines

This caused the ipmr_fib_lookup to fail, causing the memory leak.

---
:100644 100644 ed2f911... f112ad8... M net/ipv4/ipmr.c

  net/ipv4/ipmr.c |    8 ++++++--
  1 files changed, 6 insertions(+), 2 deletions(-)
net/ipv4/ipmr.c +6 -2
index ed2f911..f112ad8 100644
@@ -442,8 +442,10 @@ static netdev_tx_t reg_vif_xmit(struct sk_buff *skb, struct net_device *dev)
  	int err;
 
  	err = ipmr_fib_lookup(net,&fl,&mrt);
-	if (err<  0)
+	if (err<  0) {
+		kfree_skb(skb);
  		return err;
+	}
 
  	read_lock(&mrt_lock);
  	dev->stats.tx_bytes += skb->len;
@@ -1729,8 +1731,10 @@ int ip_mr_input(struct sk_buff *skb)
  		goto dont_forward;
 
  	err = ipmr_fib_lookup(net,&skb_rtable(skb)->fl,&mrt);
-	if (err<  0)
+	if (err<  0) {
+		kfree_skb(skb);
  		return err;
+	}
 
  	if (!local) {
  		    if (IPCB(skb)->opt.router_alert) {
Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com
maintainer
#2 lore raw

From: Ben Greear <[email protected]>
Date: Thu, 15 Jul 2010 17:04:58 -0700

Quoted 7 lines · Ben Greear
Quoted 4 lines

This was detected using two mcast router tables. The pimreg for the second interface did not have a specific mrule, so packets received by it were handled by the default table, which had nothing configured.

I just realized this should be applied against 2.6.35-pre, not 2.6.34.

Fix looks good, applied to net-2.6, thanks!