linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ARM: perf/oprofile: fix off-by-one in stack check
@ 2011-02-08  4:16 Rabin Vincent
  2011-02-08 15:57 ` Will Deacon
  0 siblings, 1 reply; 4+ messages in thread
From: Rabin Vincent @ 2011-02-08  4:16 UTC (permalink / raw)
  To: linux-arm-kernel

Since it's fp - 1 that gets passed back in as tail in the next iteration, we
need to ensure that fp - 1 is not the same as tail in order to avoid a
potential infinite loop in the perf interrupt handler (which has been observed
to occur).  A similar fix seems to be needed in the OProfile code.

Signed-off-by: Rabin Vincent <rabin.vincent@stericsson.com>
---

Do we need to  explicitly check for overflow (buftail.fp - 1 > buftail.fp)
also?  Though this should be already caught by the access check in the next
iteration of the loop.

 arch/arm/kernel/perf_event.c |    2 +-
 arch/arm/oprofile/common.c   |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/kernel/perf_event.c b/arch/arm/kernel/perf_event.c
index 5efa264..dc885f0 100644
--- a/arch/arm/kernel/perf_event.c
+++ b/arch/arm/kernel/perf_event.c
@@ -700,7 +700,7 @@ user_backtrace(struct frame_tail __user *tail,
 	 * Frame pointers should strictly progress back up the stack
 	 * (towards higher addresses).
 	 */
-	if (tail >= buftail.fp)
+	if (tail >= buftail.fp - 1)
 		return NULL;
 
 	return buftail.fp - 1;
diff --git a/arch/arm/oprofile/common.c b/arch/arm/oprofile/common.c
index 8aa9744..67b6b87 100644
--- a/arch/arm/oprofile/common.c
+++ b/arch/arm/oprofile/common.c
@@ -85,7 +85,7 @@ static struct frame_tail* user_backtrace(struct frame_tail *tail)
 
 	/* frame pointers should strictly progress back up the stack
 	 * (towards higher addresses) */
-	if (tail >= buftail[0].fp)
+	if (tail >= buftail[0].fp - 1)
 		return NULL;
 
 	return buftail[0].fp-1;
-- 
1.7.2.dirty

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-02-09 10:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-08  4:16 [PATCH] ARM: perf/oprofile: fix off-by-one in stack check Rabin Vincent
2011-02-08 15:57 ` Will Deacon
2011-02-09  3:56   ` [PATCHv2] " Rabin Vincent
2011-02-09 10:10     ` Will Deacon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).