From patchwork Wed Oct 16 21:49:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 11194535 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C8E831575 for ; Wed, 16 Oct 2019 22:18:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A814F207FF for ; Wed, 16 Oct 2019 22:18:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571264327; bh=KkXarZVi9IQI5T8enECmh0evr4Fy1GERF/KUBBGCKQE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=HSs1hEGZlMu+UUiygnNKMDyUBE6abRACejL7uDcXjLHD9laqkSovU8DoD8gMGJYOR yUqy50qzsl9s8yOn6IjmiPfzPls+QyBPij7ej7X2kbZ+ItzrruL3+vhYMz/Xr6Ky+4 +cqwrSC4WrpOMeAJiQ0Xn9lywlXibxGIgYkkMHO0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728559AbfJPWSq (ORCPT ); Wed, 16 Oct 2019 18:18:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:44162 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389001AbfJPVyV (ORCPT ); Wed, 16 Oct 2019 17:54:21 -0400 Received: from localhost (unknown [192.55.54.58]) (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 883F821925; Wed, 16 Oct 2019 21:54:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571262860; bh=KkXarZVi9IQI5T8enECmh0evr4Fy1GERF/KUBBGCKQE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eMfFgTLdq+jQIxbUlsXaA/VySKp7OK/rtXUHEV5McMWejCvhb6juXy63e/Qa3d/ye UEmdAmD0lk94qv4uQhc+vyV5pqj+SR2T0SAKAoRq/7iDvaIzvk3zQ0hNxrL68fR93l fNsQ1p+tlqYGIwpHXw18mxJqHYCH4mCEekp5oF1M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Steven Rostedt (VMware)" , Andrew Morton , Jiri Olsa , Namhyung Kim , linux-trace-devel@vger.kernel.org, Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 4.9 26/92] tools lib traceevent: Do not free tep->cmdlines in add_new_comm() on failure Date: Wed, 16 Oct 2019 14:49:59 -0700 Message-Id: <20191016214820.999791156@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191016214759.600329427@linuxfoundation.org> References: <20191016214759.600329427@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org From: Steven Rostedt (VMware) [ Upstream commit e0d2615856b2046c2e8d5bfd6933f37f69703b0b ] If the re-allocation of tep->cmdlines succeeds, then the previous allocation of tep->cmdlines will be freed. If we later fail in add_new_comm(), we must not free cmdlines, and also should assign tep->cmdlines to the new allocation. Otherwise when freeing tep, the tep->cmdlines will be pointing to garbage. Fixes: a6d2a61ac653a ("tools lib traceevent: Remove some die() calls") Signed-off-by: Steven Rostedt (VMware) Cc: Andrew Morton Cc: Jiri Olsa Cc: Namhyung Kim Cc: linux-trace-devel@vger.kernel.org Cc: stable@vger.kernel.org Link: http://lkml.kernel.org/r/20190828191819.970121417@goodmis.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/lib/traceevent/event-parse.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c index def61125ac36d..62f4cacf253ab 100644 --- a/tools/lib/traceevent/event-parse.c +++ b/tools/lib/traceevent/event-parse.c @@ -267,10 +267,10 @@ static int add_new_comm(struct pevent *pevent, const char *comm, int pid) errno = ENOMEM; return -1; } + pevent->cmdlines = cmdlines; cmdlines[pevent->cmdline_count].comm = strdup(comm); if (!cmdlines[pevent->cmdline_count].comm) { - free(cmdlines); errno = ENOMEM; return -1; } @@ -281,7 +281,6 @@ static int add_new_comm(struct pevent *pevent, const char *comm, int pid) pevent->cmdline_count++; qsort(cmdlines, pevent->cmdline_count, sizeof(*cmdlines), cmdline_cmp); - pevent->cmdlines = cmdlines; return 0; }