Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5182366ybi; Tue, 28 May 2019 08:51:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqygWTxktcQlIqOh4GtRYHpMB3/lCiiDSNI3MhXOI3W9tVKJNshqMck6VuM/RZBjpzyX0lXx X-Received: by 2002:a17:902:2884:: with SMTP id f4mr105204859plb.230.1559058660656; Tue, 28 May 2019 08:51:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559058660; cv=none; d=google.com; s=arc-20160816; b=CX5OD1RAZADPI0dBisdYsvIvJJq2jaDa8mqkOqx6CLBVT3trg4uixHXM2FPzvV3RZx VADq4Z4TwPeET8GPAKQt2eZ28zT9Bzh2n5ZsyduaPP4hZBWjbQqivUOReDn0FUqDg1sj zsqDwczG4Vn3HA4/Wv7RTGC+nCR5yHo+ldJK+36Kx1rfwsVstMImD37m+6/6cbTgio14 YuLJ/7dl7rKSy5jVbDkY851q42ZAV7OSdb2P/JKzQomHP/mB5ArWRcUQG3KAkTa94dvb RblnAz0XJL7WpGksJjILhc6x801iWRFRmcdHRZMNyMBjHEU1d9lYG34SQS3q5OQvRmvR q7Kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=rEHc1CMKOI2EV1+YEHc1IQAqUHKgfAq+IYguUjdZ5y4=; b=nv4OPh+k/lggjP2h08MI4ceBbVhUinI2tykhd7140EJdyaGrPquV5A6bBcffhpnS/2 SjK/jodjFUpbekx7l6gbl0olYg23YrLdUwHPCoDFafwaBcyNu3qGLUkZmr9X1jciu3va /ijwROBtSp6DLGujP71pQ0IbZDaSljbrlKHhrp+zdxlwhXaJ0QbjekPOyI1MO7ZDPK+O vJgUTpMJPptZutO4Rm4OUHtAutKWX/C7oDiDw4c8bTjF2SUZDQEmTmXg2upFvjVMn8Ri 3tgy0oFxZzTqO30H0UFy5gaKQ0VPvQFk/lvP7Op8X9MUb9NV3UMXzZUgPBCRrCgmf7/r HbXg== 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 h15si23967060pfn.96.2019.05.28.08.50.45; Tue, 28 May 2019 08:51:00 -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 S1726650AbfE1PsY (ORCPT + 99 others); Tue, 28 May 2019 11:48:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:57080 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726243AbfE1PsY (ORCPT ); Tue, 28 May 2019 11:48:24 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (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 864E82133F; Tue, 28 May 2019 15:48:23 +0000 (UTC) Date: Tue, 28 May 2019 11:48:21 -0400 From: Steven Rostedt To: Tomas Bortoli Cc: linux-kernel@vger.kernel.org, mingo@redhat.com Subject: Re: [PATCH] trace: Avoid memory leak in predicate_parse() Message-ID: <20190528114821.2302dabd@gandalf.local.home> In-Reply-To: <20190528154338.29976-1-tomasbortoli@gmail.com> References: <20190528104400.388e4c3f@gandalf.local.home> <20190528154338.29976-1-tomasbortoli@gmail.com> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 28 May 2019 17:43:38 +0200 Tomas Bortoli wrote: > In case of errors, predicate_parse() goes to the out_free label > to free memory and to return an error code. > > However, predicate_parse() does not free the predicates of the > temporary prog_stack array, thence leaking them. Thanks, I applied this and I'm running it through my tests. But just an FYI, when sending updated patches please add a "v2" to the subject: [PATCH v2] tracing: Avoid memory leak in predicate_parse() That way struggling maintainers like myself don't get confused about which patch to apply ;-) Thanks! -- Steve > > Signed-off-by: Tomas Bortoli > Reported-by: syzbot+6b8e0fb820e570c59e19@syzkaller.appspotmail.com > --- > kernel/trace/trace_events_filter.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c > index 05a66493a164..ecfa6f0f1c7e 100644 > --- a/kernel/trace/trace_events_filter.c > +++ b/kernel/trace/trace_events_filter.c > @@ -427,7 +427,7 @@ predicate_parse(const char *str, int nr_parens, int nr_preds, > op_stack = kmalloc_array(nr_parens, sizeof(*op_stack), GFP_KERNEL); > if (!op_stack) > return ERR_PTR(-ENOMEM); > - prog_stack = kmalloc_array(nr_preds, sizeof(*prog_stack), GFP_KERNEL); > + prog_stack = kcalloc(nr_preds, sizeof(*prog_stack), GFP_KERNEL); > if (!prog_stack) { > parse_error(pe, -ENOMEM, 0); > goto out_free; > @@ -578,6 +578,8 @@ predicate_parse(const char *str, int nr_parens, int nr_preds, > out_free: > kfree(op_stack); > kfree(inverts); > + for (i = 0; prog_stack[i].pred; i++) > + kfree(prog_stack[i].pred); > kfree(prog_stack); > return ERR_PTR(ret); > }