Skip to contentSkip to conversation

bridge: netfilter: fix a memory leak

PATCH Superseded Changli Gao 2 participants 3 messages Aug 20, 2010 – Aug 23, 2010

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bridge: netfilter: fix a memory leak

nf_bridge_alloc() always reset the skb->nf_bridge, so we should always put the old one. skb->nf_bridge->use is initialized in nf_bridge_alloc(), so we don't need to initialize it again.

---
 net/bridge/br_netfilter.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
net/bridge/br_netfilter.c +2 -4
index 2c911c0..7fde554 100644
@@ -159,11 +159,9 @@ static inline struct nf_bridge_info *nf_bridge_unshare(struct sk_buff *skb)
 	if (atomic_read(&nf_bridge->use) > 1) {
 		struct nf_bridge_info *tmp = nf_bridge_alloc(skb);
 
-		if (tmp) {
+		if (tmp)
 			memcpy(tmp, nf_bridge, sizeof(struct nf_bridge_info));
-			atomic_set(&tmp->use, 1);
-			nf_bridge_put(nf_bridge);
-		}
+		nf_bridge_put(nf_bridge);
 		nf_bridge = tmp;
 	}
 	return nf_bridge;
maintainer
#1 lore raw

From: Changli Gao <[email protected]>
Date: Fri, 20 Aug 2010 13:03:16 +0800

Quoted 5 lines

nf_bridge_alloc() always reset the skb->nf_bridge, so we should always put the old one. skb->nf_bridge->use is initialized in nf_bridge_alloc(), so we don't need to initialize it again.

We just memcpy()'d 'nf_bridge' to 'tmp', that why the ->use count is going to be something other than '1'. It now has the ->use count that 'nf_bridge' did.

And that is why we must explicitly do atomic_set() on 'tmp'.

#2 lore raw
Quoted 7 lines · David Miller

From: Changli Gao <[email protected]>
Date: Fri, 20 Aug 2010 13:03:16 +0800

Quoted 4 lines

nf_bridge_alloc() always reset the skb->nf_bridge, so we should always put the old one. skb->nf_bridge->use is initialized in nf_bridge_alloc(), so we don't need to initialize it again.

Quoted 8 lines
Quoted 1 line

We just memcpy()'d 'nf_bridge' to 'tmp', that why the ->use count is going to be something other than '1'.  It now has the ->use count that 'nf_bridge' did.

And that is why we must explicitly do atomic_set() on 'tmp'.

Oops, thanks. I'll post a update.

Signature · 2 lines
Regards,
Changli Gao([email protected])