Skip to content

Commit 0537250

Browse files
Michal Hockoummakynes
authored andcommitted
netfilter: x_tables: make allocation less aggressive
syzbot has noticed that xt_alloc_table_info can allocate a lot of memory. This is an admin only interface but an admin in a namespace is sufficient as well. eacd86c ("net/netfilter/x_tables.c: use kvmalloc() in xt_alloc_table_info()") has changed the opencoded kmalloc->vmalloc fallback into kvmalloc. It has dropped __GFP_NORETRY on the way because vmalloc has simply never fully supported __GFP_NORETRY semantic. This is still the case because e.g. page tables backing the vmalloc area are hardcoded GFP_KERNEL. Revert back to __GFP_NORETRY as a poors man defence against excessively large allocation request here. We will not rule out the OOM killer completely but __GFP_NORETRY should at least stop the large request in most cases. [akpm@linux-foundation.org: coding-style fixes] Fixes: eacd86c ("net/netfilter/x_tables.c: use kvmalloc() in xt_alloc_tableLink: http://lkml.kernel.org/r/20180130140104.GE21609@dhcp22.suse.cz Signed-off-by: Michal Hocko <mhocko@suse.com> Acked-by: Florian Westphal <fw@strlen.de> Reviewed-by: Andrew Morton <akpm@linux-foundation.org> Cc: David S. Miller <davem@davemloft.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 743ffff commit 0537250

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎net/netfilter/x_tables.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,12 @@ struct xt_table_info *xt_alloc_table_info(unsigned int size)
10081008
if ((size >> PAGE_SHIFT) + 2 > totalram_pages)
10091009
return NULL;
10101010

1011-
info = kvmalloc(sz, GFP_KERNEL);
1011+
/* __GFP_NORETRY is not fully supported by kvmalloc but it should
1012+
* work reasonably well if sz is too large and bail out rather
1013+
* than shoot all processes down before realizing there is nothing
1014+
* more to reclaim.
1015+
*/
1016+
info = kvmalloc(sz, GFP_KERNEL | __GFP_NORETRY);
10121017
if (!info)
10131018
return NULL;
10141019

0 commit comments

Comments
 (0)