From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E463B3002B3; Sat, 12 Sep 2026 07:30:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789198229; cv=none; b=lEvztJ4nPFXmIVkyao53D+4zqCCFcEMtVuw/WHFaXZh1p64oyyrRZ7Hd5pLUWE6f1gozLEZ1WWifd63aJmIOg5BsAZT6jiOdnvvcILOpXojy/ttayPn+wHcQATgE7ogiIBHt120bUEHrpCZL8rbMZhE0sbLTBykPPUOD1cRsPHQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789198229; c=relaxed/simple; bh=72CrTSN858rfk9pNDM+LCL6XteKc4zUPYxLyrSQiKmY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k8pV1F4NHNxEUFERsYemJv6CyTbyEkZXXMxia9zKxQ7MLY4OD5feo+40+JHFgefAm7r/C0w87EkhvBbm6ybUeFRKKZVnrWzH6mTx0sEdT0/NbZ29y7Q8JwaVmsjQtr4aUDRXePc9y+I35gIrTWN+BwI0BRX/eTTzWwBI8ONA9Mg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=2BqNRHj3; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="2BqNRHj3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ADA511F000FF; Sat, 12 Sep 2026 07:30:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789198227; bh=Gtrjy7YEj5ENkg8uXThl2ljkauL2UZSE92xJDeE5f14=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=2BqNRHj3O8/neTyC+RBMekhZoS8qbVWYyzDzN0eqdjLuTTfaBndw6NK5M4WflFHsC 3bMrV1CmH7LfzyJfv+wYpNge84VPXD99DInk1h5kx902yIwyYQ2o9VxP2/qhmABakJ WkFJHLdZE+pxqnQwq4JMPw3RfSnm6iR0auN55Oas= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yu Peng , Namhyung Kim , Sasha Levin Subject: [PATCH 7.2 0337/1815] perf metricgroup: Fix metric expression copy leaks Date: Sat, 12 Sep 2026 08:34:47 +0200 Message-ID: <20260912065656.831465878@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065648.999753832@linuxfoundation.org> References: <20260912065648.999753832@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.2-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yu Peng [ Upstream commit ef3af1df4f3372bd8ad47619452a283048b3bc8d ] metricgroup__copy_metric_events() allocates a new metric expression and duplicates metric_name before linking the expression into the destination metric event. Free new_expr when strdup() fails, and free the duplicated metric_name on the later error paths. Fixes: b85a4d61d302 ("perf metric: Allow modifiers on metrics") Signed-off-by: Yu Peng Signed-off-by: Namhyung Kim Signed-off-by: Sasha Levin --- tools/perf/util/metricgroup.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 69bfa2a723b24..5a60cb95e31c7 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -1693,8 +1693,10 @@ int metricgroup__copy_metric_events(struct evlist *evlist, struct cgroup *cgrp, new_expr->metric_expr = old_expr->metric_expr; new_expr->metric_threshold = old_expr->metric_threshold; new_expr->metric_name = strdup(old_expr->metric_name); - if (!new_expr->metric_name) + if (!new_expr->metric_name) { + free(new_expr); return -ENOMEM; + } new_expr->metric_unit = old_expr->metric_unit; new_expr->runtime = old_expr->runtime; @@ -1707,6 +1709,7 @@ int metricgroup__copy_metric_events(struct evlist *evlist, struct cgroup *cgrp, alloc_size = sizeof(*new_expr->metric_refs); new_expr->metric_refs = calloc(nr + 1, alloc_size); if (!new_expr->metric_refs) { + zfree(&new_expr->metric_name); free(new_expr); return -ENOMEM; } @@ -1723,6 +1726,7 @@ int metricgroup__copy_metric_events(struct evlist *evlist, struct cgroup *cgrp, alloc_size = sizeof(*new_expr->metric_events); new_expr->metric_events = calloc(nr + 1, alloc_size); if (!new_expr->metric_events) { + zfree(&new_expr->metric_name); zfree(&new_expr->metric_refs); free(new_expr); return -ENOMEM; @@ -1733,6 +1737,7 @@ int metricgroup__copy_metric_events(struct evlist *evlist, struct cgroup *cgrp, evsel = old_expr->metric_events[idx]; evsel = evlist__find_evsel(evlist, evsel->core.idx); if (evsel == NULL) { + zfree(&new_expr->metric_name); zfree(&new_expr->metric_events); zfree(&new_expr->metric_refs); free(new_expr); -- 2.53.0