From nobody Mon Oct 6 21:00:49 2025 Received: from mail-oa1-f74.google.com (mail-oa1-f74.google.com [209.85.160.74]) (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 D0E4D22FAC3 for ; Thu, 17 Jul 2025 21:02:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752786164; cv=none; b=XD1muddReltT3kMxCFQHL4SbPxQYchXd4yu/b618vTWbXYKNM+9yEtHHdw2pOn2WvWGMVIWNV+0LfdIK2kfb+xXGbJInTRduChifLi/eh+wcO0HapHDW7jkjsCLeBlKSYxcG6nD+QjtzEDyaz3nUBzDUPzOeGJGsf2JSElTTDWQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752786164; c=relaxed/simple; bh=zejmlYNwgS/OQpMHacoEnWFRqhftHB8onU2Qvy6vpsU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=qTjSqSiQZbOPut/LSrAxxkAWB3ughdgsqMfwiDdLoeAPnDwb12oBv1f/v+tl7HiPXpGncF/HaD9xHqmRIteKeQMqAMqel33GcuKQa3GgiAsKX/dSZq/q2XcZ5BW9AziBmF5ZzA7ZccNQuEwZ4FC4j/Ewdww+ynPGGYRqgsXJDOA= 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=j9ilSaMP; arc=none smtp.client-ip=209.85.160.74 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="j9ilSaMP" Received: by mail-oa1-f74.google.com with SMTP id 586e51a60fabf-2eb887a2109so1427256fac.2 for ; Thu, 17 Jul 2025 14:02:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752786162; x=1753390962; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=5dVZGHVi7sQRXRzVKkfTNIiUhn/WdB0GHZb62bnQe1c=; b=j9ilSaMPRHB+DZzYb/SMuDIF0UULb6BkWSNUdI+EdT8bPPRKWBXvNbWvzPTCava9C4 QNWUtVeR7De9Ve/ymmBjvyicp6SLLYSidVcz4SH+HtBAFxO8fK9ubvn3n0b7bZ5D70oU o6d0dw6jYk9xsQ4AcBWeoMx9cXuILOulqrARA/3K/krD8eNDFhxwaKd0bzmCnUjbK82u Q+SmIvGfWkXi85+SPqnQBjykb+7m4xm9NXwScZ4XdIcQwX3BZb16J4ZoSheQnY2ahtbR uNdm5UeRXMkjhM6wuzngNJ1A451VztnwfAe0w0GJt0kYSNZAGd+Qxl6zvON+d4vVT9ob sQ2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752786162; x=1753390962; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5dVZGHVi7sQRXRzVKkfTNIiUhn/WdB0GHZb62bnQe1c=; b=AYLoK3py9u3kiNbHPoDvNEZwUsi7ck76cAS3MMLWrWGOyTkCwo2mdISVJy/B465+uW prkJeEX25wPQ2Awk6arwp2QfbzDNOvmauIH6l79k/z+LjbH67/RKju/Tq3guNxwytwzH Se5GtkmxodPIavVgX8IIivGxIHU52wEamAdT5gje67fEsA8TragHU/YoWcrTtafk0zvF +jo0IRDYGDRLkRVzzR1McYh0VF+34v0KlMQtF2PGf8hLWsFGOjs0i5u9r0EkgkbkQDPP 0/bX6lUFhjW6Wp0xmH76tq5WmoATgPhVhwl00dil3f4t7ibcEKKVSDj63tUtPXIfKPt3 5o6g== X-Forwarded-Encrypted: i=1; AJvYcCUCB0WiS1Q+zjuMId8Fb+G94dFwhC2tdUSuHoI3DcuLp1a8nchrs3Co00ErWboYWyIJNjWU6ZcUiEmcmSw=@vger.kernel.org X-Gm-Message-State: AOJu0Yw5t+Rviwxj+rI11/bpPRfRYcjmZvPH4hZuSYAWbTNzxqSxhFv0 BrRXGc9YPwmU+tZg/WIPCDxJl2Ro67HEi5FbZlPabRMTn3jTy28MA/9Vs0qKu13AeHHlryZQNcY cBvabd+uo2Q== X-Google-Smtp-Source: AGHT+IEf3wLginiuFgPMj/KhLeA3Fl3A4TQMyoFRYUZgHRewuT2Nl/mXUfU8dUFzGBWTIush9hwAag7yKgmI X-Received: from oabna16.prod.google.com ([2002:a05:6870:6c10:b0:2b8:e735:4798]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6870:3048:b0:2d5:2955:aa58 with SMTP id 586e51a60fabf-2ffb1eafd4amr5810811fac.0.1752786161596; Thu, 17 Jul 2025 14:02:41 -0700 (PDT) Date: Thu, 17 Jul 2025 14:02:23 -0700 In-Reply-To: <20250717210233.1143622-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250717210233.1143622-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250717210233.1143622-3-irogers@google.com> Subject: [PATCH v2 02/12] perf stat: Avoid buffer overflow to the aggregation map From: Ian Rogers To: Thomas Falcon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Ben Gainey , James Clark , Howard Chu , Weilin Wang , Levi Yun , "Dr. David Alan Gilbert" , Zhongqiu Han , Blake Jones , Yicong Yang , Anubhav Shelat , Thomas Richter , Jean-Philippe Romain , Song Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" CPUs may be created and passed to perf_stat__get_aggr (via config->aggr_get_id), such as in the stat display should_skip_zero_counter. There may be no such aggr_id, for example, if running with a thread. Add a missing bound check and just create IDs for these cases. Reviewed-by: Thomas Falcon Signed-off-by: Ian Rogers --- tools/perf/builtin-stat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 77e2248fa7fc..73b4521ab8af 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1365,7 +1365,7 @@ static struct aggr_cpu_id perf_stat__get_aggr(struct = perf_stat_config *config, struct aggr_cpu_id id; =20 /* per-process mode - should use global aggr mode */ - if (cpu.cpu =3D=3D -1) + if (cpu.cpu =3D=3D -1 || cpu.cpu >=3D config->cpus_aggr_map->nr) return get_id(config, cpu); =20 if (aggr_cpu_id__is_empty(&config->cpus_aggr_map->map[cpu.cpu])) --=20 2.50.0.727.gbf7dc18ff4-goog