perf/x86/amd/ibs: Don't leak stack contents through PERF_SAMPLE_WEIGHT_STRUCT
Subsystems (3)
PATCH 1/1 perf/x86/amd/ibs: Don't leak stack contents through PERF_SAMPLE_WEIGHT_STRUCT
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.
--- arch/x86/events/amd/ibs.c | 1 + 1 file changed, 1 insertion(+)
arch/x86/events/amd/ibs.c +1 -0
@@ -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; }
Signature · 1 line
2.53.1-Meta
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 14 lines
For a load that missed the data cache,
perf_ibs_parse_ld_st_data()reports the miss latency as the sample weight and marksPERF_SAMPLE_WEIGHT_TYPEas done, soperf_prepare_sample()leaves the field alone. WithPERF_SAMPLE_WEIGHT_STRUCTit writes onlyvar1_dwandvar2_w, butperf_output_sample()copies all 8 bytes of the union into the ring buffer.var3_wtherefore carries whatever was left in the on-stack structperf_sample_datainperf_ibs_handle_irq().
CONFIG_INIT_STACK_ALL_ZEROhides 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 forPERF_SAMPLE_WEIGHT_STRUCTon x86, and since v6.14 swfilt lets an unprivileged user sample their own tasks with IBS.
Quoted 5 lines
Write
var3_was well.Fixes 6b2ae4952ef8 ("perf/x86/amd: Support PERF_SAMPLE_{WEIGHT|WEIGHT_STRUCT}")Signed-off-by Usama Arif <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1