* [patch] perf: tui: Fix segfault when drawing out-of-bounds jumps @ 2013-01-12 0:00 Frederik Deweerdt 2013-01-14 13:44 ` Arnaldo Carvalho de Melo 0 siblings, 1 reply; 4+ messages in thread From: Frederik Deweerdt @ 2013-01-12 0:00 UTC (permalink / raw) To: namhyung, acme; +Cc: linux-kernel Hi, When perf.data contains out-of-symbol jumps, annotate_browser__mark_jump_targets() correctly avoids marking out-of-symbol jump targets. However, when moving the cursor on one of said jumps, annotate_browser__draw_current_jump() will end up with a bogus 'target' pointer, causing a bogus memory access when dereferencing 'bcursor' or 'btarget' The following patch performs the same check as mark_jump_targets() in order to avoid drawing the bogus jump. Regards, Frederik Signed-off-by: Frederik Deweerdt <frederik.deweerdt@xprog.eu> diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c index 5dab3ca..8b84246 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -195,8 +195,9 @@ static void annotate_browser__draw_current_jump(struct ui_browser *browser) if (strstr(sym->name, "@plt")) return; - if (!cursor || !cursor->ins || !ins__is_jump(cursor->ins) || - !disasm_line__has_offset(cursor)) + if (!cursor || !cursor->ins || !ins__is_jump(cursor->ins) + || !disasm_line__has_offset(cursor) + || cursor->ops.target.offset >= symbol__size(sym)) return; target = ab->offsets[cursor->ops.target.offset]; ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch] perf: tui: Fix segfault when drawing out-of-bounds jumps 2013-01-12 0:00 [patch] perf: tui: Fix segfault when drawing out-of-bounds jumps Frederik Deweerdt @ 2013-01-14 13:44 ` Arnaldo Carvalho de Melo 2013-01-14 19:47 ` Frederik Deweerdt 0 siblings, 1 reply; 4+ messages in thread From: Arnaldo Carvalho de Melo @ 2013-01-14 13:44 UTC (permalink / raw) To: Frederik Deweerdt; +Cc: namhyung, linux-kernel Em Fri, Jan 11, 2013 at 07:00:43PM -0500, Frederik Deweerdt escreveu: > Hi, > > When perf.data contains out-of-symbol jumps, > annotate_browser__mark_jump_targets() correctly avoids marking > out-of-symbol jump targets. However, when moving the cursor on one of > said jumps, annotate_browser__draw_current_jump() will end up with a > bogus 'target' pointer, causing a bogus memory access when dereferencing > 'bcursor' or 'btarget' > > The following patch performs the same check as mark_jump_targets() > in order to avoid drawing the bogus jump. Thanks, I'll apply this one later today and introduce a disasm_line__is_valid_jump(cursor) routine to be used in both mark and draw routines, if you don't do it first :-) - Arnaldo > Regards, > Frederik > > Signed-off-by: Frederik Deweerdt <frederik.deweerdt@xprog.eu> > > diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c > index 5dab3ca..8b84246 100644 > --- a/tools/perf/ui/browsers/annotate.c > +++ b/tools/perf/ui/browsers/annotate.c > @@ -195,8 +195,9 @@ static void annotate_browser__draw_current_jump(struct ui_browser *browser) > if (strstr(sym->name, "@plt")) > return; > > - if (!cursor || !cursor->ins || !ins__is_jump(cursor->ins) || > - !disasm_line__has_offset(cursor)) > + if (!cursor || !cursor->ins || !ins__is_jump(cursor->ins) > + || !disasm_line__has_offset(cursor) > + || cursor->ops.target.offset >= symbol__size(sym)) > return; > > target = ab->offsets[cursor->ops.target.offset]; ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch] perf: tui: Fix segfault when drawing out-of-bounds jumps 2013-01-14 13:44 ` Arnaldo Carvalho de Melo @ 2013-01-14 19:47 ` Frederik Deweerdt 2013-01-25 11:50 ` [tip:perf/core] perf annotate browser: " tip-bot for Frederik Deweerdt 0 siblings, 1 reply; 4+ messages in thread From: Frederik Deweerdt @ 2013-01-14 19:47 UTC (permalink / raw) To: Arnaldo Carvalho de Melo; +Cc: namhyung, linux-kernel On Mon, Jan 14, 2013 at 10:44:16AM -0300, Arnaldo Carvalho de Melo wrote: > Em Fri, Jan 11, 2013 at 07:00:43PM -0500, Frederik Deweerdt escreveu: > > Hi, > > > > When perf.data contains out-of-symbol jumps, > > annotate_browser__mark_jump_targets() correctly avoids marking > > out-of-symbol jump targets. However, when moving the cursor on one of > > said jumps, annotate_browser__draw_current_jump() will end up with a > > bogus 'target' pointer, causing a bogus memory access when dereferencing > > 'bcursor' or 'btarget' > > > > The following patch performs the same check as mark_jump_targets() > > in order to avoid drawing the bogus jump. > > Thanks, I'll apply this one later today and introduce a > disasm_line__is_valid_jump(cursor) routine to be used in both mark and > draw routines, if you don't do it first :-) I thought of that, but the code currently displays an error message in the mark_jump_targets() case: if (dl->ops.target.offset >= size) { ui__error("jump to after symbol!\n" "size: %zx, jump target: %" PRIx64, size, dl->ops.target.offset); continue; } That said, the message is kind of useless and annoying (happens well over a dozen of times) in the case I hit it (annotate __strstr_sse42). How about the following: Factorize jump sanity checks from mark_jump_targets() and draw_current_jump() in an is_valid_jump() function. This fixes a segfaut when moving the cursor over an invalid jump. Signed-off-by: Frederik Deweerdt <frederik.deweerdt@xprog.eu> diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c index 5dab3ca..43ae4f6 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -182,6 +182,16 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int ab->selection = dl; } +static bool annotate_browser__is_valid_jump(struct symbol *sym, struct disasm_line *dl) +{ + if (!dl || !dl->ins || !ins__is_jump(dl->ins) + || !disasm_line__has_offset(dl) + || dl->ops.target.offset >= symbol__size(sym)) + return false; + + return true; +} + static void annotate_browser__draw_current_jump(struct ui_browser *browser) { struct annotate_browser *ab = container_of(browser, struct annotate_browser, b); @@ -195,8 +205,7 @@ static void annotate_browser__draw_current_jump(struct ui_browser *browser) if (strstr(sym->name, "@plt")) return; - if (!cursor || !cursor->ins || !ins__is_jump(cursor->ins) || - !disasm_line__has_offset(cursor)) + if (!annotate_browser__is_valid_jump(sym, cursor)) return; target = ab->offsets[cursor->ops.target.offset]; @@ -788,17 +797,9 @@ static void annotate_browser__mark_jump_targets(struct annotate_browser *browser struct disasm_line *dl = browser->offsets[offset], *dlt; struct browser_disasm_line *bdlt; - if (!dl || !dl->ins || !ins__is_jump(dl->ins) || - !disasm_line__has_offset(dl)) + if (!annotate_browser__is_valid_jump(sym, dl)) continue; - if (dl->ops.target.offset >= size) { - ui__error("jump to after symbol!\n" - "size: %zx, jump target: %" PRIx64, - size, dl->ops.target.offset); - continue; - } - dlt = browser->offsets[dl->ops.target.offset]; /* * FIXME: Oops, no jump target? Buggy disassembler? Or do we @@ -921,7 +922,7 @@ out_free_offsets: #define ANNOTATE_CFG(n) \ { .name = #n, .value = &annotate_browser__opts.n, } - + /* * Keep the entries sorted, they are bsearch'ed */ ^ permalink raw reply [flat|nested] 4+ messages in thread
* [tip:perf/core] perf annotate browser: Fix segfault when drawing out-of-bounds jumps 2013-01-14 19:47 ` Frederik Deweerdt @ 2013-01-25 11:50 ` tip-bot for Frederik Deweerdt 0 siblings, 0 replies; 4+ messages in thread From: tip-bot for Frederik Deweerdt @ 2013-01-25 11:50 UTC (permalink / raw) To: linux-tip-commits Cc: acme, linux-kernel, frederik.deweerdt, hpa, mingo, tglx, namhyung Commit-ID: 865c66c4183aab1d12522ca3ad3a3339d2437e5c Gitweb: http://git.kernel.org/tip/865c66c4183aab1d12522ca3ad3a3339d2437e5c Author: Frederik Deweerdt <frederik.deweerdt@xprog.eu> AuthorDate: Mon, 14 Jan 2013 14:47:17 -0500 Committer: Arnaldo Carvalho de Melo <acme@redhat.com> CommitDate: Thu, 24 Jan 2013 16:40:36 -0300 perf annotate browser: Fix segfault when drawing out-of-bounds jumps Factorize jump sanity checks from mark_jump_targets() and draw_current_jump() in an is_valid_jump() function. This fixes a segfault when moving the cursor over an invalid jump. Signed-off-by: Frederik Deweerdt <frederik.deweerdt@xprog.eu> Cc: Namhyung Kim <namhyung@kernel.org> Link: http://lkml.kernel.org/r/20130114194716.GA4973@ks398093.ip-192-95-24.net [ committer note: Make it a disasm_line method ] Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> --- tools/perf/ui/browsers/annotate.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c index 5dab3ca..2fc7f04 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -182,6 +182,16 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int ab->selection = dl; } +static bool disasm_line__is_valid_jump(struct disasm_line *dl, struct symbol *sym) +{ + if (!dl || !dl->ins || !ins__is_jump(dl->ins) + || !disasm_line__has_offset(dl) + || dl->ops.target.offset >= symbol__size(sym)) + return false; + + return true; +} + static void annotate_browser__draw_current_jump(struct ui_browser *browser) { struct annotate_browser *ab = container_of(browser, struct annotate_browser, b); @@ -195,8 +205,7 @@ static void annotate_browser__draw_current_jump(struct ui_browser *browser) if (strstr(sym->name, "@plt")) return; - if (!cursor || !cursor->ins || !ins__is_jump(cursor->ins) || - !disasm_line__has_offset(cursor)) + if (!disasm_line__is_valid_jump(cursor, sym)) return; target = ab->offsets[cursor->ops.target.offset]; @@ -788,17 +797,9 @@ static void annotate_browser__mark_jump_targets(struct annotate_browser *browser struct disasm_line *dl = browser->offsets[offset], *dlt; struct browser_disasm_line *bdlt; - if (!dl || !dl->ins || !ins__is_jump(dl->ins) || - !disasm_line__has_offset(dl)) + if (!disasm_line__is_valid_jump(dl, sym)) continue; - if (dl->ops.target.offset >= size) { - ui__error("jump to after symbol!\n" - "size: %zx, jump target: %" PRIx64, - size, dl->ops.target.offset); - continue; - } - dlt = browser->offsets[dl->ops.target.offset]; /* * FIXME: Oops, no jump target? Buggy disassembler? Or do we @@ -921,7 +922,7 @@ out_free_offsets: #define ANNOTATE_CFG(n) \ { .name = #n, .value = &annotate_browser__opts.n, } - + /* * Keep the entries sorted, they are bsearch'ed */ ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-01-25 11:50 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2013-01-12 0:00 [patch] perf: tui: Fix segfault when drawing out-of-bounds jumps Frederik Deweerdt 2013-01-14 13:44 ` Arnaldo Carvalho de Melo 2013-01-14 19:47 ` Frederik Deweerdt 2013-01-25 11:50 ` [tip:perf/core] perf annotate browser: " tip-bot for Frederik Deweerdt
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
Powered by JetHome