[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20100507152835.GU6450@erda.amd.com>
Date: Fri, 7 May 2010 17:28:35 +0200
From: Robert Richter <robert.richter@....com>
To: Stephane Eranian <eranian@...gle.com>
CC: Peter Zijlstra <a.p.zijlstra@...llo.nl>,
Ingo Molnar <mingo@...e.hu>,
LKML <linux-kernel@...r.kernel.org>
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@....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@....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@....com
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists