netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick McHardy <kaber@trash.net>
To: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	hemao77@gmail.com, bugme-daemon@bugzilla.kernel.org,
	netdev@vger.kernel.org,
	Netfilter Development Mailinglist
	<netfilter-devel@vger.kernel.org>
Subject: Re: [Bugme-new] [Bug 11058] New: DEADLOOP in kernel network module
Date: Wed, 09 Jul 2008 18:32:57 +0200	[thread overview]
Message-ID: <4874E839.50100@trash.net> (raw)
In-Reply-To: <4874D291.1010707@trash.net>

[-- Attachment #1: Type: text/plain, Size: 714 bytes --]

Patrick McHardy wrote:
> Jozsef Kadlecsik wrote:
>> On Wed, 9 Jul 2008, Patrick McHardy wrote:
>>
>>> Good catch, thanks. Basically all del_timer()/timeout.function calls
>>> in conntrack can happen in process context, so we'd have to disable
>>> BHs every time we do this. I think this fix should also work. The
>>> only spot where we return NF_REPEAT is in TCP conntrack, so we can
>>> simply make sure we only do this if we actually managed to kill the
>>> connection.
>>>
>>> Jozsef, what do you think?
>>
>> I agree with you completely - and nice catch, indeed! Your proposed 
>> patch looks just fine.
> 
> Thanks, I'll send a backport for 2.6.26 to Dave tonight.

OK, this is the patch I'll send upstream.


[-- Attachment #2: x --]
[-- Type: text/plain, Size: 1804 bytes --]

commit baa04a1fb3dbef550ed1dc5acd15e21e7dde3b85
Author: Patrick McHardy <kaber@trash.net>
Date:   Wed Jul 9 18:32:29 2008 +0200

    netfilter: nf_conntrack_tcp: fix endless loop
    
    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: hemao77@gmail.com [ Kernel bugzilla #11058 ]
    Signed-off-by: Patrick McHardy <kaber@trash.net>

diff --git a/net/netfilter/nf_conntrack_proto_tcp.c b/net/netfilter/nf_conntrack_proto_tcp.c
index 271cd01..dd28fb2 100644
--- a/net/netfilter/nf_conntrack_proto_tcp.c
+++ b/net/netfilter/nf_conntrack_proto_tcp.c
@@ -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:

      reply	other threads:[~2008-07-09 16:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-11058-10286@http.bugzilla.kernel.org/>
2008-07-09  4:00 ` [Bugme-new] [Bug 11058] New: DEADLOOP in kernel network module Andrew Morton
2008-07-09 12:45   ` Patrick McHardy
2008-07-09 13:27     ` Jozsef Kadlecsik
2008-07-09 15:00       ` Patrick McHardy
2008-07-09 16:32         ` Patrick McHardy [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4874E839.50100@trash.net \
    --to=kaber@trash.net \
    --cc=akpm@linux-foundation.org \
    --cc=bugme-daemon@bugzilla.kernel.org \
    --cc=hemao77@gmail.com \
    --cc=kadlec@blackhole.kfki.hu \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).