Messages in this thread Patch in this message | | | Date | Fri, 7 May 2010 17:28:35 +0200 | From | Robert Richter <> | Subject | [PATCH] perf: fix raw sample size if no sampling data is attached |
| |
On 19.04.10 14:19:57, Stephane Eranian wrote: > > + perf_sample_data_init(&data, 0); > > + if (event->attr.sample_type & PERF_SAMPLE_RAW) { > > + for (i = 1; i < size; i++) > > + rdmsrl(msr++, *buf++); > > + raw.size = sizeof(u64) * size; > > + raw.data = buffer; > > + data.raw = &raw; > > + } > > + > > Need to add the padding: raw.size = sizeof(u64) * size + sizeof(u32); > > > + regs = *iregs; /* later: update ip from ibs sample */ > > + > > + if (perf_event_overflow(event, 1, &data, ®s))
During code review I found a bug in perf_output_sample(). A fix is below.
> > + x86_pmu_stop(event); > > + else > > + __x86_pmu_enable_event(&event->hw, reenable); > > + > > + return 1; > > +}
--
From 6373951f1c660400650066b73c3bb2f6d232be67 Mon Sep 17 00:00:00 2001 From: Robert Richter <robert.richter@amd.com> Date: Fri, 7 May 2010 15:49:56 +0200 Subject: [PATCH] perf: fix raw sample size if no sampling data is attached
The header size of a raw sample is not included in the total size of a raw data sample. Thus, if no data is attached the size must be null. In this case a buffer overflow may occur when copying the sampling data.
Signed-off-by: Robert Richter <robert.richter@amd.com> --- kernel/perf_event.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/kernel/perf_event.c b/kernel/perf_event.c index 9dbe8cd..f6ddae9 100644 --- a/kernel/perf_event.c +++ b/kernel/perf_event.c @@ -3229,7 +3229,7 @@ void perf_output_sample(struct perf_output_handle *handle, u32 size; u32 data; } raw = { - .size = sizeof(u32), + .size = 0, .data = 0, }; perf_output_put(handle, raw); -- 1.7.0.3 -- Advanced Micro Devices, Inc. Operating System Research Center email: robert.richter@amd.com
-- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |