From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.71 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796334752; b=otpQWrYctdVTSeaLuxHe1VSLjd6R7DfRsh54Q9VK6VOJ9wphfS7tsropNRG3tiEWhKes W+5u2dAXZBZfXnPQCPnYeSpxWKBahOTWXpDSju2viAjOA7fykCUGHTHFeDY5O9MEVmxW8 T84H9S70G45N8wf9/RZEH/eRJj84WMwaSbe4JjxbbyioBchVw+b0Cns9PHP6U7BnGEXdY lQh7rtHrryib0ePjk8z37qda7Jc8GgVLr7qfuVpPhqQScc80WOTWrgOZueyoA9I5uiPG2 /pC3Yb0v2EXd/pJaJxCGJre7JzVJXl/pbwSTV3cEytNqU3klHv4OtHyDr4JVNK2OLfQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796334752; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=Fjva0B+Vk3Xdl2GDtdnLyGLyWqWCwRnX4mPINhoyRnk=; b=obFbryYi25HO870+XpL2BZ4s7kn0jia3seRY+FGq10KNv+x3rc4qOvFY1se/tB+8wUJt Bj/koeV6vegcWs3c+UZzT2F8Y3AQIx/aQRBMhHAlQZkNDzhYS/8nR0ZCJKryrCsLgSI3Z 6mZ+kr2ZaCKwlOja+ZqZhAyhWhNHa/94VDaYPLgYMWQBYuxN3cr/1E0iT85Zs+PdQQ1o+ pkfot7uZSNGv5hDrTOIfTR2N0YKimy4jvLoRYSAIx03ETw+Suy0sY67MtijBhgxXsCK+Z lubxs8uLpjIFVOnaZhR7dv0gB13/lZdZk+Eu6ebJr6Xz49AqIbFO5cqhBaINX9+AXiA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=O50lNgqJ; arc=none smtp.remote-ip=74.125.82.71 Received: from mail-dl1-f71.google.com (mail-dl1-f71.google.com [74.125.82.71]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6EC76606A680 for ; Thu, 3 Dec 2026 21:52:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6EC76606A680 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.a=rsa-sha256 header.s=20260707 header.b=O50lNgqJ Received: by mail-dl1-f71.google.com with SMTP id a92af1059eb24-1383723dfddso439959c88.0 for ; Thu, 03 Dec 2026 13:52:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796334751; x=1796939551; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Fjva0B+Vk3Xdl2GDtdnLyGLyWqWCwRnX4mPINhoyRnk=; b=O50lNgqJr7pQGVfU4811uYA+bdfq5LaNG2Ce31uWpQHbf31jt5BPWYZJf3jMKo2q5u 7G3UAykfqy8n+tBWMmGpnM4ZAc8JLdh8Ay4RqHYTkq30wLxWy8wn8lGsWUjvr7L/lVgP by2du8FvBb0vY2HMUPUXxwmhdPd8C2+o2mFAlIEB3SUcaDYQzjlGVeaXOaIqBZmM8P+m aV3TkUMQw9j0e9Uw/taum9DlvyzjZWY/73zw5UxGbZpv7c/96mH5UG9Ew+eJdalvhJbO uVKYyoMuYGFeQm3VRD2WICcXMxvd36HrbYdN5ykk7WG23jwl9Dj+4uNPCvEnNAf3cLXd Uo+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796334751; x=1796939551; h=content-type:cc: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:content-type; bh=Fjva0B+Vk3Xdl2GDtdnLyGLyWqWCwRnX4mPINhoyRnk=; b=THXuEeF25b4NylU5j1Z8yJ7JKr3v/GflHQ35PsUbYCRqcpk07crO/dvnJrUr9oSjH1 Uar61XPdUp6FkOTVntlYpoXbKcybHIGfnXupxB8tSxPEVoMP8RiF0dcPOYP0RyCSSqbc ODhxCKjDv3RmDHckPXW+1Hvm42g9Nn1FX7cnJa7mT6M5WQC21mpgksRVKiG/rm4p+UC3 Y0zcgw6Ygl0rs2akmH2R+8xDmc+K/h0/0neQzPJbXTotiZrthws/EPrcrmzbNVV0RhjK h96qE+gHXK295u11nPTPemAQaUYeTKpjEiCZLfrujawMOuAW+Lka5dCzUbZgLuak5VQO 5TTg== X-Forwarded-Encrypted: i=1; AL+hErHI8o3bchRytA7J2EUHeKAD5tBBACRPeUr7YjAbJ11DUt2i47pxx0RbBi6qtHuqhdImegdttgd9gXTc5jw=@vger.kernel.org X-Gm-Message-State: APuU4Z/Q66z3zsOX9+xBP6Nzvxwd00mKTvN22TmzftRGTp4HKq3lfhz3 hTZ8/ityuziUkMyAAvyYX8Y3NogRbY042/lcNFkDN0gGPmllnjShu+Dlio9r0auwrOMnfVyb32J dTrnyQMqM1Q== X-Received: from dlgn24-n1.prod.google.com ([2002:a05:7022:b198:10b0:1b5:d170:5e1c]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7023:e51:10b0:1b5:10cf:c402 with SMTP id a92af1059eb24-1b5d70cef24mr172083c88.10.1796334751196; Thu, 03 Dec 2026 13:52:31 -0800 (PST) Date: Thu, 3 Dec 2026 13:52:10 -0800 In-Reply-To: <20261203215222.1392035-1-irogers@google.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261203215222.1392035-1-irogers@google.com> X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog Message-ID: <20261203215222.1392035-2-irogers@google.com> Subject: [PATCH v2 01/13] perf off-cpu: Bound callchain length in off_cpu_write() From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark Cc: Athira Rajeev , TAKANO Mitsuhiro , Hang Zhengyang , Howard Chu , Thomas Falcon , Song Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" off_cpu_raw has MAX_STACKS + 5 entries and bpf_map_lookup_elem() copies up to MAX_STACKS frames into &off_cpu_raw[i + 2] (with i == 2, occupying indices 4..35). When a stack trace fills all MAX_STACKS frames, the unbounded while (off_cpu_raw[i + 2 + len]) loop reads off_cpu_raw[36] (which holds the previous sample's cgroup_id) and then reads and writes past the end of off_cpu_raw. Zero the stack buffer before lookup in case bpf_map_lookup_elem() fails and bound len by MAX_STACKS. Fixes: 74069a01609e ("perf record --off-cpu: Dump the remaining PERF_SAMPLE_ in sample_type from BPF's stack trace map") Signed-off-by: Ian Rogers --- tools/perf/util/bpf_off_cpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/bpf_off_cpu.c b/tools/perf/util/bpf_off_cpu.c index 71933a71c8d1..a3fdbc3c907f 100644 --- a/tools/perf/util/bpf_off_cpu.c +++ b/tools/perf/util/bpf_off_cpu.c @@ -399,10 +399,10 @@ int off_cpu_write(struct perf_session *session) /* off_cpu_raw[i] is callchain->nr (updated later) */ off_cpu_raw[i + 1] = PERF_CONTEXT_USER; - off_cpu_raw[i + 2] = 0; + memset(&off_cpu_raw[i + 2], 0, MAX_STACKS * sizeof(u64)); bpf_map_lookup_elem(stack, &key.stack_id, &off_cpu_raw[i + 2]); - while (off_cpu_raw[i + 2 + len]) + while (len < MAX_STACKS && off_cpu_raw[i + 2 + len]) len++; off_cpu_raw[i] = len + 1; -- 2.56.1.915.g69d5ec7298-goog