Re: [PATCH] Fix out-by-one error in traps.c

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Rusty Russell <rusty@...>
Cc: Andrew Morton <akpm@...>, <linux-kernel@...>, lguest <lguest@...>, Frederik Deweerdt <deweerdt@...>, Andi Kleen <ak@...>
Date: Friday, August 31, 2007 - 2:24 pm

On Sat, 1 Sep 2007, Rusty Russell wrote:

Ok, we should fix that. We should just make it look like all other stack 
frames.

There is other code in the kernel that "knows" that all kernel stacks have 
the fields for the user stack return on it, namely the ptrace code etc. 
Now, the initial stack is hopefully never *accessed* by that kind of code, 
but this kind of special-case code is just wrong.


Well, we might as well then just make the code readable instead. IOW, how 
about this one, which just declares a structure that describes the stack 
frame thing? That just makes everything clearer, since we can then use 
"sizeof(that structure)" instead of using the magic "2*sizeof(unsigned 
long)".

		Linus

---
diff --git a/arch/i386/kernel/traps.c b/arch/i386/kernel/traps.c
index cfffe3d..47b0bef 100644
--- a/arch/i386/kernel/traps.c
+++ b/arch/i386/kernel/traps.c
@@ -100,36 +100,45 @@ asmlinkage void machine_check(void);
 int kstack_depth_to_print = 24;
 static unsigned int code_bytes = 64;
 
-static inline int valid_stack_ptr(struct thread_info *tinfo, void *p)
+static inline int valid_stack_ptr(struct thread_info *tinfo, void *p, unsigned size)
 {
 	return	p > (void *)tinfo &&
-		p < (void *)tinfo + THREAD_SIZE - 3;
+		p <= (void *)tinfo + THREAD_SIZE - size;
 }
 
+/* The form of the top of the frame on the stack */
+struct stack_frame {
+	struct stack_frame *next_frame;
+	unsigned long return_address;
+};
+
 static inline unsigned long print_context_stack(struct thread_info *tinfo,
 				unsigned long *stack, unsigned long ebp,
 				struct stacktrace_ops *ops, void *data)
 {
-	unsigned long addr;
-
 #ifdef	CONFIG_FRAME_POINTER
-	while (valid_stack_ptr(tinfo, (void *)ebp)) {
-		unsigned long new_ebp;
-		addr = *(unsigned long *)(ebp + 4);
+	struct stack_frame *frame = (struct stack_frame *)ebp;
+	while (valid_stack_ptr(tinfo, frame, sizeof(*frame))) {
+		struct stack_frame *next;
+		unsigned long addr;
+
+		addr = frame->return_address;
 		ops->address(data, addr);
 		/*
 		 * break out of recursive entries (such as
 		 * end_of_stack_stop_unwind_function). Also,
 		 * we can never allow a frame pointer to
 		 * move downwards!
-	 	 */
-	 	new_ebp = *(unsigned long *)ebp;
-		if (new_ebp <= ebp)
+		 */
+		next = frame->next_frame;
+		if (next <= frame)
 			break;
-		ebp = new_ebp;
+		frame = next;
 	}
 #else
-	while (valid_stack_ptr(tinfo, stack)) {
+	while (valid_stack_ptr(tinfo, stack, sizeof(*stack))) {
+		unsigned long addr;
+
 		addr = *stack++;
 		if (__kernel_text_address(addr))
 			ops->address(data, addr);
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
2.6.23-rc3-mm1, Andrew Morton, (Wed Aug 22, 5:06 am)
Re: 2.6.23-rc3-mm1, , (Wed Aug 29, 10:04 am)
Re: 2.6.23-rc3-mm1 - vdso and gettimeofday issues with glibc, Ulrich Drepper, (Wed Aug 29, 10:46 pm)
oops at sr_block_release [Re: 2.6.23-rc3-mm1], Jiri Slaby, (Tue Aug 28, 7:32 am)
Re: oops at sr_block_release [Re: 2.6.23-rc3-mm1], Andrew Morton, (Tue Aug 28, 10:58 pm)
Re: oops at sr_block_release [Re: 2.6.23-rc3-mm1], Satyam Sharma, (Tue Aug 28, 11:08 am)
Re: oops at sr_block_release [Re: 2.6.23-rc3-mm1], Jiri Slaby, (Tue Aug 28, 11:21 am)
[-mm patch] iwl-base.c bugfixes, Adrian Bunk, (Mon Aug 27, 5:29 pm)
Re: [-mm patch] iwl-base.c bugfixes, Tomas Winkler, (Mon Aug 27, 6:34 pm)
[-mm patch] ivtv-fb.c bugfix, Adrian Bunk, (Mon Aug 27, 5:29 pm)
Re: [v4l-dvb-maintainer] [-mm patch] ivtv-fb.c bugfix, Hans Verkuil, (Tue Aug 28, 2:30 am)
[-mm patch] mousedev.c:mixdev_open_devices() bugfix, Adrian Bunk, (Mon Aug 27, 5:28 pm)
[-mm patch] unexport noautodma, Adrian Bunk, (Mon Aug 27, 5:28 pm)
[-mm patch] remove unwind exports, Adrian Bunk, (Mon Aug 27, 5:27 pm)
2.6.23-rc3-mm1: m32r defconfig compile error, Adrian Bunk, (Mon Aug 27, 5:27 pm)
Re: 2.6.23-rc3-mm1: m32r defconfig compile error, Hirokazu Takata, (Mon Aug 27, 11:50 pm)
[-mm patch] unexport sys_{open,read}, Adrian Bunk, (Mon Aug 27, 5:27 pm)
Re: [-mm patch] unexport sys_{open,read}, Arjan van de Ven, (Mon Aug 27, 6:53 pm)
Re: [-mm patch] unexport sys_{open,read}, Adrian Bunk, (Mon Aug 27, 7:17 pm)
[-mm patch] unexport snd_ctl_elem_{read,write}, Adrian Bunk, (Mon Aug 27, 5:27 pm)
[-mm patch] make do_restart_poll() static, Adrian Bunk, (Mon Aug 27, 5:27 pm)
[-mm patch] remove parport_device_num(), Adrian Bunk, (Mon Aug 27, 5:27 pm)
[-mm patch] make "struct menu_governor" static (again), Adrian Bunk, (Mon Aug 27, 5:27 pm)
X freezes kernel during exit [Re: 2.6.23-rc3-mm1], Jiri Slaby, (Sun Aug 26, 9:04 am)
Re: X freezes kernel during exit [Re: 2.6.23-rc3-mm1], Andrew Morton, (Sun Sep 9, 8:47 am)
Re: X freezes kernel during exit [Re: 2.6.23-rc3-mm1], Dave Airlie, (Tue Sep 11, 11:18 am)
Re: 2.6.23-rc3-mm1, Tilman Schmidt, (Fri Aug 24, 7:27 pm)
Re: 2.6.23-rc3-mm1, Andrew Morton, (Fri Aug 24, 8:07 pm)
Re: 2.6.23-rc3-mm1, Tilman Schmidt, (Fri Aug 24, 8:47 pm)
Re: 2.6.23-rc3-mm1, Andrew Morton, (Fri Aug 24, 11:30 pm)
Re: 2.6.23-rc3-mm1, Dave Jones, (Sat Aug 25, 12:28 am)
Re: 2.6.23-rc3-mm1, Paul Rolland, (Sat Aug 25, 3:55 am)
Re: 2.6.23-rc3-mm1, Tilman Schmidt, (Sat Aug 25, 7:37 pm)
Re: 2.6.23-rc3-mm1, john stultz, (Fri Aug 24, 8:21 pm)
Re: 2.6.23-rc3-mm1, Tilman Schmidt, (Sat Aug 25, 6:39 pm)
Re: 2.6.23-rc3-mm1, Dave Jones, (Fri Aug 24, 8:14 pm)
RE: 2.6.23-rc3-mm1, Pallipadi, Venkatesh, (Fri Aug 24, 8:13 pm)
RE: 2.6.23-rc3-mm1, Pallipadi, Venkatesh, (Fri Aug 24, 8:38 pm)
Re: 2.6.23-rc3-mm1, Tilman Schmidt, (Sat Aug 25, 7:26 pm)
Re: 2.6.23-rc3-mm1, Randy Dunlap, (Sat Aug 25, 7:57 pm)
Re: 2.6.23-rc3-mm1, Tilman Schmidt, (Mon Aug 27, 9:35 am)
2.6.23-rc3-mm1 - irda goes belly up, , (Thu Aug 23, 9:33 am)
Re: 2.6.23-rc3-mm1 - irda goes belly up, Andrew Morton, (Thu Aug 23, 5:16 pm)
[PATCH 1/2] sysctl: Properly register the irda binary sysctl..., Eric W. Biederman, (Thu Aug 23, 11:53 pm)
Re: [PATCH 1/2] sysctl: Properly register the irda binary sy..., Eric W. Biederman, (Sat Aug 25, 8:57 am)
[PATCH] sysctl: Update sysctl_check to handle compiled out c..., Eric W. Biederman, (Sat Aug 25, 2:03 pm)
Re: [PATCH 1/2] sysctl: Properly register the irda binary sy..., Eric W. Biederman, (Sat Aug 25, 1:59 pm)
Re: [PATCH 1/2] sysctl: Properly register the irda binary sy..., Eric W. Biederman, (Tue Aug 28, 5:06 pm)
[PATCH 2/2] sysctl: For irda update sysctl_checks list of bi..., Eric W. Biederman, (Thu Aug 23, 11:55 pm)
Re: 2.6.23-rc3-mm1 - irda goes belly up, Eric W. Biederman, (Thu Aug 23, 11:46 pm)
Re: 2.6.23-rc3-mm1 - irda goes belly up, Eric W. Biederman, (Thu Aug 23, 11:11 pm)
Re: 2.6.23-rc3-mm1 - irda goes belly up, Alexey Dobriyan, (Thu Aug 23, 1:37 pm)
Re: 2.6.23-rc3-mm1 - memory layout change? - lost support f..., Arjan van de Ven, (Fri Aug 24, 12:17 pm)
[-mm patch] enforce noreplace-smp in alternative_instruction..., Frederik Deweerdt, (Wed Aug 22, 4:25 pm)
Re: [-mm patch] enforce noreplace-smp in alternative_instruc..., Jeremy Fitzhardinge, (Thu Aug 23, 7:16 pm)
Re: [-mm patch] enforce noreplace-smp in alternative_instruc..., Frederik Deweerdt, (Fri Aug 24, 2:06 am)
Re: [-mm patch] enforce noreplace-smp in alternative_instruc..., Frederik Deweerdt, (Fri Aug 24, 2:04 am)
Re: [-mm patch] enforce noreplace-smp in alternative_instruc..., Jeremy Fitzhardinge, (Fri Aug 24, 2:46 am)
Re: [-mm patch] enforce noreplace-smp in alternative_instruc..., Frederik Deweerdt, (Fri Aug 24, 4:22 am)
Re: [-mm patch] enforce noreplace-smp in alternative_instruc..., Frederik Deweerdt, (Sat Aug 25, 8:23 am)
Re: [-mm patch] enforce noreplace-smp in alternative_instruc..., Frederik Deweerdt, (Sat Aug 25, 5:14 pm)
Re: [PATCH] Fix lguest page-pinning logic ("lguest: bad stac..., Frederik Deweerdt, (Thu Aug 30, 12:38 pm)
[PATCH] Fix out-by-one error in traps.c, Rusty Russell, (Thu Aug 30, 6:14 pm)
Re: [PATCH] Fix out-by-one error in traps.c, Linus Torvalds, (Fri Aug 31, 12:44 am)
Re: [PATCH] Fix out-by-one error in traps.c, Rusty Russell, (Fri Aug 31, 2:03 am)
Re: [PATCH] Fix out-by-one error in traps.c, Linus Torvalds, (Fri Aug 31, 3:51 am)
Re: [PATCH] Fix out-by-one error in traps.c, Rusty Russell, (Fri Aug 31, 1:37 pm)
Re: [PATCH] Fix out-by-one error in traps.c, Linus Torvalds, (Fri Aug 31, 2:24 pm)
Re: [PATCH] Fix out-by-one error in traps.c, Rusty Russell, (Tue Sep 4, 2:18 pm)
Re: 2.6.23-rc3-mm1: inlining failures in sound/pci/hda/hda_c..., Mariusz Kozlowski, (Wed Aug 22, 4:23 pm)
Re: 2.6.23-rc3-mm1: inlining failures in sound/pci/hda/hda_c..., Mariusz Kozlowski, (Wed Aug 22, 5:18 pm)
Re: 2.6.23-rc3-mm1, Michal Piotrowski, (Wed Aug 22, 10:19 am)
Re: 2.6.23-rc3-mm1, Andrew Morton, (Wed Aug 22, 12:17 pm)
Re: 2.6.23-rc3-mm1, Torsten Kaiser, (Wed Aug 22, 1:24 pm)
Re: 2.6.23-rc3-mm1, Andrew Morton, (Wed Aug 22, 2:14 pm)
Re: 2.6.23-rc3-mm1, Mel Gorman, (Wed Aug 22, 1:17 pm)
Re: 2.6.23-rc3-mm1, Andrew Morton, (Wed Aug 22, 2:10 pm)
Re: 2.6.23-rc3-mm1, Andi Kleen, (Thu Aug 23, 8:07 am)
Re: 2.6.23-rc3-mm1, Mel Gorman, (Thu Aug 23, 12:25 pm)
Re: 2.6.23-rc3-mm1, Andy Whitcroft, (Thu Aug 23, 8:03 am)
Re: 2.6.23-rc3-mm1, Sam Ravnborg, (Thu Aug 23, 8:28 am)
Re: 2.6.23-rc3-mm1, Sam Ravnborg, (Thu Aug 23, 10:24 am)
Re: 2.6.23-rc3-mm1, Andi Kleen, (Thu Aug 23, 8:22 am)
Re: 2.6.23-rc3-mm1, Andy Whitcroft, (Thu Aug 23, 8:34 am)
Re: 2.6.23-rc3-mm1, Mel Gorman, (Thu Aug 23, 7:39 am)
Re: net/ipv4/fib_trie.c - compile error (Re: 2.6.23-rc3-mm1), Paul E. McKenney, (Wed Aug 22, 1:03 pm)
Re: net/ipv4/fib_trie.c - compile error (Re: 2.6.23-rc3-mm1), Jarek Poplawski, (Mon Aug 27, 2:36 am)
Re: net/ipv4/fib_trie.c - compile error (Re: 2.6.23-rc3-mm1), Paul E. McKenney, (Mon Aug 27, 12:23 pm)
Re: 2.6.23-rc3-mm1, Gabriel C, (Wed Aug 22, 9:33 am)
[-mm patch] make types.h usable for non-gcc C parsers, Adrian Bunk, (Mon Aug 27, 5:27 pm)
Re: [-mm patch] make types.h usable for non-gcc C parsers, Andrew Morton, (Tue Aug 28, 3:37 am)
Re: [-mm patch] make types.h usable for non-gcc C parsers, Mike Frysinger, (Tue Aug 28, 1:42 pm)
Re: [-mm patch] make types.h usable for non-gcc C parsers, Randy Dunlap, (Tue Aug 28, 10:40 am)
Re: [-mm patch] make types.h usable for non-gcc C parsers, Michael Matz, (Tue Aug 28, 10:19 am)
Re: [-mm patch] make types.h usable for non-gcc C parsers, Mike Frysinger, (Mon Aug 27, 5:34 pm)
Re: [-mm patch] make types.h usable for non-gcc C parsers, Mike Frysinger, (Mon Aug 27, 5:42 pm)
Re: 2.6.23-rc3-mm1, Andrew Morton, (Wed Aug 22, 12:09 pm)
Re: 2.6.23-rc3-mm1, Gabriel C, (Wed Aug 22, 1:01 pm)
[BUG] 2.6.23-rc3-mm1 - kernel BUG at net/core/skbuff.c:95!, Kamalesh Babulal, (Wed Aug 22, 9:02 am)
[BUG] fs/xfs/xfs_bmap_btree.c:2312: error: 'b' undeclared (f..., Michal Piotrowski, (Wed Aug 22, 6:11 am)
Re: [BUG] fs/xfs/xfs_bmap_btree.c:2312: error: 'b' undeclare..., Michal Piotrowski, (Wed Aug 22, 6:27 am)
Re: 2.6.23-rc3-mm1: net/wireless/rt2x00mac.c build failure, Mariusz Kozlowski, (Wed Aug 22, 3:16 pm)
Re: 2.6.23-rc3-mm1: net/wireless/rt2x00mac.c build failure, John W. Linville, (Wed Aug 22, 3:58 pm)
Re: 2.6.23-rc3-mm1: net/wireless/rt2x00mac.c build failure, Mariusz Kozlowski, (Wed Aug 22, 3:54 pm)
Re: 2.6.23-rc3-mm1: net/wireless/rt2x00mac.c build failure, Rafael J. Wysocki, (Wed Aug 22, 4:22 pm)
Re: 2.6.23-rc3-mm1: kgdb build failure on powerpc, Mariusz Kozlowski, (Wed Aug 22, 3:04 pm)
Re: 2.6.23-rc3-mm1: kgdb build failure on powerpc, Andrew Morton, (Wed Aug 22, 3:47 pm)
Re: [Kgdb-bugreport] 2.6.23-rc3-mm1: kgdb build failure on p..., Pete/Piet Delaney, (Wed Aug 29, 7:43 pm)
Re: [Kgdb-bugreport] 2.6.23-rc3-mm1: kgdb build failure on p..., Pete/Piet Delaney, (Wed Aug 29, 9:19 pm)
Re: [Kgdb-bugreport] 2.6.23-rc3-mm1: kgdb build failure on p..., Pete/Piet Delaney, (Wed Aug 29, 8:05 pm)
Re: 2.6.23-rc3-mm1: WARNING: during resume from suspend on x..., Rafael J. Wysocki, (Wed Aug 22, 1:30 pm)
Re: 2.6.23-rc3-mm1: locking boot-time self-test failure, Mariusz Kozlowski, (Wed Aug 22, 1:26 pm)
Re: 2.6.23-rc3-mm1: locking boot-time self-test failure, Frederik Deweerdt, (Wed Aug 22, 5:27 pm)
Re: 2.6.23-rc3-mm1: fix b43 compilation, Rafael J. Wysocki, (Wed Aug 22, 12:33 pm)
Re: 2.6.23-rc3-mm1: fix b43 compilation, Michael Buesch, (Wed Aug 22, 5:56 pm)
Re: 2.6.23-rc3-mm1: fix b43 compilation, John W. Linville, (Wed Aug 22, 10:56 pm)
Re: 2.6.23-rc3-mm1: fix b43 compilation, Andrew Morton, (Thu Aug 23, 3:07 am)
Re: 2.6.23-rc3-mm1, Randy Dunlap, (Wed Aug 22, 2:03 pm)
Re: 2.6.23-rc3-mm1, Andrew Morton, (Wed Aug 22, 2:32 pm)
Re: 2.6.23-rc3-mm1, Andi Kleen, (Wed Aug 22, 3:38 pm)
Re: 2.6.23-rc3-mm1, Randy Dunlap, (Wed Aug 22, 3:17 pm)
Re: 2.6.23-rc3-mm1, Andi Kleen, (Wed Aug 22, 4:53 pm)