Skip to contentSkip to conversation

core/netfilter.c: possible use of freed skb

PATCH/RFC Applied Bart De Schuymer 3 participants 4 messages Jul 27, 2003 – Jul 30, 2003

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

Hi Dave,

In nf_reinject(), info->okfn(skb) is called when the verdict is NF_ACCEPT. This okfn deals with the skb and is responsible for freeing the skb. Unfortunately the current code in nf_reinject() still uses this possibly freed skb.
The patch below fixes this without introducing any new code. It should be ok to dev_put the devices earlier, thanks to the preceding rcu_read_lock.
I also moved the dev_put's of info->{in,out}dev to keep the code together.

cheers,
Bart

net/core/netfilter.c renamed from net/core/netfilter.c.old +12 -13
@@ -557,6 +557,18 @@ void nf_reinject(struct sk_buff *skb, st
 
 	rcu_read_lock();
 
+	/* Release those devices we held, or Alexey will kill me. */
+	if (info->indev) dev_put(info->indev);
+	if (info->outdev) dev_put(info->outdev);
+#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
+	if (skb->nf_bridge) {
+		if (skb->nf_bridge->physindev)
+			dev_put(skb->nf_bridge->physindev);
+		if (skb->nf_bridge->physoutdev)
+			dev_put(skb->nf_bridge->physoutdev);
+	}
+#endif
+
 	/* Drop reference to owner of hook which queued us. */
 	module_put(info->elem->owner);
 
@@ -599,19 +611,6 @@ void nf_reinject(struct sk_buff *skb, st
 	}
 	rcu_read_unlock();
 
-	/* Release those devices we held, or Alexey will kill me. */
-	if (info->indev) dev_put(info->indev);
-	if (info->outdev) dev_put(info->outdev);
-#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
-	if (skb->nf_bridge) {
-		if (skb->nf_bridge->physindev)
-			dev_put(skb->nf_bridge->physindev);
-		if (skb->nf_bridge->physoutdev)
-			dev_put(skb->nf_bridge->physoutdev);
-	}
-#endif
-
-
 	if (verdict == NF_DROP)
 		kfree_skb(skb);
 
#1 lore raw
Quoted 5 lines · On Sun, 27 Jul 2003 16:55:15 +0200 Bart De Schuymer <[email protected]> wrote:

In nf_reinject(), info->okfn(skb) is called when the verdict is NF_ACCEPT. This okfn deals with the skb and is responsible for freeing the skb. Unfortunately the current code in nf_reinject() still uses this possibly freed skb.
The patch below fixes this without introducing any new code.

This patch looks OK to me, can I get an ACK from the netfilter folks?

#2 lore raw
Quoted 2 lines · David S. Miller

This patch looks OK to me, can I get an ACK from the netfilter folks?

Dave, the patch looks fine to me.

Sorry for the delay, still catching up with everything that was lost while I was at OLS.

Please apply!

Signature · 5 lines
- Harald Welte <[email protected]>             http://www.netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie
#3 lore raw
Quoted 6 lines · On Wed, 30 Jul 2003 16:06:29 +0200 Harald Welte <[email protected]> wrote:
Quoted 2 lines · David S. Miller

This patch looks OK to me, can I get an ACK from the netfilter folks?

Dave, the patch looks fine to me.

Applied, thanks guys.