possible race in init_conntrack()?
Hi devel,
please have a look at init_conntrack(), in ip_conntrack_core.c.
static unsigned int drop_next = 0; ... if (drop_next >= ip_conntrack_htable_size) drop_next = 0; if (!early_drop(&ip_conntrack_hash[drop_next++])
I see no locking around drop_next. init_conntrack() is entered from ip_conntrack_in(), and that can run on two CPUs at the same time, right? Then the following story seems possible (though very unlikely):
Let drop_next be ip_conntrack_htable_size-1.
CPU0 does the bounds check, it passes.
CPU1 does the bounds check, it passes.
CPU0 writes back the incremented value.
CPU1 for whatever reason, CPU1 rereads the incremented value, and happily accesses ip_conntrack_hash[ip_conntrack_htable_size].
Boom (very faint, very low frequency, but Boom).
Did I overlook something? Making drop_next atomic_t should be a good fix.
best regards
Patrick
Quoted 21 lines · Patrick Schaaf
please have a look at
init_conntrack(), inip_conntrack_core.c.static unsigned int drop_next = 0; ... if (drop_next >= ip_conntrack_htable_size) drop_next = 0; if (!early_drop(&ip_conntrack_hash[drop_next++])I see no locking around
drop_next.init_conntrack()is entered fromip_conntrack_in(), and that can run on two CPUs at the same time, right? Then the following story seems possible (though very unlikely):Let
drop_nextbe ip_conntrack_htable_size-1.
CPU0 does the bounds check, it passes.
CPU1 does the bounds check, it passes.
CPU0 writes back the incremented value.
CPU1 for whatever reason, CPU1 rereads the incremented value, and happily accesses ip_conntrack_hash[ip_conntrack_htable_size].
Boom (very faint, very low frequency, but Boom).
Quoted 1 line
Did I overlook something? Making
drop_nextatomic_tshould be a good fix.
Yes, it seems a (rarely occuring) race condition.
Unfortunately the code segment is not perfect from other reason as well:
it can quite easily happen, that we do not find unreplied connection neither in the current nor in the random chain when we have a couple of them in other chains. :-(
Regards,
Jozsef
-
E-mail : [email protected], [email protected]
WWW-Home: http://www.kfki.hu/~kadlec
Address : KFKI Research Institute for Particle and Nuclear Physics
H-1525 Budapest 114, POB. 49, Hungary
Quoted 2 lines · Patrick Schaaf
Hi devel,
Did I overlook something? Makingdrop_nextatomic_tshould be a good fix.
no, you didn't. I'm not going to submit a patch for this, since we've never had a single bug report and it is very theoretic [whatever reason has to become true], and we are currently redesigning the conntrack hash anyway.... so I'd expect the new conntrack hash code including the limit-number-of-entries-per-chain code to fix this issue as well :)
Quoted 2 lines
best regards
Patrick
Signature · 5 lines
Live long and prosper - Harald Welte / [email protected] http://www.gnumonks.org/ ============================================================================ GCS/E/IT d- s-: a-- C+++ UL++++$ P+++ L++++$ E--- W- N++ o? K- w--- O- M- V-- PS+ PE-- Y+ PGP++ t++ 5-- !X !R tv-- b+++ DI? !D G+ e* h+ r% y+(*)