From: Usama Arif <usama.arif@linux.dev>
To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
namhyung@kernel.org, mark.rutland@arm.com,
alexander.shishkin@linux.intel.com, jolsa@kernel.org,
irogers@google.com, adrian.hunter@intel.com,
james.clark@linaro.org, tglx@kernel.org, bp@alien8.de,
dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com,
ravi.bangoria@amd.com, linux-perf-users@vger.kernel.org,
linux-kernel@vger.kernel.org, rkeilty@meta.com,
atish.patra@linux.dev, dgreid@meta.com, riel@surriel.com,
shakeel.butt@linux.dev, kernel-team@meta.com
Cc: Usama Arif <usama.arif@linux.dev>, stable@vger.kernel.org
Subject: [PATCH] perf/x86/amd/ibs: Don't leak stack contents through PERF_SAMPLE_WEIGHT_STRUCT
Date: Mon, 23 Nov 2026 08:23:15 -0800 [thread overview]
Message-ID: <20261123162315.1142701-1-usama.arif@linux.dev> (raw)
For a load that missed the data cache, perf_ibs_parse_ld_st_data()
reports the miss latency as the sample weight and marks
PERF_SAMPLE_WEIGHT_TYPE as done, so perf_prepare_sample() leaves the
field alone. With PERF_SAMPLE_WEIGHT_STRUCT it writes only var1_dw and
var2_w, but perf_output_sample() copies all 8 bytes of the union into
the ring buffer. var3_w therefore carries whatever was left in the
on-stack struct perf_sample_data in perf_ibs_handle_irq().
CONFIG_INIT_STACK_ALL_ZERO hides this by clearing the struct on entry.
Without it, every such sample hands 2 bytes of kernel stack to user
space. "perf mem record" asks for PERF_SAMPLE_WEIGHT_STRUCT on x86, and
since v6.14 swfilt lets an unprivileged user sample their own tasks with
IBS.
Write var3_w as well.
Fixes: 6b2ae4952ef8 ("perf/x86/amd: Support PERF_SAMPLE_{WEIGHT|WEIGHT_STRUCT}")
Cc: stable@vger.kernel.org
Signed-off-by: Usama Arif <usama.arif@linux.dev>
---
arch/x86/events/amd/ibs.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/x86/events/amd/ibs.c b/arch/x86/events/amd/ibs.c
index 66e67e27224f18..9aa47751b37f6c 100644
--- a/arch/x86/events/amd/ibs.c
+++ b/arch/x86/events/amd/ibs.c
@@ -1376,6 +1376,7 @@ static void perf_ibs_parse_ld_st_data(__u64 sample_type,
if (sample_type & PERF_SAMPLE_WEIGHT_STRUCT) {
data->weight.var1_dw = op_data3.dc_miss_lat;
data->weight.var2_w = op_data.tag_to_ret_ctr;
+ data->weight.var3_w = 0;
} else if (sample_type & PERF_SAMPLE_WEIGHT) {
data->weight.full = op_data3.dc_miss_lat;
}
--
2.53.1-Meta
next reply other threads:[~2026-11-23 16:23 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 16:23 Usama Arif [this message]
2026-11-23 16:31 ` [PATCH] perf/x86/amd/ibs: Don't leak stack contents through PERF_SAMPLE_WEIGHT_STRUCT sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261123162315.1142701-1-usama.arif@linux.dev \
--to=usama.arif@linux.dev \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=atish.patra@linux.dev \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=dgreid@meta.com \
--cc=hpa@zytor.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=ravi.bangoria@amd.com \
--cc=riel@surriel.com \
--cc=rkeilty@meta.com \
--cc=shakeel.butt@linux.dev \
--cc=stable@vger.kernel.org \
--cc=tglx@kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox