Skip to contentSkip to conversation

Fix double-free in br_add_if.

PATCH Stephen Hemminger 1 participant 1 message Sep 25, 2009 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 32 lines · On Fri, 25 Sep 2009 14:25:24 -0600 Jeff Hansen <[email protected]> wrote:

There is a potential double-kfree in net/bridge/br_if.c. If br_fdb_insert fails, then the kobject is put back (which calls kfree due to the kobject release), and then kfree is called again on the net_bridge_port. This patch fixes the crash.

---
 net/bridge/br_if.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
net/bridge/br_if.c +2 -1
index eb404dc..1becec1 100644
@@ -368,7 +368,7 @@ done:
 int br_add_if(struct net_bridge *br, struct net_device *dev)
 {
 	struct net_bridge_port *p;
-	int err = 0;
+	int err = 0, kobj_initted = 0;
 
 	if (dev->flags & IFF_LOOPBACK || dev->type != ARPHRD_ETHER)
 		return -EINVAL;
@@ -391,6 +391,7 @@ int br_add_if(struct net_bridge *br, struct net_device *dev)
 				   SYSFS_BRIDGE_PORT_ATTR);
 	if (err)
 		goto err0;
+	kobj_initted = 1;
 
 	err = br_fdb_insert(br, p, dev->dev_addr);
 	if (err)

net/bridge/br_if.c err0: · line 437

Quoted 9 lines
net/bridge/br_if.c +2 -1
@@ -429,7 +430,8 @@ err0:
 	dev_set_promiscuity(dev, -1);
 put_back:
 	dev_put(dev);
-	kfree(p);
+	if (!kobj_initted)
+		kfree(p);
 	return err;
 }
 

I'll look at it, probably needs fixing, but the code style with condition variables is out of place in this code.