Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2681yba; Fri, 19 Apr 2019 18:48:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqxu52+b0VEmzYCU/Y+cLDasrEZS5x23dDddx7R16wKhhuWs3OT9FZ/8rH9HvamEU15U+MrP X-Received: by 2002:aa7:8a92:: with SMTP id a18mr7372385pfc.218.1555724907426; Fri, 19 Apr 2019 18:48:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555724907; cv=none; d=google.com; s=arc-20160816; b=KLEb9XxYe+EqKe6wF6u3HJFkYXeKa1PX+fBCRspcEZRxSt1dNYBPplId93qV6Xir7+ 4DoFWRVf9eS4R3j3rgr/c1yqNlKEASY04Wb8gOlXhvm26CkW++fzz1jLfQeNlRNmRgE5 ObKdf/cGFFp8sdrSeYHjRR5lWCzGONGFDZp26U8S7gQSnrj7z9w8SYlTKO4PMHce7QDg mHiSWEWOdGwtdXj5pBH2TIuqwvUb7Cd+nzroMFXP9oxfOkcxEdwNEKSsQgT6GYFN5cw4 XuZBol09ldm8KBPKXvD65BHf5875Iyp5yWGMaQRqgoLhJNU5wqaku1B8pMp3ChrZ4eES FdfA== 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:dkim-signature; bh=KoLUBG9OBJnqhZVGIJANAjoXcQhif/38ucJI49kEifk=; b=z9dAjohOVsQKCuszP16SRx9NTNz3hAel/woC6RRlt1DR/ofVDvRLq6SHBvFtGnSIPK Fi9I0BExMkpKwUdBIpE9snXYZ55VbbFK3aEKMrGdJAEWZzAHEw8tWNZ7mPWrHRrrCI2l NqPIbUZ6yJP9zv47yP/xub8yVB0CEQbU5GG9Ry4/f/0nwq4opcgl3NjeP5QAxaCnWytD Jc5Q41YjkAS7fdHqsXvQmhYpryRUSbhTtHVfPEljS45QzHO1TuiIWsltS2EQiqYgAnk5 mF1GmUUsRj5DRiU2zwEXMTSuroQ6epBf+TA1fwTUNDto0AdlichZtdWmdfm8/WrWGGiS a2IQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@umn.edu header.s=20160920 header.b=GX3SLxns; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=umn.edu Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y11si6621196plk.237.2019.04.19.18.48.12; Fri, 19 Apr 2019 18:48:27 -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=@umn.edu header.s=20160920 header.b=GX3SLxns; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=umn.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727572AbfDTBqr (ORCPT + 99 others); Fri, 19 Apr 2019 21:46:47 -0400 Received: from mta-p3.oit.umn.edu ([134.84.196.203]:38870 "EHLO mta-p3.oit.umn.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725858AbfDTBqq (ORCPT ); Fri, 19 Apr 2019 21:46:46 -0400 Received: from localhost (localhost [127.0.0.1]) by mta-p3.oit.umn.edu (Postfix) with ESMTP id C394EA0A for ; Sat, 20 Apr 2019 01:46:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=umn.edu; h= content-type:content-type:subject:subject:message-id:date:date :from:from:in-reply-to:references:mime-version:received:received :received; s=20160920; t=1555724804; x=1557539205; bh=1+gEhSVO0m qrkUVP5FD21Tqp3hcyyuecKeWAxa/2ht0=; b=GX3SLxnsFw0VcCcAKnceeCge8U tveGtEkcEGTviiCFiHzUvVOfgxcfccYTjnW+vG8Db0Eq39VHp7nV5FnsGlEeXZoR DXrCdefFWN+91ISG9SrnrAS8/vrTb2q8l/8kL2ojCracw26m2wjmHRq0e8Z2pBWg VClHAsgA4aS6FLgnRFMxNbA/yFACcLU2o1I2smP6B5aio/p+4BB6sz3E6Is/ryIV Z1JGuWQ2/gDR0oh+X7zDF8bw5cTHQx78cUVQqr8ihWvY4EukUfX5Rz7284JC52VK U3F5IhpQTc7Q4ModeGO7ZiHCXkgIydVaucgrsdPRePeDNWwhslOyncYbvTgw== X-Virus-Scanned: amavisd-new at umn.edu Received: from mta-p3.oit.umn.edu ([127.0.0.1]) by localhost (mta-p3.oit.umn.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 99s9eJjCOjAL for ; Fri, 19 Apr 2019 20:46:44 -0500 (CDT) Received: from mail-it1-f169.google.com (mail-it1-f169.google.com [209.85.166.169]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: wang6495) by mta-p3.oit.umn.edu (Postfix) with ESMTPSA id 8657A9AB for ; Fri, 19 Apr 2019 20:46:44 -0500 (CDT) Received: by mail-it1-f169.google.com with SMTP id f22so10689473ita.3 for ; Fri, 19 Apr 2019 18:46:44 -0700 (PDT) X-Gm-Message-State: APjAAAW576wzCuMByu36q7nMcfLuLWHYvuvnskPUn9bkVcnY6tDdCkDe Esm5NYh8tn2LVVmdQRF8EEWNlql5bBFoXTNp5nU= X-Received: by 2002:a05:6638:26e:: with SMTP id x14mr5083193jaq.32.1555724804305; Fri, 19 Apr 2019 18:46:44 -0700 (PDT) MIME-Version: 1.0 References: <1555686587-13866-1-git-send-email-wang6495@umn.edu> In-Reply-To: From: Wenwen Wang Date: Fri, 19 Apr 2019 20:46:08 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2] audit: fix a memory leak bug To: Paul Moore Cc: Eric Paris , "moderated list:AUDIT SUBSYSTEM" , 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 Fri, Apr 19, 2019 at 2:28 PM Paul Moore wrote: > > On Fri, Apr 19, 2019 at 11:10 AM Wenwen Wang wrote: > > > > In audit_rule_change(), audit_data_to_entry() is firstly invoked to > > translate the payload data to the kernel's rule representation. In > > audit_data_to_entry(), depending on the audit field type, an audit tree may > > be created in audit_make_tree(), which eventually invokes kmalloc() to > > allocate the tree. Since this tree is a temporary tree, it will be then > > freed in the following execution, e.g., audit_add_rule() if the message > > type is AUDIT_ADD_RULE or audit_del_rule() if the message type is > > AUDIT_DEL_RULE. However, if the message type is neither AUDIT_ADD_RULE nor > > AUDIT_DEL_RULE, i.e., the default case of the switch statement, this > > temporary tree is not freed. > > > > To fix this issue, only allocate the tree when the type is AUDIT_ADD_RULE > > or AUDIT_DEL_RULE. > > > > Signed-off-by: Wenwen Wang > > --- > > kernel/auditfilter.c | 16 +++++++++++----- > > 1 file changed, 11 insertions(+), 5 deletions(-) > > This looks good, it just needs some minor vertical whitespace fixes (see below). > > > diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c > > index 63f8b3f..923b858 100644 > > --- a/kernel/auditfilter.c > > +++ b/kernel/auditfilter.c > > @@ -1114,22 +1114,28 @@ int audit_rule_change(int type, int seq, void *data, size_t datasz) > > int err = 0; > > struct audit_entry *entry; > > > > - entry = audit_data_to_entry(data, datasz); > > - if (IS_ERR(entry)) > > - return PTR_ERR(entry); > > - > > switch (type) { > > case AUDIT_ADD_RULE: > > + entry = audit_data_to_entry(data, datasz); > > + if (IS_ERR(entry)) > > + return PTR_ERR(entry); > > + > > I realize you are taking the blank line from the code above, but we > probably don't need it here. > > > err = audit_add_rule(entry); > > audit_log_rule_change("add_rule", &entry->rule, !err); > > break; > > + > > Definitely do not add this blank line. > > > case AUDIT_DEL_RULE: > > + entry = audit_data_to_entry(data, datasz); > > + if (IS_ERR(entry)) > > + return PTR_ERR(entry); > > + > > err = audit_del_rule(entry); > > audit_log_rule_change("remove_rule", &entry->rule, !err); > > break; > > + > > Same here. > Thanks for your comments. I will remove the blank lines. Wenwen