netfilter connection tracking TIMEOUT issue
Hi,
I have run into the timeout issue related to the connection tracking entry several times. The fact that those connection tracking entries
just stay in the connection tracking table and take effect due to the default timeout values (for example, TCP_CONNTRACK_ESTABLISHED is 5 DAYS) could compromise the security or put network connection into the wrong state.
For instance, I can implement "Virtual Servers" using DNAT such as
iptables -t nat -A PREROUTING -i ppp0 -p tcp --dport 22 -j DNAT --to 192.168.1.5
to create a virtual ssh server behind my Linux gateway.
However, when a ssh connection is established from the remove to the ssh server,
the TCP connection tracking entry will be created in ESTABLISHED status with timeout set to 5 DAYS. So even I realized I made a mistake to allow this kind
of SSH virtual server and deleted the iptables rule, due to the 5 DAYS timeout, the remote can still connect to the ssh server within 5 DAYS unless I
rebooted the gateway or reloaded ip_conntrack module!!!
I don't know how netfilter designers come up with these TIMEOUT values. I searched
the mailing list before and there were arguments about it.
I don't want to argue about these values. But I think we should come up with a method that when we delete an iptables rule, at least we can easily elect to
delete related connection tracking entries in the connection tracking table.
Do we have an easy way to delete specified entries in the connection tracking table
without writing a kernel module? The only way I know to access connection tracking table
from the user space is "cat /proc/net/ip_conntrack".
Thanks in advance.
-Song
Quoted 3 lines · Song Wang
of SSH virtual server and deleted the iptables rule, due to the 5 DAYS timeout, the remote can still connect to the ssh server within 5 DAYS unless I rebooted the gateway or reloaded
ip_conntrackmodule!!!
Not quite.. his already established SSH session will be allowed to last for ever (or until idle for 5 days with no packets exchanged), but no new SSH sessions will/should be allowed.
Also, this is obviously subject to your ruleset. Only if you accept ESTABLISHED sessions without any kind of verification of the session then you are at risk of running into this kind of issues.
Quoted 2 lines
I don't know how netfilter designers come up with these TIMEOUT values. I searched the mailing list before and there were arguments about it.
By the design of TCP.
ESTABLISHED needs a very long timeout due to the fact that there might not be any packets exchanged for a very long time if there is no data to be exchanged between the two endpoints.
All these timeouts is related to is the connection tracking of sessions.
It is your firewall rules which accepts/denies packets. Your firewall rules can use connection tracking information, but should not do so blindly.
Quoted 4 lines
I don't want to argue about these values. But I think we should come up with a method that when we delete an iptables rule, at least we can easily elect to delete related connection tracking entries in the connection tracking table.
See ctnetlink.
You can also look into the CONFIRMED patch submitted by one of my collegues some months ago (meant to be used together with the conntrack match). But the scheme used by CONFIRMED is not yet fully polished.
Regards
Henrik