Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5179967ybi; Tue, 28 May 2019 08:48:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqxa0ee+jJ9tfU9oKhrh9aLdHPaLwOdBiBzsQf37t1dXPm5XlxgA2mPK0giHjHZNytZg16SE X-Received: by 2002:a17:902:8a91:: with SMTP id p17mr71238078plo.60.1559058527816; Tue, 28 May 2019 08:48:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559058527; cv=none; d=google.com; s=arc-20160816; b=xM6fnpc6wMu1G3dtGEThYVCjnCf1WN9THUFGkh9sA5ohFifXTDQRXg3P1PuihCsF8R WCe7be0lSG6jGeWXQ4XpIukDRhPti76850YrpkKw3ofkV/OWxmfSdF3VK3jO9DhStcJK j4IafcmVy7YsCMzkOg5+2Uvf+nEc746irUdv+IqP+IW4aDAeMG5O9jVbGIdsZcfuLPjz FVei07GuVhxAaeu8X5dk4QB6nVZIrjkh8rTGCQxCYSh9Kq+AVOyHKgYlBYa5FhtD8pgI syi6HW/hLLwFmd2Qn1ZjpOtoU1QgZEBN8GJPgPUK7L/DOERxCTzykg294f5OyIRZkd6s w1uA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=3QcHyU0ChRIqu42slw8WQtOrrcCMUCI+/jcdZM9VOkM=; b=XVvhnNHd/bHABHyXiQWw/Y9wB/UcE7Mhm0iJt+NEbmj2E+Hu3/2MgM6NHWuk49QIYr EXSjhCfDtiS4wUT4v6Oe6TYk0U+hAQ34LVk1qJQahwrCPJTu4gJ306VY6QDAF4aC27sK P0M86zbrsEMdONYC019rrXqPCgTF7YDHxs3nOHd1nGh5+GGpIv/gZMwIUYE06hg50LKy m1ape4LV+zgfUKx5cp82pV0CMBBhYJqXgbeC2I7jk8PauX5Ewols26WMreCW2r5G2HJQ 3kPfujZK2Ga0raDcieL1MHZYjwGOPkC8rx+33aQ/E7F6dBjXSa99TwlY5OQKuYXppT11 9HBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nAzcPGxT; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d16si21459135plr.408.2019.05.28.08.48.24; Tue, 28 May 2019 08:48:47 -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=@gmail.com header.s=20161025 header.b=nAzcPGxT; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727084AbfE1Pno (ORCPT + 99 others); Tue, 28 May 2019 11:43:44 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:38169 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726688AbfE1Pnn (ORCPT ); Tue, 28 May 2019 11:43:43 -0400 Received: by mail-lj1-f193.google.com with SMTP id 14so18195436ljj.5 for ; Tue, 28 May 2019 08:43:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3QcHyU0ChRIqu42slw8WQtOrrcCMUCI+/jcdZM9VOkM=; b=nAzcPGxTp8r6ndLEWEm43735s8vwleAVc9BIhk0Ih8z0T9Vx3+c/Gxsl7Vcij6cYHJ we2Fz6MnR6sE51Vpq4b+zvGP2mxoDYCdo6rEN3UrfNkOv/6aBEYat7amBcMltixqla+P BXeGwQxA29rR6w3zpAb0E3hMOHt6VjhH4xJBhME6gW4X1GeFyv5h0vdlXPySfxIylrpJ 3O4o3+oSgenC3MSx4S+bHgiQJoDzEFM9OD9lW0eyQWpuD4/+11kg4UHfmbHHGEjERcoY qFmpfXBszmU1wAAQvHDVwd/l2UP6O7OK6MECtjyD37iLTfKxHL10G67w/E6KEGkwG4n0 P4Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=3QcHyU0ChRIqu42slw8WQtOrrcCMUCI+/jcdZM9VOkM=; b=VNLshYNqqTrrDB6YpVUMlO9wFGPeI0JaK86PesfOk11uNsViMBL+yaptxFLoBjgdc/ YTtRpmiXo6ii87VIbAg4ZfCD+kLVxXYk9CUvQLqVpCogfc6ibbAus/UyCZVlzrcf50Lr aPcVGK7kkjw4uuEVkaL1Dctw1y/vRDIdYtnnKtOu3Zbjq9PKCg3tbTP7fdEHVVIVcN31 EukHxoWZWL0qo17Tot2Tf1YAzgOgmDOrezA9UU+PA+IoW9H2zbaJWxdgrGHZD0z1EcAC rVpDxmI/QBKJ6ABMkx0fuenZ+sYfefUGVNZLZKHeHFGJze8E4QtKYR1FE2cs+nKGlxyB Uc6Q== X-Gm-Message-State: APjAAAUu/Oj6CPr3qaiiOKy9eE+L02za21nVIhx0MU+9OJ7ZPYz0mQXO JOZckNYlXlFfkV2gc1UjmsgtrZdm3VU= X-Received: by 2002:a2e:4710:: with SMTP id u16mr36129829lja.41.1559058222035; Tue, 28 May 2019 08:43:42 -0700 (PDT) Received: from debian-tom.home (2-111-15-75-dynamic.dk.customer.tdc.net. [2.111.15.75]) by smtp.gmail.com with ESMTPSA id t2sm3415721ljd.36.2019.05.28.08.43.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 May 2019 08:43:41 -0700 (PDT) From: Tomas Bortoli To: rostedt@goodmis.org Cc: linux-kernel@vger.kernel.org, mingo@redhat.com, Tomas Bortoli Subject: [PATCH] trace: Avoid memory leak in predicate_parse() Date: Tue, 28 May 2019 17:43:38 +0200 Message-Id: <20190528154338.29976-1-tomasbortoli@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190528104400.388e4c3f@gandalf.local.home> References: <20190528104400.388e4c3f@gandalf.local.home> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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); } -- 2.11.0