Skip to contentSkip to conversation

netfilter: x_tables: check for size overflow

PATCH Applied Florian Westphal 2 participants 2 messages Mar 10, 2016 – Mar 12, 2016

Subsystems (2)
lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 netfilter: x_tables: check for size overflow

Ben Hawkes says:
integer overflow in xt_alloc_table_info, which on 32-bit systems can lead to small structure allocation and a copy_from_user based heap corruption.

---
 net/netfilter/x_tables.c | 3 +++
 1 file changed, 3 insertions(+)
net/netfilter/x_tables.c +3 -0
index c8a0b7d..17a9a9f 100644
@@ -659,6 +659,9 @@ struct xt_table_info *xt_alloc_table_info(unsigned int size)
 	struct xt_table_info *info = NULL;
 	size_t sz = sizeof(*info) + size;
 
+	if (sz < size || sz < sizeof(*info))
+		return NULL;
+
 	/* Pedantry: prevent them from hitting BUG() in vmalloc.c --RR */
 	if ((SMP_ALIGN(size) >> PAGE_SHIFT) + 2 > totalram_pages)
 		return NULL;
Signature · 1 line
2.4.10
maintainer Applied
#1 lore raw
Quoted 4 lines · Florian Westphal

Ben Hawkes says:
integer overflow in xt_alloc_table_info, which on 32-bit systems can lead to small structure allocation and a copy_from_user based heap corruption.

Applied, thanks Florian. I have slightly mangled this patch, the second check suffices to catch this case for us.

Quoted 11 lines
---
 net/netfilter/x_tables.c | 3 +++
 1 file changed, 3 insertions(+)
net/netfilter/x_tables.c +0 -0
index c8a0b7d..17a9a9f 100644

net/netfilter/x_tables.c struct xt_table_info *xt_alloc_table_info(unsigned int size) · line 663

Quoted 5 lines
net/netfilter/x_tables.c +2 -0
@@ -659,6 +659,9 @@ struct xt_table_info *xt_alloc_table_info(unsigned int size)
 	struct xt_table_info *info = NULL;
 	size_t sz = sizeof(*info) + size;
 
+	if (sz < size || sz < sizeof(*info))
+		return NULL;

So this will show up in the tree like this:

        if (sz < sizeof(*info))
                return NULL;