Anton Blanchard discovered that when he ran a simple example of
evt2raw on a POWER7 machine, he got a seg fault in libpfm because
libpfm checked the size field of the perf_event_attr struct, and
if it's non-zero, it uses that size to memset the struct to all
zeros.  If the size is garbage (a large number), memset will write
past the end of the structure, corrupting memory, and possibly
causing a seg fault.

This patch corrects that by initializing the size field to the
size of the perf_event_addr_struct which is being passed in.  This
should be the safest route.

Reported-by: Anton Blanchard <an...@au1.ibm.com>
Signed-off-by: Corey Ashford <cjash...@linux.vnet.ibm.com>
---
 perf_examples/evt2raw.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/perf_examples/evt2raw.c b/perf_examples/evt2raw.c
index 7d11598..7565ce9 100644
--- a/perf_examples/evt2raw.c
+++ b/perf_examples/evt2raw.c
@@ -66,6 +66,7 @@ main(int argc, char **argv)
                errx(1, "Internal error: pfm_initialize returned %s",
                        pfm_strerror(ret));
 
+       pea.size = sizeof(struct perf_event_attr);
        ret = pfm_get_perf_event_encoding(event_str, PFM_PLM0|PFM_PLM3, &pea,
                &fstr, NULL);
        if (ret != PFM_SUCCESS)
-- 
1.7.0.4


------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
perfmon2-devel mailing list
perfmon2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perfmon2-devel

Reply via email to