Re: [PATCH] perf/x86/amd/ibs: Don't leak stack contents through PERF_SAMPLE_WEIGHT_STRUCT

From: Ravi Bangoria

Date: Fri Nov 27 2026 - 07:18:17 EST


> 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@xxxxxxxxxxxxxxx
> Signed-off-by: Usama Arif <usama.arif@xxxxxxxxx>

Reviewed-by: Ravi Bangoria <ravi.bangoria@xxxxxxx>