netfilter: x_tables: check for size overflow
Subsystems (2)
Florian Westphal
maintainerPATCH 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.
Reported-by Ben Hawkes <[email protected]>
Signed-off-by Florian Westphal <[email protected]>
--- net/netfilter/x_tables.c | 3 +++ 1 file changed, 3 insertions(+)
net/netfilter/x_tables.c +3 -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 ; +/* 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
Quoted 4 lines · Florian Westphal
Ben Hawkes says:
integer overflow inxt_alloc_table_info, which on 32-bit systems can lead to small structure allocation and acopy_from_userbased heap corruption.
Applied, thanks Florian. I have slightly mangled this patch, the second check suffices to catch this case for us.
Quoted 11 lines
Reported-by Ben Hawkes <[email protected]>Signed-off-by Florian Westphal <[email protected]>--- net/netfilter/x_tables.c | 3 +++ 1 file changed, 3 insertions(+)net/netfilter/x_tables.c +0
-0
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;