Fix locking in ip_conntrack_change_expect()
Subsystems (2)
PATCH 1/1 Fix locking in ip_conntrack_change_expect()
Hi again, Dave!
Below is an important bugfix for netfilter (by Martin Josefsson).
In ip_conntrack_change_expect() we were at least need to grab a readlock before comparing the tuple/mask of an ip_conntrack_expect.
Pleae note that the bug was introduced in early 2.4.20-pre time, as newnat was merged. So there's no need to worry about old (stable) kernel releases.
Please apply the following fix, Thanks.
- Harald
net/ipv4/netfilter/ip_conntrack_core.c renamed from net/ipv4/netfilter/ip_conntrack_core.c.mjufs +9 -7
@@ -1060,7 +1060,10 @@int ip_conntrack_change_expect (struct ip_conntrack_expect *expect,struct ip_conntrack_tuple *newtuple) { +int ret; +MUST_BE_READ_LOCKED (&ip_conntrack_lock); +WRITE_LOCK (&ip_conntrack_expect_tuple_lock);DEBUGP ("change_expect:\n" );DEBUGP ("exp tuple: " );DUMP_TUPLE (&expect->tuple);
@@ -1073,26 +1076,25 @@ && LIST_FIND(&ip_conntrack_expect_list, expect_clash, struct ip_conntrack_expect *, newtuple, &expect->mask)) { /* Force NAT to find an unused tuple */ - return -1; + ret = -1; } else { -WRITE_LOCK (&ip_conntrack_expect_tuple_lock);memcpy (&expect->ct_tuple, &expect->tuple,sizeof (expect->tuple));memcpy (&expect->tuple, newtuple,sizeof (expect->tuple)); -WRITE_UNLOCK (&ip_conntrack_expect_tuple_lock); -return 0 ; + ret =0 ; } }else {/* Resent packet */ DEBUGP ("change expect: resent packet\n" );if (ip_ct_tuple_equal (&expect->tuple, newtuple)) { -return 0 ; + ret =0 ; }else {/* Force NAT to choose again the same port */ -return -1 ; + ret =-1 ; } } +WRITE_UNLOCK (&ip_conntrack_expect_tuple_lock); -return -1 ; +return ret; }/* Alter reply tuple (maybe alter helper). If it's already taken,
Signature · 5 lines
Live long and prosper - Harald Welte / [email protected] http://www.gnumonks.org/ ============================================================================ "If this were a dictatorship, it'd be a heck of a lot easier, just so long as I'm the dictator." -- George W. Bush Dec 18, 2000
David S. Miller
Applied From: Harald Welte <[email protected]>
Date: Mon, 14 Oct 2002 13:40:47 +0200
Pleae note that the bug was introduced in early 2.4.20-pre time, as newnat was merged. So there's no need to worry about old (stable) kernel releases.
Please apply the following fix, Thanks.
Applied.
I guess this means I really should push this stuff in for 2.4.20-preX
Quoted 4 lines · David Miller
Applied.
I guess this means I really should push this stuff in for 2.4.20-preX
yes, this is the only one which should be submitted before 2.4.20-final.
Thanks.
Signature · 5 lines
Live long and prosper - Harald Welte / [email protected] http://www.gnumonks.org/ ============================================================================ "If this were a dictatorship, it'd be a heck of a lot easier, just so long as I'm the dictator." -- George W. Bush Dec 18, 2000
From: Harald Welte <[email protected]>
Date: Mon, 14 Oct 2002 16:03:09 +0200
Quoted 2 lines · David Miller
I guess this means I really should push this stuff in for 2.4.20-preX
yes, this is the only one which should be submitted before 2.4.20-final.
There were two locking fixes Harald :-)
What I want to push to Marcelo is:
1) Avoid nesting readlocks in conntrack
2) Fix ip_conntrack_change_expect locking
3) Display ipv6 SIT encapsulation properly
Ok?
Quoted 11 lines · David Miller
From: Harald Welte <[email protected]>
Date: Mon, 14 Oct 2002 16:03:09 +0200Quoted 2 lines · David Miller
I guess this means I really should push this stuff in for 2.4.20-preX
yes, this is the only one which should be submitted before 2.4.20-final.
There were two locking fixes Harald :-)
Well, according to my definition of a locking fix (for a locking bug) there only was one. Having a nested readlock is not a locking bug. It was just the debug statements.
Anyway, it's not worth discussing this further.
Quoted 7 lines
What I want to push to Marcelo is:
1) Avoid nesting readlocks in conntrack
2) Fixip_conntrack_change_expectlocking
3) Display ipv6 SIT encapsulation properlyOk?
Perfect, thanks. The only harmful bug is number 2.
Signature · 5 lines
Live long and prosper - Harald Welte / [email protected] http://www.gnumonks.org/ ============================================================================ "If this were a dictatorship, it'd be a heck of a lot easier, just so long as I'm the dictator." -- George W. Bush Dec 18, 2000