locking issue in ip_conntrack_alter_reply
Subsystems (2)
Hi everyone,
I submitted a patch for a similar issue not a long time ago. See:
http://lists.netfilter.org/pipermail/netfilter-devel/2004-March/014764.html
Well, actually I found a contradiction here, we write-locked the conntrack table but that assertion says that this conntrack is not confirmed, this implies that the conntrack is not in the hash table yet. If that assertion is right, we should replace that write_lock for a read_lock while calling __ip_conntrack_find and remove that write_lock at the end of the function.
int ip_conntrack_alter_reply(struct ip_conntrack *conntrack,
const struct ip_conntrack_tuple *newreply)
{
WRITE_LOCK(&ip_conntrack_lock);
if (__ip_conntrack_find(newreply, conntrack)) {
WRITE_UNLOCK(&ip_conntrack_lock);
return 0;
}
/* Should be unconfirmed, so not in hash table yet */
IP_NF_ASSERT(!is_confirmed(conntrack)); <--------------------------I'll study if that assertion is right before submitting a patch. Feedback is always welcome :-).
regards,
Pablo
Hi Pablo,
Quoted 19 lines · Pablo Neira
Well, actually I found a contradiction here, we write-locked the conntrack table but that assertion says that this conntrack is not confirmed, this implies that the conntrack is not in the hash table yet. If that assertion is right, we should replace that
write_lockfor aread_lockwhile calling__ip_conntrack_findand remove thatwrite_lockat the end of the function.int ip_conntrack_alter_reply(struct
ip_conntrack*conntrack,
const structip_conntrack_tuple*newreply){ WRITE_LOCK(&ip_conntrack_lock); if (__ip_conntrack_find(newreply, conntrack)) { WRITE_UNLOCK(&ip_conntrack_lock); return 0; } /* Should be unconfirmed, so not in hash table yet */ IP_NF_ASSERT(!is_confirmed(conntrack)); <--------------------------
Quoted 1 line
I'll study if that assertion is right before submitting a patch.
The assertion is right, because we alter unconfirmed packets when setting up nat info. And you're also right, write-locking is unnecessary: the entry is not in the hash table yet, so nobody else can grab and modify the conntrack entry. [And it is overlooked in the per bucket locking patch too.]
Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : KFKI Research Institute for Particle and Nuclear Physics
H-1525 Budapest 114, POB. 49, Hungary
Quoted 4 lines · Jozsef Kadlecsik
On Fri, 30 Apr 2004, Pablo Neira wrote:
Quoted 10 lines
Quoted 3 lines
I'll study if that assertion is right before submitting a patch.
The assertion is right, because we alter unconfirmed packets when setting up nat info. And you're also right, write-locking is unnecessary: the entry is not in the hash table yet, so nobody else can grab and modify the conntrack entry. [And it is overlooked in the per bucket locking patch too.]
I've ported your conntrack patches to 2.6, I will include this change before adding them to CVS.
Regards
Patrick
Quoted 10 lines
Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : KFKI Research Institute for Particle and Nuclear PhysicsH-1525 Budapest 114, POB. 49, Hungary
Hi Patrick,
Quoted 10 lines · Patrick McHardy
Quoted 4 lines · Jozsef Kadlecsik
The assertion is right, because we alter unconfirmed packets when setting up nat info. And you're also right, write-locking is unnecessary: the entry is not in the hash table yet, so nobody else can grab and modify the conntrack entry. [And it is overlooked in the per bucket locking patch too.]
I've ported your conntrack patches to 2.6, I will include this change before adding them to CVS.
Attached the patch to fix this.
regards,
Pablo
Index: net/ipv4/netfilter/ip_conntrack_core.c
===================================================================
RCS file: /home/cvs/linux-2.6/net/ipv4/netfilter/ip_conntrack_core.c,v retrieving revision 1.1.1.1
net/ipv4/netfilter/ip_conntrack_core.c +2 -3
@@ -1093,9 +1093,9 @@int ip_conntrack_alter_reply (struct ip_conntrack *conntrack,const struct ip_conntrack_tuple *newreply) { -WRITE_LOCK (&ip_conntrack_lock); +READ_LOCK (&ip_conntrack_lock);if (__ip_conntrack_find (newreply, conntrack)) { -WRITE_UNLOCK (&ip_conntrack_lock); +READ_UNLOCK (&ip_conntrack_lock);return 0 ; }/* Should be unconfirmed, so not in hash table yet */
@@ -1109,7 +1109,6 @@ conntrack->helper =LIST_FIND (&helpers, helper_cmp, struct ip_conntrack_helper *, newreply); -WRITE_UNLOCK (&ip_conntrack_lock);return 1 ; }
Quoted 2 lines · Patrick McHardy
I've ported your conntrack patches to 2.6, I will include this change before adding them to CVS.
Thanks! Finally, finally I'm before a a big pom-ng (runme/Netfilter_POM.pm) update, stay tuned :-)
Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : KFKI Research Institute for Particle and Nuclear Physics
H-1525 Budapest 114, POB. 49, Hungary
Quoted 15 lines · Pablo Neira
Hi Patrick,
Quoted 11 lines · Patrick McHardy
Quoted 7 lines · Jozsef Kadlecsik
The assertion is right, because we alter unconfirmed packets when setting
up nat info. And you're also right, write-locking is unnecessary: the entry is not in the hash table yet, so nobody else can grab and modify the
conntrack entry. [And it is overlooked in the per bucket locking patch too.]
Quoted 5 lines
Quoted 2 lines
I've ported your conntrack patches to 2.6, I will include this change before adding them to CVS.
Attached the patch to fix this.
Isn't there a LOCK/UNLOCK imbalance in your patch?
Regards
Henrik
Hi,
Quoted 7 lines · Henrik Nordstrom
Quoted 3 lines
Attached the patch to fix this.
Isn't there a LOCK/UNLOCK imbalance in your patch?
you are right, I should rush... :-( Sorry!
regards,
Pablo
Index: net/ipv4/netfilter/ip_conntrack_core.c
===================================================================
RCS file: /home/cvs/linux-2.6/net/ipv4/netfilter/ip_conntrack_core.c,v retrieving revision 1.1.1.1
net/ipv4/netfilter/ip_conntrack_core.c +3 -3
@@ -1093,9 +1093,9 @@int ip_conntrack_alter_reply (struct ip_conntrack *conntrack,const struct ip_conntrack_tuple *newreply) { -WRITE_LOCK (&ip_conntrack_lock); +READ_LOCK (&ip_conntrack_lock);if (__ip_conntrack_find (newreply, conntrack)) { -WRITE_UNLOCK (&ip_conntrack_lock); +READ_UNLOCK (&ip_conntrack_lock);return 0 ; }/* Should be unconfirmed, so not in hash table yet */
@@ -1109,7 +1109,7 @@ conntrack->helper =LIST_FIND (&helpers, helper_cmp, struct ip_conntrack_helper *, newreply); -WRITE_UNLOCK (&ip_conntrack_lock); +READ_UNLOCK (&ip_conntrack_lock);return 1 ; }
Hi,
2004-05-03, h keltezéssel 11:05-kor Jozsef Kadlecsik ezt írta:
Quoted 19 lines
Quoted 19 lines
Well, actually I found a contradiction here, we write-locked the conntrack table but that assertion says that this conntrack is not confirmed, this implies that the conntrack is not in the hash table yet. If that assertion is right, we should replace that
write_lockfor aread_lockwhile calling__ip_conntrack_findand remove thatwrite_lockat the end of the function.int ip_conntrack_alter_reply(struct
ip_conntrack*conntrack,
const structip_conntrack_tuple*newreply){ WRITE_LOCK(&ip_conntrack_lock); if (__ip_conntrack_find(newreply, conntrack)) { WRITE_UNLOCK(&ip_conntrack_lock); return 0; } /* Should be unconfirmed, so not in hash table yet */ IP_NF_ASSERT(!is_confirmed(conntrack)); <--------------------------
Quoted 6 lines
Quoted 1 line
I'll study if that assertion is right before submitting a patch.
The assertion is right, because we alter unconfirmed packets when setting up nat info. And you're also right, write-locking is unnecessary: the entry is not in the hash table yet, so nobody else can grab and modify the conntrack entry. [And it is overlooked in the per bucket locking patch too.]
Why is the whole check necessary here? ip_conntrack_alter_reply() is
called by ip_nat_setup_info() to change the reply tuple of the conntrack. However, by assuring that there is no clashing conntrack entry at this time, we gain nothing. get_unique_tuple() tries to return such a tuple, and ip_conntrack_alter_reply() checks once more in vain: a new clashing conntrack entry can be created and confirmed before confirmation of this conntrack.
So I'd say this hash lookup should be removed completely.
Signature · 2 lines
Regards, Krisztian KOVACS