Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6257338imu; Mon, 21 Jan 2019 05:59:20 -0800 (PST) X-Google-Smtp-Source: ALg8bN4QgUaPs4eBq7ysTr7p0XwOF8Hloj4hwwRyAtS5VazUjVsfk22EDNcyTyTfGdoAN9dPLc0N X-Received: by 2002:a65:4646:: with SMTP id k6mr23242881pgr.153.1548079160861; Mon, 21 Jan 2019 05:59:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548079160; cv=none; d=google.com; s=arc-20160816; b=Q1/j0TzEw+5ALQNAshlgThTpoknBWwXakqI8RvI8x0SEyhWz2hbypEIGpbjb29I470 /7qDra9adxmhqSprrVw4eoSh5mlFQ9B2hEtrNfQPzSy9JBIgevj7yD/p5scnUL1VUUXp SXI8Pwi7ZczcVFQKqEQkpGdo5j4i0B3V4ftbFTGuT+hz5KOO5pBy1ghpP+a2ZrncRIJg s/x+W1FqNnnj94+ZQQGRGT6kzUN39xUNkqaHbJ3axL9u0Th36YjRz+PtjZQvzCVYFG+c gPXiOl8Sp7ovy73pE2V1S3oSZWw18MVj9XFGZ5QaEIKnr8d5y3190zyI18yu+P0tL1Hb fX7Q== 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=qw+A4sZlS8U8olT7W2Rawp9pwXLhbubtdVGZlqzhL2E=; b=afsj4+OI3N7j0/pl2YF2Hi5VId5h3tKY8rWwWw5RMBvqdBX3loCje0do/jM+iW0MV5 +Mkh+WebwgRMI542ko9k9b05rh1EZLqS7IqxDFXDBZq5TITB3K3XUiGjE90IQFBN34J/ yEAXTVjh2VopkP4hjvK6caMDujzI/rYPwI4C5D4ah1NpclurpGXlt72lJlAc/Uyng2WE semAlI/jBxQe5uD3Vqc64CIS317HnHSwaroWJ1fwl08OWAwME3iqMUAp1gTu1m2yrPA2 d8Kw2kfKWqORR+4tJhPCmYFxWsVhS+emW1pkW1t/wtZGWy3WFXKGphZkKJeYsHynumT2 eUiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NBh4HnQx; 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 y7si6441006pgq.545.2019.01.21.05.59.05; Mon, 21 Jan 2019 05:59:20 -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=NBh4HnQx; 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 S1731960AbfAUN4f (ORCPT + 99 others); Mon, 21 Jan 2019 08:56:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:41802 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731939AbfAUN4a (ORCPT ); Mon, 21 Jan 2019 08:56:30 -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 6403D2084C; Mon, 21 Jan 2019 13:56:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548078989; bh=J5wa0eo8jZ3fDNPOuQHfeV+0kXIhSQIOwXO2hfxwPH0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NBh4HnQxJKnYUJmWd0j776AilBXlgXi5Bny4SSh/QGIK2xP2U9YN28tofmLYv+QIo GkD0y+i40Egv4PebIzjfrbFbcS5twinbGim/JHXE5sWbV1N3ivI5bzpI7IEuCblJrF rd4NZdQVNmI2aV+8FHp82tEcsP0+PLtcvzm2EkiA= 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.9 37/51] netfilter: ebtables: account ebt_table_info to kmemcg Date: Mon, 21 Jan 2019 14:44:33 +0100 Message-Id: <20190121122457.271400912@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190121122453.700446926@linuxfoundation.org> References: <20190121122453.700446926@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.9-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 @@ -1147,14 +1147,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;