Skip to contentSkip to conversation

: Fix deadlock on NAT helper unload

NETFILTER 2.4 Patrick McHardy 3 participants 3 messages Sep 14, 2006 – Oct 8, 2006

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

[NETFILTER]: Fix deadlock on NAT helper unload

When a NAT helper is unlocked conntrack/NAT may deadlock because of the following lock sequence:

.. ip_nat_helper_unregister
-> ip_ct_selective_cleanup
-> get_next_corpse (ip_conntrack_lock)
-> kill_helper (ip_nat_lock)

.. ip_nat_fn (ip_nat_lock)
-> ip_nat_setup_info
-> ip_conntrack_alter_reply (ip_conntrack_lock)

Taking ip_nat_lock in kill_helper() is unnecessary since the helper assigned to a connection is immutable and new connections can't have the helper that is beeing unloaded assigned since it is already removed from the global list.

Reported by <[email protected]>.

net/ipv4/netfilter/ip_nat_helper.c +1 -7
@@ -522,13 +522,7 @@
 static int
 kill_helper(const struct ip_conntrack *i, void *helper)
 {
-	int ret;
-
-	READ_LOCK(&ip_nat_lock);
-	ret = (i->nat.info.helper == helper);
-	READ_UNLOCK(&ip_nat_lock);
-
-	return ret;
+	return (i->nat.info.helper == helper);
 }
 
 void ip_nat_helper_unregister(struct ip_nat_helper *me)
#1 lore raw

Hi Patrick,

I missed this patch, and it seems David did not notice it either. David, do you have any objection against it ? Otherwise I will merge it.

Thanks,
Willy

Quoted 38 lines · Patrick McHardy

[NETFILTER]: Fix deadlock on NAT helper unload
When a NAT helper is unlocked conntrack/NAT may deadlock because of the following lock sequence:

.. ip_nat_helper_unregister
-> ip_ct_selective_cleanup
-> get_next_corpse (ip_conntrack_lock)
-> kill_helper (ip_nat_lock)

.. ip_nat_fn (ip_nat_lock)
-> ip_nat_setup_info
-> ip_conntrack_alter_reply (ip_conntrack_lock)

Taking ip_nat_lock in kill_helper() is unnecessary since the helper assigned to a connection is immutable and new connections can't have the helper that is beeing unloaded assigned since it is already removed from the global list.

Reported by <[email protected]>.

net/ipv4/netfilter/ip_nat_helper.c +1 -7
@@ -522,13 +522,7 @@
 static int
 kill_helper(const struct ip_conntrack *i, void *helper)
 {
-	int ret;
-
-	READ_LOCK(&ip_nat_lock);
-	ret = (i->nat.info.helper == helper);
-	READ_UNLOCK(&ip_nat_lock);
-
-	return ret;
+	return (i->nat.info.helper == helper);
 }
 
 void ip_nat_helper_unregister(struct ip_nat_helper *me)
maintainer
#2 lore raw

From: Willy Tarreau <[email protected]>
Date: Sat, 7 Oct 2006 11:50:11 +0200

Quoted 3 lines

I missed this patch, and it seems David did not notice it either. David, do you have any objection against it ? Otherwise I will merge it.

No objection, it's been rotting in my mailbox too, sorry: