From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0043BC3A5AA for ; Wed, 4 Sep 2019 17:59:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C6D23208E4 for ; Wed, 4 Sep 2019 17:59:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567619988; bh=2w9cBEpuvv137vz55MidZCdZC8ewdK2WUXJtiTkff6Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=uSlNPAF0iS0jhK2IpRYpMjapkVbYfNlpqpP3pXKTL3PcNjUbj3+4i2mXffG4AJC3b bKuHQKoaKwuvFsX3bkigJftPDY4ed3OQILz0zlWkTcopp9t+9bWMaJztpDlfLiDnMB zlSa4QJXYc/YaKmc6jr+IV3sYHH1nsQpDReahg8Y= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387636AbfIDR7r (ORCPT ); Wed, 4 Sep 2019 13:59:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:38618 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388265AbfIDR7l (ORCPT ); Wed, 4 Sep 2019 13:59:41 -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 45C7C21883; Wed, 4 Sep 2019 17:59:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567619980; bh=2w9cBEpuvv137vz55MidZCdZC8ewdK2WUXJtiTkff6Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HR47O7H6aPShCS7nTiS5nCpTBWGuIl1a2iCact3Eaw5sKDQfWmzb28MUIGWC0j6pe 53XqBTg5VFlZcye41WmT5Y/OQ2c8dzBseMN93h4Ucztxc2jqPSUedZx8GHY8/p48O9 oLvrg+oGxJwuQZz3PxqWGogUd7QYybwj0WAxV0Jg= 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 4.9 03/83] netfilter: ebtables: fix a memory leak bug in compat Date: Wed, 4 Sep 2019 19:52:55 +0200 Message-Id: <20190904175303.871150754@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175303.488266791@linuxfoundation.org> References: <20190904175303.488266791@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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 142ccaae9c7b6..4a47918b504f8 100644 --- a/net/bridge/netfilter/ebtables.c +++ b/net/bridge/netfilter/ebtables.c @@ -2288,8 +2288,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