login
Header Space

 
 

[PATCH] netfilter: ipt_recent: sanity check hit count

Previous thread: 2.6.24 Kernel freeze by Jacek Luczak on Saturday, March 15, 2008 - 9:56 am. (1 message)

Next thread: initramfs - unable to boot livcd from usb-cdrom devices (bug) by depaolis.salvatore@libero.it on Saturday, March 15, 2008 - 10:14 am. (1 message)
To: <linux-kernel@...>
Cc: <netfilter-devel@...>, <kaber@...>, <akpm@...>, <skennedy@...>, <daniel@...>
Date: Saturday, March 15, 2008 - 9:49 am

If a rule using ipt_recent is created with a hit count greater than
ip_pkt_list_tot, the rule will never match as it cannot keep track
of enough timestamps. This patch makes ipt_recent refuse to create such
rules.

With ip_pkt_list_tot's default value of 20, the following can be used
to reproduce the problem.

nc -u -l 0.0.0.0 1234 &amp;
for i in `seq 1 100`; do echo $i | nc -w 1 -u 127.0.0.1 1234; done

This limits it to 20 packets:
iptables -A OUTPUT -p udp --dport 1234 -m recent --set --name test \
         --rsource
iptables -A OUTPUT -p udp --dport 1234 -m recent --update --seconds \
         60 --hitcount 20 --name test --rsource -j DROP

While this is unlimited:
iptables -A OUTPUT -p udp --dport 1234 -m recent --set --name test \
         --rsource
iptables -A OUTPUT -p udp --dport 1234 -m recent --update --seconds \
         60 --hitcount 21 --name test --rsource -j DROP

With the patch the second rule-set will throw an EINVAL.

Signed-off-by: Daniel Hokka Zakrisson &lt;daniel@hozac.com&gt;
Reported-by: Sean Kennedy &lt;skennedy@vcn.com&gt;
---
 net/ipv4/netfilter/ipt_recent.c |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/ipv4/netfilter/ipt_recent.c
b/net/ipv4/netfilter/ipt_recent.c
index 68cbe3c..8e8f042 100644
--- a/net/ipv4/netfilter/ipt_recent.c
+++ b/net/ipv4/netfilter/ipt_recent.c
@@ -252,6 +252,8 @@ recent_mt_check(const char *tablename, const void *ip,
 	if ((info-&gt;check_set &amp; (IPT_RECENT_SET | IPT_RECENT_REMOVE)) &amp;&amp;
 	    (info-&gt;seconds || info-&gt;hit_count))
 		return false;
+	if (info-&gt;hit_count &gt; ip_pkt_list_tot)
+		return false;
 	if (info-&gt;name[0] == '\0' ||
 	    strnlen(info-&gt;name, IPT_RECENT_NAME_LEN) == IPT_RECENT_NAME_LEN)
 		return false;
-- 
1.5.3.3
--
To: Daniel Hokka Zakrisson <daniel@...>
Cc: <linux-kernel@...>, <netfilter-devel@...>, <akpm@...>, <skennedy@...>
Date: Monday, March 17, 2008 - 9:55 am

Applied, thanks.
--
Previous thread: 2.6.24 Kernel freeze by Jacek Luczak on Saturday, March 15, 2008 - 9:56 am. (1 message)

Next thread: initramfs - unable to boot livcd from usb-cdrom devices (bug) by depaolis.salvatore@libero.it on Saturday, March 15, 2008 - 10:14 am. (1 message)
speck-geostationary