Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6267827imu; Mon, 21 Jan 2019 06:07:22 -0800 (PST) X-Google-Smtp-Source: ALg8bN4kcenedMXu+oG/5Ye+pcithEmSrBRM3oCcD6uNX7xvXRiZ0YhMaENAOWZyBELGEc84pXFd X-Received: by 2002:a62:6ec8:: with SMTP id j191mr29907388pfc.198.1548079642216; Mon, 21 Jan 2019 06:07:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548079642; cv=none; d=google.com; s=arc-20160816; b=ZZZSnaztMw0+b8Ffq4plRd+5wdHzA2+AEPPSoYneXKc2fH4YZhthAqFM1SQQT1TJPn iMP5b1RsI3HWWDYdLEdAj8j0Bxjf0JFtbMtH78HHLIjI5Rzlxz5CX7etbJX0p6wa7+8f fohGOO+mhOkhoFk19+Z7ajoDnSj4gGuPWXjdrKDuOI8yQipPPcZFRrJEku2TgmVXUgOT RY+KXABcz9YNrZEvlFw20IT8bA/sKo3QvRcZKwhZdEyOoBGF71r6g8SZeccT+Xt+tdaQ NDQoP5L+ep3Bgu/FFaxdDaMP83wIwatk7Eq9dDmxMWWQTSlVzK8QXVr9K/I6vWI+O0N2 EGbA== 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=MTzi+yVOpPg1nCgBcf+t+8GYHiKrytP6XOiwk4RCHXc=; b=SpFKh8A4FSqJxQHHVkuG8w8nvaeVraSHutet5rTissFOGtAAaKmXhai4X6JZAXi5zk FqhMZEMVm9o2uhzb21cwFbYLC98bKEbODa2Z1fF1y2HuGPJTJ59dC/6dqupUlNm+EYCq pTR7GR/5W94tWcmRw726j1gnFvsZaaGxhY4xsKcKYZHMpT8KnNTUTuEuoGQooabZ3XXI BLQ4M7bRTMHCoJcqNq4uvYfOwJPsVOAzv/k8R6xI1H5bSZeHMCXlI5f8NWA0/vW9ojYB 9SDp87QTT4oXsUoGDNnatLBBQLyRhKydXX7tJ3qS3eznOPFNHThup7guJCYoANONIXE1 qHEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xlfbIryR; 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 i2si13039512pgl.153.2019.01.21.06.07.06; Mon, 21 Jan 2019 06:07:22 -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=xlfbIryR; 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 S1732638AbfAUOB1 (ORCPT + 99 others); Mon, 21 Jan 2019 09:01:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:48386 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732154AbfAUOBW (ORCPT ); Mon, 21 Jan 2019 09:01:22 -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 AD60C2089F; Mon, 21 Jan 2019 14:01:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548079281; bh=o6beDz6+dBB9OIbijO6dxkui/wioAJh0dV1nCeif7Rc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xlfbIryRfB+lZ5QNfRMJYQ4GDPPPfOTkTaecRlRYvVcuv9kK6b7dN8Vz89N8V4d54 UEvKUSLvxuVHnBeJWMDtNXXVC1R040gTTa94WajYcWKEnI4NxgU0+4SfG1UC6aRgHk Ad5vW0eYN5e59L2gRaFHBmm5LGvKBH+EJEJ9lcHQ= 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.19 69/99] netfilter: ebtables: account ebt_table_info to kmemcg Date: Mon, 21 Jan 2019 14:49:01 +0100 Message-Id: <20190121134916.606265438@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190121134913.924726465@linuxfoundation.org> References: <20190121134913.924726465@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.19-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 @@ -1137,14 +1137,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;