Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2093014ybp; Thu, 10 Oct 2019 02:04:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqy4usLhVUX0y6vrK4iV/q/7PEEKMPMDsOxPOH8jvOCqp4g4yyy1hpNqWHbJcgLs5mq0MMVM X-Received: by 2002:a17:906:950e:: with SMTP id u14mr7044187ejx.145.1570698248274; Thu, 10 Oct 2019 02:04:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570698248; cv=none; d=google.com; s=arc-20160816; b=gPCQYIw+N78kG52lup2w2MawgiUHl2MzqTkyfKUhqkLY6yAt2TpeYx66T8P+C3TKRn tkxG05AbGPFDRNZ/4hPbXHXzt5U7PsejxtdDNeCFngH2nQPJI+Dyyqfsnf1UuhVKLnCM xDdqo61Al4U4xcHikVgtQcrdxhEckCHKIfuFpxYtCzbpkYeiHr/+g1C+QoGXqFApxHnh yfm+HVX4ehjfFbHINHv1wA2u2ogF2h80CgyF+V2V/U/IUzd5qFs4MSQ+gUSC4O9zQk1Y PN2OgRTa+6+ddOYHwq/ffAaA+lf9Vraxr9iBDMYm1JpO65iCXOhs6wM38NYmk4tuMup+ qgdQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lfFXDGAaXOxxNmiBv6vS4STQg8yzacvR4Zca/LQrPRY=; b=HvpX7WKXYuSV38ili2oz1Qq55sHKdsSQTRVNnWQTRUDr0swW8LW39rwrzHttk2PVIB McUfax269l6P4j4FhTuJwL4fvCVfeUD/NhTbYP/X7VYMvuLL3zcZUooEscnZQoh1qrcw S5/ubXoG0fOmnUNF4so9UoUYZKHXJChMoJAuQrp3cLUvuVQP64kIErVRQ8jDpM34ouKh o8QtV4APBdxA4R2YYkEzAAzTZ9HFbmx8zGXplCtOY5ohWvYDPlEIXxOWgdI+AXWzyycQ BogNlFit2slwBvcjqfhPn4ww7Y3OTc/lJOxjCHdp+zPLJJLTDH5qFOU3nJ4jOgvM1fjp 99Rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Dybwz2l6; 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 ox13si2682409ejb.0.2019.10.10.02.03.44; Thu, 10 Oct 2019 02:04:08 -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=@kernel.org header.s=default header.b=Dybwz2l6; 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 S2387639AbfJJIlS (ORCPT + 99 others); Thu, 10 Oct 2019 04:41:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:45590 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388281AbfJJIlP (ORCPT ); Thu, 10 Oct 2019 04:41:15 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 1085522479; Thu, 10 Oct 2019 08:41:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570696873; bh=zws2NfICo8i79kq3giIGcUyMD4BfkP5hx0wv0zz3sis=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Dybwz2l6+SRIw0z312H5R5EjoNdcGSxnC5HEx9lzuEAd1b2rL5EiUYphim8kXJ3Cm Xybgwte68gm1sDaWhllRc/GrNGwuJM9HT7o0zkzX+/X65R7v/H7CSHmpz/ebDoOTQc 171/0tyD9f0A/0iPV2ojj5te0CRhkIXU9E4G3TYA= 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 Subject: [PATCH 5.3 039/148] tools lib traceevent: Do not free tep->cmdlines in add_new_comm() on failure Date: Thu, 10 Oct 2019 10:35:00 +0200 Message-Id: <20191010083613.518791014@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191010083609.660878383@linuxfoundation.org> References: <20191010083609.660878383@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Steven Rostedt (VMware) commit b0215e2d6a18d8331b2d4a8b38ccf3eff783edb1 upstream. 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: Greg Kroah-Hartman --- tools/lib/traceevent/event-parse.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) --- a/tools/lib/traceevent/event-parse.c +++ b/tools/lib/traceevent/event-parse.c @@ -269,10 +269,10 @@ static int add_new_comm(struct tep_handl errno = ENOMEM; return -1; } + tep->cmdlines = cmdlines; cmdlines[tep->cmdline_count].comm = strdup(comm); if (!cmdlines[tep->cmdline_count].comm) { - free(cmdlines); errno = ENOMEM; return -1; } @@ -283,7 +283,6 @@ static int add_new_comm(struct tep_handl tep->cmdline_count++; qsort(cmdlines, tep->cmdline_count, sizeof(*cmdlines), cmdline_cmp); - tep->cmdlines = cmdlines; return 0; }