netfilter: x_tables: make allocation less aggressive

"Linux Kernel Mailing List" <[email protected]>
Newsgroups gmane.linux.kernel.commits.head
Message-ID <[email protected]>
Web:        https://git.kernel.org/torvalds/c/0537250fdc6c876ed4cbbe874c739aebef493ee2
Commit:     0537250fdc6c876ed4cbbe874c739aebef493ee2
Parent:     743ffffefac1c670c6618742c923f6275d819604
Refname:    refs/heads/master
Author:     Michal Hocko <[email protected]>
AuthorDate: Tue Jan 30 11:30:11 2018 -0800
Committer:  Pablo Neira Ayuso <[email protected]>
CommitDate: Fri Feb 2 12:45:16 2018 +0100

    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.  eacd86ca3b03 ("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.
    
    [[email protected]: coding-style fixes]
    Fixes: eacd86ca3b03 ("net/netfilter/x_tables.c: use kvmalloc() in xt_alloc_tableLink: http://lkml.kernel.org/r/[email protected]
    Signed-off-by: Michal Hocko <[email protected]>
    Acked-by: Florian Westphal <[email protected]>
    Reviewed-by: Andrew Morton <[email protected]>
    Cc: David S. Miller <[email protected]>
    Signed-off-by: Andrew Morton <[email protected]>
    Signed-off-by: Pablo Neira Ayuso <[email protected]>
---
 net/netfilter/x_tables.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
index 8fa4d37141a7..2f685ee1f9c8 100644
--- a/net/netfilter/x_tables.c
+++ b/net/netfilter/x_tables.c
@@ -1008,7 +1008,12 @@ struct xt_table_info *xt_alloc_table_info(unsigned int size)
 	if ((size >> PAGE_SHIFT) + 2 > totalram_pages)
 		return NULL;
 
-	info = kvmalloc(sz, GFP_KERNEL);
+	/* __GFP_NORETRY is not fully supported by kvmalloc but it should
+	 * work reasonably well if sz is too large and bail out rather
+	 * than shoot all processes down before realizing there is nothing
+	 * more to reclaim.
+	 */
+	info = kvmalloc(sz, GFP_KERNEL | __GFP_NORETRY);
 	if (!info)
 		return NULL;
 
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.