Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6276922imu; Mon, 21 Jan 2019 06:15:17 -0800 (PST) X-Google-Smtp-Source: ALg8bN6gW9boTikC2k1UgUFMlIdE463+nbYZEonMGamAo4LLSszw+ezSPvWb/ft1SODp3es/M1rF X-Received: by 2002:a65:6542:: with SMTP id a2mr27966304pgw.389.1548080117495; Mon, 21 Jan 2019 06:15:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548080117; cv=none; d=google.com; s=arc-20160816; b=LXCtsOUsZcm62TQNbFfvvHYvX51/jYIkujWqtXwnJzlBDz3sHFi2e1m6AAdr/pbPaa /SjQPScGy0hHGGDZfR99d5AyGoy8hOlEzYm0uQF32BVSGFeDOUDeqF4zHXFMb3WTD0Rv djWigC4JfGBCfeT/PInFUsTFebCsPpVMeRX/SXD4nu33ogPztGzO3cTuszwz1Iy2i9H7 3aHaTy9VT3r/9TrsJg7jOdMoBbdR7RMjPni/F8l5Hfb72vE2aGWscoR9JgPr333XWfr+ +xJH33p3CAqGNT0fHeKEE6CAT+meSEroruXLJdxaPk0jyNasrnMKLsczeAYd85j6ttQY othA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=14/ZWU8NzHbC37US4NQjUNriA6Et6zIENms8vuA5DYE=; b=aUrT454388H+h7sSwOjWi7/dr24XzOc7WFf8x34PwXfqjB7zL1iLNRfqVSJ6h8Wzix VjMTugD3UFtQsOpgbqiVCfrezKagkBWrr2n6kbXY2zoo99XQMfpxAnmcZ+AguHWwRori L/c7YRPR+KdmMjcfz8ty+y7CG5XaGMV5f8JCFC3/TviLBiMFazqj0OxqpGkHxI+tGoY0 I0GyC3BXNjsxv6ksxaLbWSd/9TsBCHyscJRou4KrjDDg+bap1bc7ZPM2wRY2e+IGD9FE Gy8HsyCocYAOndsNL2/+hg50QPgC6qAj9kVt2jh2gI6z6JeP9Mv626MOje+QEptl+2gt nexQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YD1I2xs7; 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 g21si11926496pgl.114.2019.01.21.06.15.00; Mon, 21 Jan 2019 06:15:17 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=YD1I2xs7; 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 S1731387AbfAUONb (ORCPT + 99 others); Mon, 21 Jan 2019 09:13:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:36634 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731210AbfAUNxJ (ORCPT ); Mon, 21 Jan 2019 08:53:09 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 67A832084C; Mon, 21 Jan 2019 13:53:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548078788; bh=1+BFqj1sSDBTArY6qFPtlJvloXZ/7/X1lLWe8fzCtpQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YD1I2xs7/ARN764o+qOznQprWzqoA94RKT2lwmzWQOHSVo2w9TOTmeZT2XBkeARD2 VONWTb0K2FrSm38nKJrKp1fsp8rd4Sh12762VCLPR660v3J1tIU7Y86BTeDO1RBJP8 kU+NOn/fcf6ogc30rDQkEfvqvroxygm5xoGHJ89E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+7713f3aa67be76b1552c@syzkaller.appspotmail.com, Shakeel Butt , Kirill Tkhai , Pablo Neira Ayuso Subject: [PATCH 4.14 44/59] netfilter: ebtables: account ebt_table_info to kmemcg Date: Mon, 21 Jan 2019 14:44:09 +0100 Message-Id: <20190121122501.692716433@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190121122456.529172919@linuxfoundation.org> References: <20190121122456.529172919@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: Shakeel Butt commit e2c8d550a973bb34fc28bc8d0ec996f84562fb8a upstream. The [ip,ip6,arp]_tables use x_tables_info internally and the underlying memory is already accounted to kmemcg. Do the same for ebtables. The syzbot, by using setsockopt(EBT_SO_SET_ENTRIES), was able to OOM the whole system from a restricted memcg, a potential DoS. By accounting the ebt_table_info, the memory used for ebt_table_info can be contained within the memcg of the allocating process. However the lifetime of ebt_table_info is independent of the allocating process and is tied to the network namespace. So, the oom-killer will not be able to relieve the memory pressure due to ebt_table_info memory. The memory for ebt_table_info is allocated through vmalloc. Currently vmalloc does not handle the oom-killed allocating process correctly and one large allocation can bypass memcg limit enforcement. So, with this patch, at least the small allocations will be contained. For large allocations, we need to fix vmalloc. Reported-by: syzbot+7713f3aa67be76b1552c@syzkaller.appspotmail.com Signed-off-by: Shakeel Butt Reviewed-by: Kirill Tkhai Signed-off-by: Pablo Neira Ayuso Signed-off-by: Greg Kroah-Hartman --- net/bridge/netfilter/ebtables.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/net/bridge/netfilter/ebtables.c +++ b/net/bridge/netfilter/ebtables.c @@ -1134,14 +1134,16 @@ static int do_replace(struct net *net, c tmp.name[sizeof(tmp.name) - 1] = 0; countersize = COUNTER_OFFSET(tmp.nentries) * nr_cpu_ids; - newinfo = vmalloc(sizeof(*newinfo) + countersize); + newinfo = __vmalloc(sizeof(*newinfo) + countersize, GFP_KERNEL_ACCOUNT, + PAGE_KERNEL); if (!newinfo) return -ENOMEM; if (countersize) memset(newinfo->counters, 0, countersize); - newinfo->entries = vmalloc(tmp.entries_size); + newinfo->entries = __vmalloc(tmp.entries_size, GFP_KERNEL_ACCOUNT, + PAGE_KERNEL); if (!newinfo->entries) { ret = -ENOMEM; goto free_newinfo;