From nobody Fri Dec 19 19:17:11 2025 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D321B1A0BFB for ; Wed, 8 Jan 2025 05:15:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736313321; cv=none; b=CR4/WzELzJsqZDITEwdRpIPBt+RgqlbMkLqKTSxM6l4+45ofYWYuMKqgsd0vcyhSTHx3Bqdo5b54mT8JdgpL3VMy4h46qX3INDJpLQjKHye4Xxawj5WM2NE9kzZqk6nLkjoKjpNqjAOSHbvTbiUMNgflXJgKlZIO+8fhob0pWwI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736313321; c=relaxed/simple; bh=+FUIceUBljXQwmCRFhOHGxWwPSQm0aXXrH6E+PxuQOg=; h=Date:Message-Id:Mime-Version:Subject:From:To:Content-Type; b=RXK1hWcfgc5rzBHAKFNxElqXZOjKDQSMoR2Nh1yAuul1+sheec4SmKrfluXaIqDpNgqrn20JnbSpz4vb+OpNzAvzXNFOoAtTI9X4+7nWaCmmwCjy2+iqbwT2eEPAuZnPdTXvipXzOyz7zzghi+F7WpDdlXR/vxSNZf9/ENMeUKE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=mK97ONhd; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="mK97ONhd" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e5382ab0b41so14370324276.2 for ; Tue, 07 Jan 2025 21:15:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736313317; x=1736918117; darn=vger.kernel.org; h=to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=AT8iEH9vJtkOa5w38JMpGTjeNCZxlcDJNjwk/k3hwYw=; b=mK97ONhdNr5TPaEV4cerpriclyT2U01frSEJ21YTdvi9uzJsdsxl40SDgv+na72zRf 0ScTz5ziAKDxeGWoPm7QLLv7sOa9+bUV28Humx+RRgHKUO6VA+sm44VTHcZGbP0qDdug TiD5r17lNhV8nVZk+rHyXbeseAvdqtjZJ+GGilKR6OoJLuRwHC5fGGzLVGbEAlz4ocYC s6vQmdPtsqBJo27RFRwCPLaO+M1I+EGXkzFuKX4Mh4nBPJdq/08DoP/G2PK8MNurF6qS Z1LZg60he9G/xzNKRZgjZNYt5Dtgd8lmJNGM5QAuQNCchPl32v3ZBfn84tNJlNAUQGA6 SzhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736313317; x=1736918117; h=to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=AT8iEH9vJtkOa5w38JMpGTjeNCZxlcDJNjwk/k3hwYw=; b=qzBSL2uRqtadD4+XR4Ih7Is10u5j70SQrk2+ebwDZId7wJQMD52ITVbc0Cq0cU9QYB 3E4bpUvZUbRLL6xUx1Gj1vSun4TfWYZEw95oLmDnb12EPC6vgvTTrgPe2pBIPImnC09N n0jLBE7H9rzyY6Ps564SANjEyQwHP1YsAfAQOxx/GI7cc3QgqovwVEGj2L40bHro1kNV UzCuRTc26IQwKa51smFZ/n9vjGQ9ZnuaZ9u16eOaatvvSkDcfbg7EmOmf1rz2qG0JaVC O4+HFmAz3HLUlkNB/npt7Qu5GYishZAkWo2b6+3pVteeu1luLZSCt4QjBomBQ0w99wPJ 6PSw== X-Forwarded-Encrypted: i=1; AJvYcCWGbZ+lyXic0A0/n5jXRZF3oO9te4Th1cMqIivbHVnUuoyZI5Uy4keAkARWlNGyoqiizDHj3qURDGoYICw=@vger.kernel.org X-Gm-Message-State: AOJu0YzTAmiLQhoDi0SqlF56WSPCWW4aZQuSRAMfSqXzBHUuQlqjuCZK eqaSDhAfDWvMpUiu2YaRXK7AJ8fcauJwzxlXhYeJOH3dJTAzUj+EXAVuMd2YUf2g2tLIXxX96FG oROHh+g== X-Google-Smtp-Source: AGHT+IEJWREqN4VCs2OVQHrtGO7R0c+il2ZFdztGbPuyEp2GXh7uA8jD6ma9Y6eTpk/ZgN9UiEYm8mg9ZXMu X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:7ae:a887:5504:e3ca]) (user=irogers job=sendgmr) by 2002:a25:d8cb:0:b0:e39:3168:53be with SMTP id 3f1490d57ef6-e54ee2330f6mr3853276.9.1736313317666; Tue, 07 Jan 2025 21:15:17 -0800 (PST) Date: Tue, 7 Jan 2025 21:15:11 -0800 Message-Id: <20250108051511.1720369-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Subject: [PATCH v1] perf test cpumap: Avoid use-after-free following merge From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Leo Yan , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Previously cpu maps in the test weren't modified by calls to the cpu map API, however, perf_cpu_map__merge was modified so the left hand argument was updated. In the test this meant the maps copy of the "two" map was put/deleted in the merge meaning when accessed via maps, the pointer was stale and to the put/deleted memory. To fix this add an extra layer of indirection to the maps array, so the updated value of two is accessed. Fixes: a9d2217556f7 ("libperf cpumap: Refactor perf_cpu_map__merge()") Signed-off-by: Ian Rogers Reviewed-by: James Clark --- tools/perf/tests/cpumap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/perf/tests/cpumap.c b/tools/perf/tests/cpumap.c index 5ed7ff072ea3..2354246afc5a 100644 --- a/tools/perf/tests/cpumap.c +++ b/tools/perf/tests/cpumap.c @@ -252,16 +252,16 @@ static int test__cpu_map_equal(struct test_suite *tes= t __maybe_unused, int subte struct perf_cpu_map *empty =3D perf_cpu_map__intersect(one, two); struct perf_cpu_map *pair =3D perf_cpu_map__new("1-2"); struct perf_cpu_map *tmp; - struct perf_cpu_map *maps[] =3D {empty, any, one, two, pair}; + struct perf_cpu_map **maps[] =3D {&empty, &any, &one, &two, &pair}; =20 for (size_t i =3D 0; i < ARRAY_SIZE(maps); i++) { /* Maps equal themself. */ - TEST_ASSERT_VAL("equal", perf_cpu_map__equal(maps[i], maps[i])); + TEST_ASSERT_VAL("equal", perf_cpu_map__equal(*maps[i], *maps[i])); for (size_t j =3D 0; j < ARRAY_SIZE(maps); j++) { /* Maps dont't equal each other. */ if (i =3D=3D j) continue; - TEST_ASSERT_VAL("not equal", !perf_cpu_map__equal(maps[i], maps[j])); + TEST_ASSERT_VAL("not equal", !perf_cpu_map__equal(*maps[i], *maps[j])); } } =20 @@ -274,7 +274,7 @@ static int test__cpu_map_equal(struct test_suite *test = __maybe_unused, int subte perf_cpu_map__put(tmp); =20 for (size_t i =3D 0; i < ARRAY_SIZE(maps); i++) - perf_cpu_map__put(maps[i]); + perf_cpu_map__put(*maps[i]); =20 return TEST_OK; } --=20 2.47.1.613.gc27f4b7a9f-goog