netfilter: xt_recent: don't reject rule if new hitcount exceeds table max
Subsystems (2)
Florian Westphal
maintainerPATCH 1/1 netfilter: xt_recent: don't reject rule if new hitcount exceeds table max
given:
-A INPUT -m recent --update --seconds 30 --hitcount 4 and
iptables-save > foo
then
iptables-restore < foo
will fail with:
kernel: xt_recent: hitcount (4) is larger than packets to be remembered (4) for table DEFAULT
Even when the check is fixed, the restore won't work if the hitcount is increased to e.g. 6, since by the time checkentry runs it will find the 'old' incarnation of the table.
We can avoid this by increasing the maximum threshold silently; we only have to rm all the current entries of the table (these entries would not have enough room to handle the increased hitcount).
This even makes (not-very-useful)
-A INPUT -m recent --update --seconds 30 --hitcount 4 -A INPUT -m recent --update --seconds 30 --hitcount 42 work.
--- net/netfilter/xt_recent.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
net/netfilter/xt_recent.c +5 -6
@@ -378,12 +378,11 @@ static int recent_mt_check(const struct xt_mtchk_param *par,mutex_lock (&recent_mutex); t =recent_table_lookup (recent_net, info->name);if (t !=NULL ) { -if (info->hit_count > t->nstamps_max_mask) { -pr_info ("hitcount (%u) is larger than packets to be remembered (%u) for table %s\n" , - info->hit_count, t->nstamps_max_mask +1 , - info->name); - ret = -EINVAL ; - goto out; +if (nstamp_mask > t->nstamps_max_mask) { +spin_lock_bh (&recent_lock); +recent_table_flush (t); + t->nstamps_max_mask = nstamp_mask; +spin_unlock_bh (&recent_lock); } t->refcnt++;
Signature · 1 line
2.0.5
Quoted 22 lines · Florian Westphal
given:
-A INPUT -m recent --update --seconds 30 --hitcount 4 and
iptables-save > foothen
iptables-restore < foowill fail with:
kernel:xt_recent: hitcount (4) is larger than packets to be remembered (4) for table DEFAULTEven when the check is fixed, the restore won't work if the hitcount is increased to e.g. 6, since by the time checkentry runs it will find the 'old' incarnation of the table.
We can avoid this by increasing the maximum threshold silently; we only have to rm all the current entries of the table (these entries would not have enough room to handle the increased hitcount).
This even makes (not-very-useful)
(quoted diff) +0
-2-A INPUT -m recent --update --seconds 30 --hitcount 4 -A INPUT -m recent --update --seconds 30 --hitcount 42
Quoted 1 line
work.
Applied, thanks Florian.