netfilter ipt_conntrack/ipt_state moduse count
Subsystems (2)
PATCH 1/1 netfilter ipt_conntrack/ipt_state moduse count
Hi Dave!
Please apply the following fix to your 2.4.x tree. A 2.6.x fix is not needed, because of it's different reference counting.
Thanks.
--
- Harald Welte <[email protected]> http://www.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
net/ipv4/netfilter/ipt_conntrack.c +6 -1
@@ -109,10 +109,15 @@static int __init init (void ) { +int ret; +/* NULL if ip_conntrack not a module */ if (ip_conntrack_module)__MOD_INC_USE_COUNT (ip_conntrack_module); -return ipt_register_match (&conntrack_match); + ret =ipt_register_match (&conntrack_match); +if (ret) +__MOD_DEC_USE_COUNT (ip_conntrack_module); +return ret; } static void __exit fini(void)
net/ipv4/netfilter/ipt_state.c +6 -1
@@ -46,10 +46,15 @@static int __init init (void ) { +int ret; +/* NULL if ip_conntrack not a module */ if (ip_conntrack_module)__MOD_INC_USE_COUNT (ip_conntrack_module); -return ipt_register_match (&state_match); + ret =ipt_register_match (&state_match); +if (ret) +__MOD_DEC_USE_COUNT (ip_conntrack_module); +return ret; } static void __exit fini(void)
Quoted 4 lines · Harald Welte
Hi Dave!
Please apply the following fix to your 2.4.x tree. A 2.6.x fix is not needed, because of it's different reference counting.
Looks like the patch is buggy - it will oops in the failure path if ip_conntrack is not a module (it will call __MOD_DEC_USE_COUNT(NULL)).
Also, why this manual refcounting is needed here at all? ipt_conntrack.o and ipt_state.o have references at least to ip_conntrack_get(), which is exported by ip_conntrack.o. Because of this, there is no way to unload ip_conntrack without unloading ipt_conntrack and ipt_state first.
Other instances where ip_conntrack_module is used also don't seem to need it for the same reason.
Quoted 48 lines
Thanks.
--
- Harald Welte <[email protected]> http://www.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
diff -Nru --exclude-from /space/home/laforge/scripts/dontdiff --exclude .depend --exclude '*.o' --exclude '*.ko' --exclude '*.ver' --exclude '.*.flags' --exclude '*.orig' --exclude '*.rej' --exclude '*.cmd' --exclude '*.mod.c' --exclude '*~'linux-2.4.24/net/ipv4/netfilter/ipt_conntrack.clinux-2.4.24-usecount/net/ipv4/netfilter/ipt_conntrack.cnet/ipv4/netfilter/ipt_conntrack.c +6
-1@@ -109,10 +109,15 @@static int __init init (void ) { +int ret; +/* NULL if ip_conntrack not a module */ if (ip_conntrack_module)__MOD_INC_USE_COUNT (ip_conntrack_module); -return ipt_register_match (&conntrack_match); + ret =ipt_register_match (&conntrack_match); +if (ret) +__MOD_DEC_USE_COUNT (ip_conntrack_module); +return ret; } static void __exit fini(void)diff -Nru --exclude-from /space/home/laforge/scripts/dontdiff --exclude .depend --exclude '*.o' --exclude '*.ko' --exclude '*.ver' --exclude '.*.flags' --exclude '*.orig' --exclude '*.rej' --exclude '*.cmd' --exclude '*.mod.c' --exclude '*~'
linux-2.4.24/net/ipv4/netfilter/ipt_state.clinux-2.4.24-usecount/net/ipv4/netfilter/ipt_state.cnet/ipv4/netfilter/ipt_state.c +6
-1@@ -46,10 +46,15 @@static int __init init (void ) { +int ret; +/* NULL if ip_conntrack not a module */ if (ip_conntrack_module)__MOD_INC_USE_COUNT (ip_conntrack_module); -return ipt_register_match (&state_match); + ret =ipt_register_match (&state_match); +if (ret) +__MOD_DEC_USE_COUNT (ip_conntrack_module); +return ret; } static void __exit fini(void)
Cc'ing Rusty, he's the kernel modules expert ;)
Quoted 9 lines · Sergey Vlasov
Quoted 4 lines · Harald Welte
Hi Dave!
Please apply the following fix to your 2.4.x tree. A 2.6.x fix is not needed, because of it's different reference counting.
Looks like the patch is buggy - it will oops in the failure path if
ip_conntrackis not a module (it will call__MOD_DEC_USE_COUNT(NULL)).
mh, indeed. So the behaviour prior to the patch was buggy, after the patch it's still buggy, but in a different (even more obvious) way.
Quoted 5 lines
Also, why this manual refcounting is needed here at all? ipt_conntrack.o and ipt_state.o have references at least to
ip_conntrack_get(), which is exported by ip_conntrack.o. Because of this, there is no way to unloadip_conntrackwithout unloadingipt_conntrackandipt_statefirst.
That's a good question. I actually think this might have been introduced historically.
As you correctly indicate, there is no reason for explicit reference counting in all the cases where ip_conntrack_module is used:
ip_nat_standalone.c : is using conntrack functions anyway ipt_conntrack.c: calls ip_conntrack_get() ipt_helper.c: calls ip_conntrack_get() ipt_state.c: calls ip_conntrack_get()
I will prepare another patch that removes all refcounting, as you have suggested.
Rusty: Any idea why this was ever introduced in 2.4.x ? Am I missing something?
Signature · 5 lines
- Harald Welte <[email protected]> http://www.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
In message <[email protected]> you write:
Quoted 1 line
ip_nat_standalone.c: is using conntrack functions anyway
IIRC, this wasn't always the case, especially on UP (where the conntrack lock vanishes).
If it is the case now, we're OK.
Cheers,
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
Quoted 5 lines · Rusty Russell
In message <[email protected]> you write:
Quoted 1 line
ip_nat_standalone.c: is using conntrack functions anywayIIRC, this wasn't always the case, especially on UP (where the conntrack lock vanishes).
ip_conntrack_get() is now called from ip_nat_fn(). This should be sufficient.
Quoted 1 line
If it is the case now, we're OK.
Ok, I'm going to prepare a patch
Quoted 2 lines
Cheers,
Rusty.
Signature · 5 lines
- Harald Welte <[email protected]> http://www.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