aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv6
diff options
context:
space:
mode:
authorDave Jones <davej@codemonkey.org.uk>2015-05-19 20:55:17 -0400
committerPablo Neira Ayuso <pablo@netfilter.org>2015-05-20 07:46:49 -0400
commit1086bbe97a074844188c6c988fa0b1a98c3ccbb9 (patch)
treec4b90cdf9b27072391ec62aa06408e1a57baed1e /net/ipv6
parent3bfe049807c240344b407e3cfb74544927359817 (diff)
netfilter: ensure number of counters is >0 in do_replace()
After improving setsockopt() coverage in trinity, I started triggering vmalloc failures pretty reliably from this code path: warn_alloc_failed+0xe9/0x140 __vmalloc_node_range+0x1be/0x270 vzalloc+0x4b/0x50 __do_replace+0x52/0x260 [ip_tables] do_ipt_set_ctl+0x15d/0x1d0 [ip_tables] nf_setsockopt+0x65/0x90 ip_setsockopt+0x61/0xa0 raw_setsockopt+0x16/0x60 sock_common_setsockopt+0x14/0x20 SyS_setsockopt+0x71/0xd0 It turns out we don't validate that the num_counters field in the struct we pass in from userspace is initialized. The same problem also exists in ebtables, arptables, ipv6, and the compat variants. Signed-off-by: Dave Jones <davej@codemonkey.org.uk> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'net/ipv6')
-rw-r--r--net/ipv6/netfilter/ip6_tables.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
index 1a732a1d3c8e..62f5b0d0bc9b 100644
--- a/net/ipv6/netfilter/ip6_tables.c
+++ b/net/ipv6/netfilter/ip6_tables.c
@@ -1275,6 +1275,9 @@ do_replace(struct net *net, const void __user *user, unsigned int len)
1275 /* overflow check */ 1275 /* overflow check */
1276 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters)) 1276 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
1277 return -ENOMEM; 1277 return -ENOMEM;
1278 if (tmp.num_counters == 0)
1279 return -EINVAL;
1280
1278 tmp.name[sizeof(tmp.name)-1] = 0; 1281 tmp.name[sizeof(tmp.name)-1] = 0;
1279 1282
1280 newinfo = xt_alloc_table_info(tmp.size); 1283 newinfo = xt_alloc_table_info(tmp.size);
@@ -1822,6 +1825,9 @@ compat_do_replace(struct net *net, void __user *user, unsigned int len)
1822 return -ENOMEM; 1825 return -ENOMEM;
1823 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters)) 1826 if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
1824 return -ENOMEM; 1827 return -ENOMEM;
1828 if (tmp.num_counters == 0)
1829 return -EINVAL;
1830
1825 tmp.name[sizeof(tmp.name)-1] = 0; 1831 tmp.name[sizeof(tmp.name)-1] = 0;
1826 1832
1827 newinfo = xt_alloc_table_info(tmp.size); 1833 newinfo = xt_alloc_table_info(tmp.size);