瀏覽代碼

dumpstack: x86: add "end" parameter to valid_stack_ptr and print_context_stack

- Add "end" parameter to valid_stack_ptr and print_context_stack
 - use sizeof(long) as the size of a word on the stack

Signed-off-by: Alexander van Heukelum <heukelum@fastmail.fm>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Alexander van Heukelum 16 年之前
父節點
當前提交
3a18512db0
共有 2 個文件被更改,包括 14 次插入7 次删除
  1. 13 6
      arch/x86/kernel/dumpstack_32.c
  2. 1 1
      arch/x86/kernel/dumpstack_64.c

+ 13 - 6
arch/x86/kernel/dumpstack_32.c

@@ -28,10 +28,16 @@ void printk_address(unsigned long address, int reliable)
 }
 }
 
 
 static inline int valid_stack_ptr(struct thread_info *tinfo,
 static inline int valid_stack_ptr(struct thread_info *tinfo,
-			void *p, unsigned int size)
+			void *p, unsigned int size, void *end)
 {
 {
 	void *t = tinfo;
 	void *t = tinfo;
-	return	p > t && p <= t + THREAD_SIZE - size;
+	if (end) {
+		if (p < end && p >= (end-THREAD_SIZE))
+			return 1;
+		else
+			return 0;
+	}
+	return p > t && p < t + THREAD_SIZE - size;
 }
 }
 
 
 /* The form of the top of the frame on the stack */
 /* The form of the top of the frame on the stack */
@@ -43,16 +49,17 @@ struct stack_frame {
 static inline unsigned long
 static inline unsigned long
 print_context_stack(struct thread_info *tinfo,
 print_context_stack(struct thread_info *tinfo,
 		unsigned long *stack, unsigned long bp,
 		unsigned long *stack, unsigned long bp,
-		const struct stacktrace_ops *ops, void *data)
+		const struct stacktrace_ops *ops, void *data,
+		unsigned long *end)
 {
 {
 	struct stack_frame *frame = (struct stack_frame *)bp;
 	struct stack_frame *frame = (struct stack_frame *)bp;
 
 
-	while (valid_stack_ptr(tinfo, stack, sizeof(*stack))) {
+	while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
 		unsigned long addr;
 		unsigned long addr;
 
 
 		addr = *stack;
 		addr = *stack;
 		if (__kernel_text_address(addr)) {
 		if (__kernel_text_address(addr)) {
-			if ((unsigned long) stack == bp + 4) {
+			if ((unsigned long) stack == bp + sizeof(long)) {
 				ops->address(data, addr, 1);
 				ops->address(data, addr, 1);
 				frame = frame->next_frame;
 				frame = frame->next_frame;
 				bp = (unsigned long) frame;
 				bp = (unsigned long) frame;
@@ -96,7 +103,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
 
 
 		context = (struct thread_info *)
 		context = (struct thread_info *)
 			((unsigned long)stack & (~(THREAD_SIZE - 1)));
 			((unsigned long)stack & (~(THREAD_SIZE - 1)));
-		bp = print_context_stack(context, stack, bp, ops, data);
+		bp = print_context_stack(context, stack, bp, ops, data, NULL);
 		/*
 		/*
 		 * Should be after the line below, but somewhere
 		 * Should be after the line below, but somewhere
 		 * in early boot context comes out corrupted and we
 		 * in early boot context comes out corrupted and we

+ 1 - 1
arch/x86/kernel/dumpstack_64.c

@@ -141,7 +141,7 @@ print_context_stack(struct thread_info *tinfo,
 
 
 		addr = *stack;
 		addr = *stack;
 		if (__kernel_text_address(addr)) {
 		if (__kernel_text_address(addr)) {
-			if ((unsigned long) stack == bp + 8) {
+			if ((unsigned long) stack == bp + sizeof(long)) {
 				ops->address(data, addr, 1);
 				ops->address(data, addr, 1);
 				frame = frame->next_frame;
 				frame = frame->next_frame;
 				bp = (unsigned long) frame;
 				bp = (unsigned long) frame;