Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7197719ybi; Mon, 22 Jul 2019 08:43:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqzTbxYjS6WEESOkbPDOakXJsNlDMw2eV9BjGbRy1ei+XR2Tg9aYPmgUbLivaNwJYqaZTgkW X-Received: by 2002:a63:e14d:: with SMTP id h13mr72292855pgk.431.1563810192557; Mon, 22 Jul 2019 08:43:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563810192; cv=none; d=google.com; s=arc-20160816; b=DHiYJ8C+3Q75dVi5CnXfnDvwjJzMOJqZmX/dtg4unZOI0U5hGUnLNiRw8EPMUY1YHH uNhg9EsNfUn61q9uFK+FuZOXlVop5/+o0TKdRTm+e6ZabgZQPo/dnDxtA82OHa2l1bgL Y5ezwUgJNo2Mu4u18PkGe40TrILN/EOvCYZMTVxGlQzpHYFlW+d70bIcnBDgVFlfmbXT InG1TzJ/Wvt4eHJDrP238rpH56Iuc5RnNR6H7wcgKmsc2JN4Vddamzi9SZiUXtvx1BVH xjYmzPXm4BpIce2cdirQCigsB7+C9jaYcmkBn7hw+RnaXi6STUza1OjGn3/7gIGSN1TA RjLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=DZIkAAJy7QlVRlGShC0PsjFYGo7KbcW53m48UbmQiPQ=; b=XQCCt0P8Jc5xSshKsuHaFLxHidyvIOI8mFAWEDDEIKqiguPRi+CbM9kH3vCh4zO/Sl UeE03acHYLEayOe/V3gi9IRXbr9D86wEfUxuyjpoB0jYj22gsvlnXCtRZYLLMSp8QXac WHQJEGZj48ROwcbYEFMQYv5azzhvOy3XoA4cI92NkdDUMWiVuu4FwjCyMEYW30jzNgbf 0wGehD+dp2keDUEcU/0xEqWizZyIzSYC4YFcR1rJn8hrj6+Aq4mo0KLb/KNB7E8MDiv0 8wwDX5IHZHlkkitAVjpXIa9GsLfQu8eBRg4kSH4vFeMUzYGNr+LVKASZGEGQzdVyilya jhdw== ARC-Authentication-Results: i=1; mx.google.com; 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 k5si8107069plt.355.2019.07.22.08.42.56; Mon, 22 Jul 2019 08:43:12 -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; 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 S1729217AbfGVMyj (ORCPT + 99 others); Mon, 22 Jul 2019 08:54:39 -0400 Received: from ajax.cs.uga.edu ([128.192.4.6]:49366 "EHLO ajax.cs.uga.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727164AbfGVMyi (ORCPT ); Mon, 22 Jul 2019 08:54:38 -0400 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (authenticated bits=0) by ajax.cs.uga.edu (8.14.4/8.14.4) with ESMTP id x6MCsZkX013562 (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256 verify=OK); Mon, 22 Jul 2019 08:54:37 -0400 Received: by mail-lf1-f48.google.com with SMTP id 62so21670281lfa.8; Mon, 22 Jul 2019 05:54:36 -0700 (PDT) X-Gm-Message-State: APjAAAUVtJrnlw7xYq8J1kpLJPP/+MnqLN9+2al5jfaWtr0pH8CzBDIh 4Z29ufzqpDyoPcDlC00bVbGB22kn6fH+65nCB9o= X-Received: by 2002:ac2:4565:: with SMTP id k5mr31911521lfm.170.1563800075295; Mon, 22 Jul 2019 05:54:35 -0700 (PDT) MIME-Version: 1.0 References: <1563625366-3602-1-git-send-email-wang6495@umn.edu> <20190722123204.rvsqlqgynfgjcif7@oracle.com> In-Reply-To: <20190722123204.rvsqlqgynfgjcif7@oracle.com> From: Wenwen Wang Date: Mon, 22 Jul 2019 07:53:59 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] netfilter: ebtables: compat: fix a memory leak bug To: "Liam R. Howlett" Cc: Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , Roopa Prabhu , Nikolay Aleksandrov , "David S. Miller" , "open list:NETFILTER" , "open list:NETFILTER" , "moderated list:ETHERNET BRIDGE" , "open list:ETHERNET BRIDGE" , open list , Wenwen Wang Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 22, 2019 at 7:34 AM Liam R. Howlett wrote: > > Nice catch. The code that exists is confusing due to newinfo->entries > being overwritten and then freed in the existing code path as you state > in your commit log. > > * Wenwen Wang [190720 08:23]: > > From: Wenwen Wang > > > > 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 > > --- > > 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 963dfdc..fd84b48e 100644 > > --- a/net/bridge/netfilter/ebtables.c > > +++ b/net/bridge/netfilter/ebtables.c > > @@ -2261,8 +2261,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; > > + } > > > Would it be worth adding a new goto label above out_unlock and free this > entries_tmp? It could then be used in previous failure path as well. Yes, that would make the code much clearer and easier to understand. Thanks! Wenwen