Skip to contentSkip to conversation

conntrack event cache deadlock

DISCUSSION David S. Miller 2 participants 2 messages Sep 22, 2005 netfilter

lore
Share & tools
lore
#0 lore raw

We can try to take the ip_conntrack_lock as a writer twice, and thus deadlock, via this code path:

ip_ct_refresh_acct()
{
...

		write_lock_bh(&ip_conntrack_lock);
		/* Need del_timer for race avoidance (may already be dying). */
		if (del_timer(&ct->timeout)) {
			ct->timeout.expires = jiffies + extra_jiffies;
			add_timer(&ct->timeout);
			/* FIXME: We loose some REFRESH events if this function
			 * is called without an skb.  I'll fix this later -HW */
			if (skb)
				ip_conntrack_event_cache(IPCT_REFRESH, skb);

ip_conntrack_event_cache()
{
...

		__ip_ct_event_cache_init(ct);

__ip_ct_event_cache_init()
{
...

		__ip_ct_deliver_cached_events(ecache);

ip_ct_deliver_cached_events()
{
...

		__ip_ct_deliver_cached_events(ecache);

__ip_ct_deliver_cached_events()
{
...

	ip_conntrack_put(ecache->ct);

ip_conntrack_put()
{
...

	nf_conntrack_put(&ct->ct_general);

nf_conntrack_put()
{
...

	if (nfct && atomic_dec_and_test(&nfct->use))
		nfct->destroy(nfct);

->destroy() is setup by:

	conntrack->ct_general.destroy = destroy_conntrack;

so we call:

destroy_conntrack()
{
...

	write_lock_bh(&ip_conntrack_lock);

and this is where we deadlock.

This was caught by Ingo's spinlock debugging code in lib/spinlock_debug.c BTW :-)

#1 lore raw
Quoted 3 lines · David S. Miller

We can try to take the ip_conntrack_lock as a writer twice, and thus deadlock, via this code path:

Thanks, this has been pending on our TODO list for quite some time. We
can also sleep while holding a lock. The fundamental problem is that updating the event cache can trigger a previous event to be delivered (via a notifier chain), and we don't really know what hangs off the notifier. Therefore, we have to change the code to only call the event cache functions outside any locks held.

I'm terribly busy today, but I'll try to look into it asap.

This needs to be fixed before 2.6.14 becomes final.

Signature · 5 lines
- Harald Welte <[email protected]>                 http://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