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=unavailable 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 A4FC7C3A5A3 for ; Tue, 27 Aug 2019 08:11:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 71F962173E for ; Tue, 27 Aug 2019 08:11:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566893466; bh=WS+CmDHqzUy2zgz4R2Zrq74rKLhmlrcLhpmKzwlhLK8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=b6cOUtHgmEu5kaMsJ0hi1523u68eZG20VIfr4l8v8kbnJ/xdn3W5vWv2kKCxZkHqT eR87BI1kVWtzsFya7831zuHjiHWUK0PBpYWJUucOhRvV53hkqvMpTxxPi3njap8Lej rPq1FS9NfYuRydhj6Ik70c1smZt12IrsHRnJbhuA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731859AbfH0ICC (ORCPT ); Tue, 27 Aug 2019 04:02:02 -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: 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 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