Received: by 10.213.65.68 with SMTP id h4csp671279imn; Fri, 6 Apr 2018 07:05:13 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/xqXFGze1YkPqLWcYTDduPK6kxgKgJcS2a33XnrTKVHuiNEenVPZnKDu3F/tfM7p8x70/7 X-Received: by 10.99.127.83 with SMTP id p19mr4611423pgn.161.1523023513728; Fri, 06 Apr 2018 07:05:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523023513; cv=none; d=google.com; s=arc-20160816; b=FwjvwzrxbHm13XvbVrjgwqmlERvZv7vHtxx6/P76LH9ZUD5FYbdwuhWspzDIHZSCrW 1nzU9odBOV9V4XE6VczG21IiwQE1UVSv+YNbW83/Cvf2ABp4/35I3/oSS5obyhIZK45h FHKmC6pD5S2RK+v7OutLUvsk3IS9XXYeAdIOLLg2kX7DGTXW9bwOmIeKIaxF9fbt555I oOHNfgVtPb8AYgg0VXx2LXdVH6AS2inU2V9YVon3ElxqIrCmmDVUu9tOMrfsKUkztnPA aqRzZ8TIB6x+XYe2a2uUQrswGwNj9Hc4gGn+fwQPnAVQGXC9Yb7Cktkt2NL7rnXcOGtZ Ds9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=xLMXAwnc+FfHhvxShpU/FBWyAIJuoga6REeqBwjf48M=; b=GzYkIhyQQxMW1JqdNj5mSbu7j1gkW87DCMPEixUA3APcOYIZF1LgCT3UPa4sjTOiw4 XKzB2wMPacmah3K9DJzry96osGUVPNqVlBQyoSRosTJziedv5wIfiuBjS13OgIfc8CTN DeHAVJu0UZw56mdwpLCw2c+qVWEe33stH1r5CP/RT0TXuFgWVsISvWU9LjNiKRsKURuk x+4hmKhVDZjAj1hdg8KfajIn4bmZGbDHHU2r1Y7SZ3Q/QzePHRi+kag72qk92DUmakTu 8yJrkh/6CeSlairWFgWBl7doGbX789pPzThDrtzAcEgLImDbwVC+z1M3Wl2VbwnKRGWM YAxQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a17si7160007pgn.429.2018.04.06.07.04.59; Fri, 06 Apr 2018 07:05:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756589AbeDFODV (ORCPT + 99 others); Fri, 6 Apr 2018 10:03:21 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:36646 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756476AbeDFNlx (ORCPT ); Fri, 6 Apr 2018 09:41:53 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 6A519D02; Fri, 6 Apr 2018 13:41:52 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michal Hocko , Florian Westphal , Andrew Morton , "David S. Miller" , Pablo Neira Ayuso Subject: [PATCH 4.15 32/72] netfilter: x_tables: make allocation less aggressive Date: Fri, 6 Apr 2018 15:24:07 +0200 Message-Id: <20180406084352.045366378@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180406084349.367583460@linuxfoundation.org> References: <20180406084349.367583460@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Michal Hocko commit 0537250fdc6c876ed4cbbe874c739aebef493ee2 upstream. 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. [akpm@linux-foundation.org: coding-style fixes] Fixes: eacd86ca3b03 ("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 Acked-by: Florian Westphal Reviewed-by: Andrew Morton Cc: David S. Miller Signed-off-by: Andrew Morton Signed-off-by: Pablo Neira Ayuso Signed-off-by: Greg Kroah-Hartman --- net/netfilter/x_tables.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/net/netfilter/x_tables.c +++ b/net/netfilter/x_tables.c @@ -1008,7 +1008,12 @@ struct xt_table_info *xt_alloc_table_inf 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;