From: Patrick McHardy <kaber@trash.net>
To: mirq-linux@rere.qmqm.pl
Cc: netfilter-devel@lists.netfilter.org
Subject: Re: [PATCH 2.6.20 07/10] nfnetlink_log: fix module reference counting
Date: Wed, 14 Feb 2007 17:46:38 +0100 [thread overview]
Message-ID: <45D33CEE.6050404@trash.net> (raw)
In-Reply-To: <20070213162535.GA10544@rere.qmqm.pl>
[-- Attachment #1: Type: text/plain, Size: 1184 bytes --]
Micha³ Miros³aw wrote:
> On Tue, Feb 13, 2007 at 01:48:03PM +0100, Patrick McHardy wrote:
>
>>I think we should just cancel the timer on destruction.
>
>
> It won't solve a race between destroying the instance and logging a
> packet. It could happen that:
>
> CPU1 CPU2
> nfulnl_log_packet()
> -> instance_lookup_get()
> -> lock inst
> ** got lock on inst
> _instance_destroy(inst)
> -> remove inst from list
> -> remove timer and unref inst
> -> lock inst
> -> start a timer
> -> unlock inst
> ** got lock on inst
> -> clear the skb
> -> unlock inst
> -> unref inst
> -> unref module... but we still have a timer pending!
This is easily fixable by adding a synchronize_rcu() call
after removing the instance from the global list.
nfulnl_log_packet() is called within a RCU read-side
critical section, so once synchronize_rcu() returns we're
guaranteed no CPU is within nfulnl_log_packet anymore with
this instance. And I think it is really preferable to having
the timer armed after destroying the instance.
This patch should take care of both the module reference
problem and the refcount leak.
[-- Attachment #2: x --]
[-- Type: text/plain, Size: 833 bytes --]
diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
index 8a460b1..1d45ff6 100644
--- a/net/netfilter/nfnetlink_log.c
+++ b/net/netfilter/nfnetlink_log.c
@@ -213,6 +213,9 @@ _instance_destroy2(struct nfulnl_instanc
if (lock)
write_unlock_bh(&instances_lock);
+ sychronize_rcu();
+ if (del_timer_sync(&inst->timer))
+ instance_put(inst);
/* then flush all pending packets from skb */
spin_lock_bh(&inst->lock);
@@ -363,9 +366,6 @@ __nfulnl_send(struct nfulnl_instance *in
{
int status;
- if (timer_pending(&inst->timer))
- del_timer(&inst->timer);
-
if (!inst->skb)
return 0;
@@ -676,6 +676,9 @@ #endif
* enough room in the skb left. flush to userspace. */
UDEBUG("flushing old skb\n");
+ if (del_timer(&inst->timer))
+ instance_put(inst);
+
__nfulnl_send(inst);
}
next prev parent reply other threads:[~2007-02-14 16:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-12 0:39 [PATCH 2.6.20 07/10] nfnetlink_log: fix module reference counting Michał Mirosław
2007-02-13 12:48 ` Patrick McHardy
2007-02-13 16:25 ` Michał Mirosław
2007-02-14 16:46 ` Patrick McHardy [this message]
2007-02-14 17:07 ` Michał Mirosław
2007-02-14 17:22 ` Patrick McHardy
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=45D33CEE.6050404@trash.net \
--to=kaber@trash.net \
--cc=mirq-linux@rere.qmqm.pl \
--cc=netfilter-devel@lists.netfilter.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.