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 4E2D9C3A5A6 for ; Tue, 27 Aug 2019 08:17:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1BEB3206BA for ; Tue, 27 Aug 2019 08:17:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566893853; bh=EckQD5802OaCUczfZ4Hir4YXw79+iz7taCIsv2SumYA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=O7pnYvotFa76KBpmkLg39o7Iiy6INnfDqBM+7YNd6A2XiRSVv7hoS1ZDPbEqTX17C IrNIijbBnTocivQyTKvkLrutGCGagTn6wUIK6p6lHmVZwJaHZRht7xrv+D48Ur5ZZ2 Iiz3t9TZr+Ep6qoDVXD76yIB0n4+44BAbZ13vNWs= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729024AbfH0Hvv (ORCPT ); Tue, 27 Aug 2019 03:51:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:42984 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729017AbfH0Hvu (ORCPT ); Tue, 27 Aug 2019 03:51:50 -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 D6890217F5; Tue, 27 Aug 2019 07:51:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566892309; bh=EckQD5802OaCUczfZ4Hir4YXw79+iz7taCIsv2SumYA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NxhhXNrRH4SsYmzx/yyPbg6i5a8vXm4pLLILvfVB6AGUONoJfB5TjeQWZVTGxifrt EXJ4BmVN/32sadQ0gaVNj1mcqNK+UQLb3g6KFWCvDkFVV003uFK1KLSIVeTouV3V0s wZzAS0YGujv+VkT7tcS/u9TQRdYq0LX/Nu85P9vM= 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.14 04/62] netfilter: ebtables: fix a memory leak bug in compat Date: Tue, 27 Aug 2019 09:50:09 +0200 Message-Id: <20190827072700.331076787@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190827072659.803647352@linuxfoundation.org> References: <20190827072659.803647352@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 f9c6e8ca1fcb0..100b4f88179a2 100644 --- a/net/bridge/netfilter/ebtables.c +++ b/net/bridge/netfilter/ebtables.c @@ -2273,8 +2273,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