Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 8 Dec 2009 20:18:54 +0000 (UTC)
From:      Marius Strobl <marius@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r200272 - in head/sys: sparc64/sparc64 sun4v/sun4v
Message-ID:  <200912082018.nB8KIseI098720@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: marius
Date: Tue Dec  8 20:18:54 2009
New Revision: 200272
URL: http://svn.freebsd.org/changeset/base/200272

Log:
  Add additional checks of the kernel stack addresses in order to
  ensure we don't overrun the end of the call chain.
  
  MFC after:	1 week

Modified:
  head/sys/sparc64/sparc64/stack_machdep.c
  head/sys/sun4v/sun4v/stack_machdep.c

Modified: head/sys/sparc64/sparc64/stack_machdep.c
==============================================================================
--- head/sys/sparc64/sparc64/stack_machdep.c	Tue Dec  8 19:18:32 2009	(r200271)
+++ head/sys/sparc64/sparc64/stack_machdep.c	Tue Dec  8 20:18:54 2009	(r200272)
@@ -36,15 +36,20 @@ __FBSDID("$FreeBSD$");
 #include <machine/stack.h>
 #include <machine/vmparam.h>
 
-static void stack_capture(struct stack *st, struct frame *fp);
+static void stack_capture(struct stack *st, struct frame *frame);
 
 static void
-stack_capture(struct stack *st, struct frame *fp)
+stack_capture(struct stack *st, struct frame *frame)
 {
+	struct frame *fp;
 	vm_offset_t callpc;
 
 	stack_zero(st);
-	while (1) {
+	fp = frame;
+	for (;;) {
+		if (!INKERNEL((vm_offset_t)fp) ||
+		    !ALIGNED_POINTER(fp, uint64_t))
+                        break;
 		callpc = fp->fr_pc;
 		if (!INKERNEL(callpc))
 			break;
@@ -56,6 +61,9 @@ stack_capture(struct stack *st, struct f
 			break;
 		if (stack_put(st, callpc) == -1)
 			break;
+		if (v9next_frame(fp) <= fp ||
+		    v9next_frame(fp) >= frame + KSTACK_PAGES * PAGE_SIZE)
+			break;
 		fp = v9next_frame(fp);
 	}
 }

Modified: head/sys/sun4v/sun4v/stack_machdep.c
==============================================================================
--- head/sys/sun4v/sun4v/stack_machdep.c	Tue Dec  8 19:18:32 2009	(r200271)
+++ head/sys/sun4v/sun4v/stack_machdep.c	Tue Dec  8 20:18:54 2009	(r200272)
@@ -36,20 +36,28 @@ __FBSDID("$FreeBSD$");
 #include <machine/stack.h>
 #include <machine/vmparam.h>
 
-static void stack_capture(struct stack *st, struct frame *fp);
+static void stack_capture(struct stack *st, struct frame *frame);
 
 static void
-stack_capture(struct stack *st, struct frame *fp)
+stack_capture(struct stack *st, struct frame *frame)
 {
+	struct frame *fp;
 	vm_offset_t callpc;
 
 	stack_zero(st);
-	while (1) {
+	fp = frame;
+	for (;;) {
+		if (!INKERNEL((vm_offset_t)fp) ||
+		    !ALIGNED_POINTER(fp, uint64_t))
+                        break;
 		callpc = fp->fr_pc;
 		if (!INKERNEL(callpc))
 			break;
 		if (stack_put(st, callpc) == -1)
 			break;
+		if (v9next_frame(fp) <= fp ||
+		    v9next_frame(fp) >= frame + KSTACK_PAGES * PAGE_SIZE)
+			break;
 		fp = v9next_frame(fp);
 	}
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200912082018.nB8KIseI098720>