Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753324AbeAQNcN (ORCPT + 1 other); Wed, 17 Jan 2018 08:32:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:59804 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753228AbeAQNcA (ORCPT ); Wed, 17 Jan 2018 08:32:00 -0500 DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8375C20836 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=acme@kernel.org Date: Wed, 17 Jan 2018 10:31:56 -0300 From: Arnaldo Carvalho de Melo To: Thomas Richter Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, brueckner@linux.vnet.ibm.com, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: Re: [PATCH] perf record: Fix failed memory allocation for get_cpuid_str Message-ID: <20180117133156.GG30880@kernel.org> References: <20180117131611.34319-1-tmricht@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180117131611.34319-1-tmricht@linux.vnet.ibm.com> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: Em Wed, Jan 17, 2018 at 02:16:11PM +0100, Thomas Richter escreveu: > In x86 architecture dependend part function > get_cpuid_str() mallocs a 128 byte buffer, but does not > check if the memory allocation succeeded or not. > When the memory allocation fails, function __get_cpuid() > is called with first parameter being a NULL pointer. > However this function references its first parameter > and operates on a NULL pointer which might cause core > dumps. Thanks, applied. - Arnaldo > Signed-off-by: Thomas Richter > --- > tools/perf/arch/x86/util/header.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/tools/perf/arch/x86/util/header.c b/tools/perf/arch/x86/util/header.c > index 33027c5e6f92..c6b5204e0280 100644 > --- a/tools/perf/arch/x86/util/header.c > +++ b/tools/perf/arch/x86/util/header.c > @@ -70,7 +70,7 @@ get_cpuid_str(void) > { > char *buf = malloc(128); > > - if (__get_cpuid(buf, 128, "%s-%u-%X$") < 0) { > + if (buf && __get_cpuid(buf, 128, "%s-%u-%X$") < 0) { > free(buf); > return NULL; > } > -- > 2.13.4