Received: by 10.213.65.68 with SMTP id h4csp690626imn; Fri, 6 Apr 2018 07:21:22 -0700 (PDT) X-Google-Smtp-Source: AIpwx49nMVmGSFnHYKMvti4/FjUzY7W791fTbSlCHD372mxlyinVMn0xcVWI+FznsDVimLLob4M9 X-Received: by 2002:a17:902:c24:: with SMTP id 33-v6mr28052965pls.88.1523024482126; Fri, 06 Apr 2018 07:21:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523024482; cv=none; d=google.com; s=arc-20160816; b=0NvVhdsW6cqlJqAeo4h39Ipl2LJnzOeveSgoIOiocG9ueBlrxWxXrluDV2Y8enA1at 4KjW7SUiZnEM4PE24k3f2c/Dampb5tAhiaX2z2PNrOzrxkDFGv7iGXSiuXMhEt0LfD72 3HRAHe6MOj2hCvFXud0xZrvsQtcfT4ILDoBOxUF+dAM2wsGFE4H7FzFyPaVfKcpVR7Xi 23D11yYQU/e0+tHQ2wNAycEjG5JMTtlDkJxml9r1HdIDqJQF4s+S+H1d3zWrXfjAF71i Y3aEQOHLbH9LdZNWDJhKY+NtQ48aWD+k0z0KeRulPqWZ6/gChaBP4zKSu9QOKzlSVnT3 uCwQ== 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=oOC6WEuBus3gtfHar1njFnKUtdhkgOxjRerNVlt0OGg=; b=z4k8V1qUczRf3DK7bXFucbAlheU4NQPi+Jb3/NcAEe2Ah11PKKfGIu7EOdEIH8I12U b5bOcuhywZ44cQEfzPGL/DxWKimAIuMkT1fbG7gAypaAIS3JP75hQoyBSUhlb+npG/Ag ALWUy0XuBXIetGCFT4q9J0Cm8rN9UTKus5zq8OgROz2eDxELiMMP0T/1VBaiY+uKfaZP KV/Eyf71rL+spl4pqUbzU+ZI3dktTk2FUOgkO7ioHj9SpNr9Sl75Z1PrvunQ7RlaT1no kf9uKl95zO44q7e3wejVrWNfKZnoLQZNSV4p0gdTjlZ0U3oBTgigD4VqviYl7qJJJafM 4LPQ== 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 s16-v6si8019786plp.113.2018.04.06.07.21.08; Fri, 06 Apr 2018 07:21:22 -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 S932463AbeDFNid (ORCPT + 99 others); Fri, 6 Apr 2018 09:38:33 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:33346 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932436AbeDFNi3 (ORCPT ); Fri, 6 Apr 2018 09:38:29 -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 1007EBB6; Fri, 6 Apr 2018 13:38:28 +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.14 29/67] netfilter: x_tables: make allocation less aggressive Date: Fri, 6 Apr 2018 15:23:59 +0200 Message-Id: <20180406084345.147965221@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180406084341.225558262@linuxfoundation.org> References: <20180406084341.225558262@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.14-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;