Received: by 2002:a05:7412:1703:b0:e2:908c:2ebd with SMTP id dm3csp3987849rdb; Wed, 30 Aug 2023 11:53:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEe+cCRNv8Rs/xr5pKrppNtHFbQx1kxv2UVBQHspmKQlVS8pYwzVvpxVMF9YtLdMVkuxw5U X-Received: by 2002:a17:902:efc7:b0:1bc:7001:6e62 with SMTP id ja7-20020a170902efc700b001bc70016e62mr2200454plb.35.1693421594155; Wed, 30 Aug 2023 11:53:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693421594; cv=none; d=google.com; s=arc-20160816; b=oDLtRW0Yz2ktorpxTTfaf8T+EoVHqgfYZlZSsehqdK7E0F3TINmIH/TA7FbjTiGr/6 xo37v7LuvYCUS4v3gc69JNToIBRv8uxp/FAkGDB1DnD6InlegpeMh1COz5aWNjI6Bn1a /I2DKWLL7AIKSi/EFnzpkAkgRGhzgcx6QZ0GSBf/RWoagc+XoIntT/Gle2vPlW6MR4xj j9E3ClzK5SS/2OIniegtypvSvTwubRz9QAqbN9JJEYIQhzMUfLgBq6Ig09K3aceBXgNt s1Lzp80JXABM05I79ccvW/lSwHuJf14wWKSRjMfkFqsRhkntY47MQLsFwvGcWgClXrci 3Stw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=285+fZ9DEAVHYdPTLKJ1SalvkVNQthlTltMgmW7bpw0=; fh=8UGTjIGBNFvvqb99uy87t0o2nawcYjc0HL/Bwub8MyA=; b=qSTPMCQ7pN6KmUSOtlKHFx+i78O9mRoPMqKQv3nB6HdvJkNeQuvVoz959inX+4DAXc KN9ijkwpvHQrkp7Wy6nS9YjwNSo5hdwSIUxz1+h3vl6OlFQJmU6lQmnBrzartCxodNNf laehNTu04+yZlGhSrxe/tXO3MLCZVtrYAI1HMLjomUbrfmTwAHMOrsBvcGj1502m+30S +S8O0CS3KcTQk+rnFb9Y+gtiM0r27jFnESdDCI7TIG6g/919dKif21S8BiIQQrm27Prn W6M9XOo2O3DqwzJUUWvrfef71/N1yjepaXnClbXP5or3r1SkAURAOnkZHoPfbxcHaViv ocpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BSUbGCgK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y16-20020a17090322d000b001c0a165a219si2691568plg.134.2023.08.30.11.52.29; Wed, 30 Aug 2023 11:53:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BSUbGCgK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239208AbjH3SkL (ORCPT + 99 others); Wed, 30 Aug 2023 14:40:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245651AbjH3PsM (ORCPT ); Wed, 30 Aug 2023 11:48:12 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 231A4122; Wed, 30 Aug 2023 08:48:10 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A2AD961FB9; Wed, 30 Aug 2023 15:48:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD8BCC433C7; Wed, 30 Aug 2023 15:48:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1693410489; bh=wnPJiJm7rQrsAoc2rWmWxlawY0FbhE1X+OSVa1CfQkg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=BSUbGCgKqPv26pt2syJYnQN5yPQVVlwVb0WAg2KDZmNu4ATFh6yjTkfSztfa9oEr8 XM+icEUhh0cPNhJzbZswf8QrDpIo+F41XZJwSoVwD8N+VdG5F9BimXRC4ulIBmb9XF Ntb41DAvA/gCaZW3MgF3SjOxidFDyzizQAOYKHZE815MryZEXv9U5YGQHoLkMRkS8i v9arDRbeJaQySdvcHaiGbivJicgNHYIT7N8Kfq+XZ2Rm2/1lSZk7cjn1euP/yUQ8ah DjdFwulViZMTjbmi7YSWoUpfWEmjjPahMHu0F0OeRrvnjaJkIbHDPIhOI/NEjfVov7 afBlwGV/yIPng== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 0F6B840722; Wed, 30 Aug 2023 12:48:06 -0300 (-03) Date: Wed, 30 Aug 2023 12:48:06 -0300 From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ian Rogers , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Kan Liang , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Sumanth Korikkar , Thomas Richter , Jing Zhang Subject: Re: [PATCH v1] perf pmu: Avoid uninitialized use of alias->str Message-ID: References: <20230830000545.1638964-1-irogers@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Url: http://acmel.wordpress.com X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Tue, Aug 29, 2023 at 07:23:58PM -0700, Namhyung Kim escreveu: > Hi Ian, > > On Tue, Aug 29, 2023 at 5:05 PM Ian Rogers wrote: > > > > alias is allocated with malloc allowing uninitialized memory to be > > accessed. The initialization of str was moved late after it could have > > been updated by a JSON event, however, this create a potential for an > > uninitialized use. Fix this by assigning str to NULL early. Testing on > > ARM (Raspberry Pi) showed a memory leak in the same code so add a > > zfree. > > > > Fixes: f63a536f03a2 ("perf pmu: Merge JSON events with sysfs at load time") > > Signed-off-by: Ian Rogers > > Acked-by: Namhyung Kim Thanks, applied. - Arnaldo > Thanks, > Namhyung > > > > --- > > tools/perf/util/pmu.c | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c > > index cde33e01959a..b3f8f3f1e900 100644 > > --- a/tools/perf/util/pmu.c > > +++ b/tools/perf/util/pmu.c > > @@ -532,6 +532,7 @@ static int perf_pmu__new_alias(struct perf_pmu *pmu, const char *name, > > if (!alias) > > return -ENOMEM; > > > > + alias->str = NULL; > > INIT_LIST_HEAD(&alias->terms); > > alias->scale = 1.0; > > alias->unit[0] = '\0'; > > @@ -593,6 +594,7 @@ static int perf_pmu__new_alias(struct perf_pmu *pmu, const char *name, > > ret += scnprintf(newval + ret, sizeof(newval) - ret, > > "%s=%s", term->config, term->val.str); > > } > > + zfree(&alias->str); > > alias->str = strdup(newval); > > if (!pe) > > pmu->sysfs_aliases++; > > -- > > 2.42.0.rc2.253.gd59a3bf2b4-goog > > -- - Arnaldo