Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp5232150ybl; Tue, 27 Aug 2019 01:13:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqz0FuiVGPnHdeDuDZ9Mb/OIlDaa0j1nRINouvBxt45WXYE8WlWHazlObyPCiQXgqUGDke3S X-Received: by 2002:aa7:9483:: with SMTP id z3mr24974843pfk.104.1566893615624; Tue, 27 Aug 2019 01:13:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566893615; cv=none; d=google.com; s=arc-20160816; b=Hu/eMWx0Tj2faIeOMBnpLGULii/uFChlj9RbwY+YTb5w/a6oiEO09gCP9IMRL15HFD jCJRmOIJOwfrpI0zYiq+acYN8Ra21J/YOF/9ohCQI8rJQwOgB5vQmuN5v3KHzz1rTzHn r6He2EfbT2O42Xtl6tdOW6pllpyIfyiyUUS5sLt+KGHXJkXHRVA/GuICTwKi6I3N/Zd1 neAZ8kitWu8gfSgE7+CmDRl2FsDwxbq7YMLnZKGVDO13OaYQPybK7ZQhnjvTlJEoA37A PSqF4aEPLS0eOWIb07rK25WUPapf/IJRjfUINHBBKY+p5/4BdhYWybDphCPeImRRujSs nIlA== 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=CC2TGgrEFMDNUFRTUpsvP0Zx/drKtUP90xiYzh1LHMk=; b=TLzMIJktdrm97XRL+gYUTCHCAGh/xrz6X73e8K2TfdTM7QN9kMtv/oYLeWXDN6efDg TNPwlO9mE6MSWWsiXTUpHhaMWFnwVmZcekZ8TTiJHZ4PkghxVdZbzIKoa6N1TU11H2Tv 52qTABm5wJ1OS1qHeHPJBzYjZYYsyQyP8d8RG4w9jJjleLbP2S1QEP0rUZ6bKTxX4hFP D0KhtwpbO+0za3LkKkHgdVSdSdK1/LgZ4iEyA3mJbx/tY5zSijbisLQJh5WFwTP0iMTb 39fFmLm7Xe9j4Ub4Vtk/r5Iqgg1UmYUWjXiaWSL69Xi2czdbLDUSKrkIxMgvlDj+De/u ebKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QjoeVbuH; 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 k4si11664879pls.191.2019.08.27.01.13.20; Tue, 27 Aug 2019 01:13:35 -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; dkim=pass header.i=@kernel.org header.s=default header.b=QjoeVbuH; 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 S1731509AbfH0ICU (ORCPT + 99 others); Tue, 27 Aug 2019 04:02:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:58722 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731381AbfH0ICB (ORCPT ); Tue, 27 Aug 2019 04:02:01 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 1B842206BA; Tue, 27 Aug 2019 08:01:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566892920; bh=WS+CmDHqzUy2zgz4R2Zrq74rKLhmlrcLhpmKzwlhLK8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QjoeVbuHxqLuW54PpkjFSbBQ5TFPDrY9piTkUqPXZ+k/ul+L5ReSq6BvPPJYGrizU 1Ta6MVFKhFIc1R7lK4WlQbevfGdBLVtdXmawtogtB8Mp6fhTUKc1i4tVJUVyRnDn4X evqurtm/7HmaLuXD3EO6i8TvE3TCttwTAfMTIFf8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wenwen Wang , Florian Westphal , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 5.2 017/162] netfilter: ebtables: fix a memory leak bug in compat Date: Tue, 27 Aug 2019 09:49:05 +0200 Message-Id: <20190827072738.932000832@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190827072738.093683223@linuxfoundation.org> References: <20190827072738.093683223@linuxfoundation.org> User-Agent: quilt/0.66 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 [ Upstream commit 15a78ba1844a8e052c1226f930133de4cef4e7ad ] In compat_do_replace(), a temporary buffer is allocated through vmalloc() to hold entries copied from the user space. The buffer address is firstly saved to 'newinfo->entries', and later on assigned to 'entries_tmp'. Then the entries in this temporary buffer is copied to the internal kernel structure through compat_copy_entries(). If this copy process fails, compat_do_replace() should be terminated. However, the allocated temporary buffer is not freed on this path, leading to a memory leak. To fix the bug, free the buffer before returning from compat_do_replace(). Signed-off-by: Wenwen Wang Reviewed-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/bridge/netfilter/ebtables.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c index 1fa9ac483173d..c8177a89f52c3 100644 --- a/net/bridge/netfilter/ebtables.c +++ b/net/bridge/netfilter/ebtables.c @@ -2267,8 +2267,10 @@ static int compat_do_replace(struct net *net, void __user *user, state.buf_kern_len = size64; ret = compat_copy_entries(entries_tmp, tmp.entries_size, &state); - if (WARN_ON(ret < 0)) + if (WARN_ON(ret < 0)) { + vfree(entries_tmp); goto out_unlock; + } vfree(entries_tmp); tmp.entries_size = size64; -- 2.20.1