Skip to contentSkip to conversation

netfilter -stable: nf_conntrack_tcp: fix endless loop

PATCH Patrick McHardy 2 participants 2 messages Jul 17, 2008 – Jul 30, 2008

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

This patch for 2.6.25.x fixes a race condition between TCP conntrack and ctnetlink that can lead to an endless loop.

Please apply, thanks.

commit e85c8c076640e9cd42fb52f27fea16f74b236626

Author: Patrick McHardy <[email protected]>
Date:   Thu Jul 17 14:06:16 2008 +0200

netfilter: nf_conntrack_tcp: fix endless loop

Upstream commit 6b69fe0:

When a conntrack entry is destroyed in process context and destruction is interrupted by packet processing and the packet is an attempt to reopen a closed connection, TCP conntrack tries to kill the old entry itself and returns NF_REPEAT to pass the packet through the hook again. This may lead to an endless loop: TCP conntrack repeatedly finds the old entry, but can not kill it itself since destruction is already in progress, but destruction in process context can not complete since TCP conntrack is keeping the CPU busy.

Drop the packet in TCP conntrack if we can't kill the connection ourselves to avoid this.

Reported by: [email protected] [ Kernel bugzilla #11058 ]

net/netfilter/nf_conntrack_proto_tcp.c +8 -2
index 6256795..73cef18 100644
@@ -844,9 +844,15 @@ static int tcp_packet(struct nf_conn *ct,
 			/* Attempt to reopen a closed/aborted connection.
 			 * Delete this connection and look up again. */
 			write_unlock_bh(&tcp_lock);
-			if (del_timer(&ct->timeout))
+			/* Only repeat if we can actually remove the timer.
+			 * Destruction may already be in progress in process
+			 * context and we must give it a chance to terminate.
+			 */
+			if (del_timer(&ct->timeout)) {
 				ct->timeout.function((unsigned long)ct);
-			return -NF_REPEAT;
+				return -NF_REPEAT;
+			}
+			return -NF_DROP;
 		}
 		/* Fall through */
 	case TCP_CONNTRACK_IGNORE:
#1 lore raw

patch netfilter-stable-nf_conntrack_tcp-fix-endless-loop.patch added to 2.6.25-stable tree

This is a note to let you know that we have just queued up the patch titled

Subject: netfilter -stable: nf_conntrack_tcp: fix endless loop

to the 2.6.25-stable tree. Its filename is

netfilter-stable-nf_conntrack_tcp-fix-endless-loop.patch

A git repo of this tree can be found at
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

Quoted 1 line

From [email protected] Thu Jul 17 05:08:03 2008

From: Patrick McHardy <[email protected]>
Date: Thu, 17 Jul 2008 14:07:47 +0200
Subject: netfilter -stable: nf_conntrack_tcp: fix endless loop
To: [email protected]
Cc: Netfilter Development Mailinglist <[email protected]>, "David S. Miller" <[email protected]>
Message-ID: <[email protected]>

From: Patrick McHardy <[email protected]>

netfilter: nf_conntrack_tcp: fix endless loop

Upstream commit 6b69fe0:

When a conntrack entry is destroyed in process context and destruction is interrupted by packet processing and the packet is an attempt to reopen a closed connection, TCP conntrack tries to kill the old entry itself and returns NF_REPEAT to pass the packet through the hook again. This may lead to an endless loop: TCP conntrack repeatedly finds the old entry, but can not kill it itself since destruction is already in progress, but destruction in process context can not complete since TCP conntrack is keeping the CPU busy.

Drop the packet in TCP conntrack if we can't kill the connection ourselves to avoid this.

Reported by: [email protected] [ Kernel bugzilla #11058 ]

---
 net/netfilter/nf_conntrack_proto_tcp.c |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
net/netfilter/nf_conntrack_proto_tcp.c +8 -2
@@ -845,9 +845,15 @@ static int tcp_packet(struct nf_conn *ct
 			/* Attempt to reopen a closed/aborted connection.
 			 * Delete this connection and look up again. */
 			write_unlock_bh(&tcp_lock);
-			if (del_timer(&ct->timeout))
+			/* Only repeat if we can actually remove the timer.
+			 * Destruction may already be in progress in process
+			 * context and we must give it a chance to terminate.
+			 */
+			if (del_timer(&ct->timeout)) {
 				ct->timeout.function((unsigned long)ct);
-			return -NF_REPEAT;
+				return -NF_REPEAT;
+			}
+			return -NF_DROP;
 		}
 		/* Fall through */
 	case TCP_CONNTRACK_IGNORE:

Patches currently in stable-queue which might be from [email protected] are

queue-2.6.25/netfilter-stable-nf_conntrack_tcp-fix-endless-loop.patch