aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorJeremy Fitzhardinge <jeremy@goop.org>2006-12-22 04:11:21 -0500
committerLinus Torvalds <torvalds@woody.osdl.org>2006-12-22 11:55:51 -0500
commit8701ea957dd2a7c309e17c8dcde3a64b92d8aec0 (patch)
tree37019047caf24df91f617677f72b378d1e23d82e /arch
parent7c7e9425f114a109b07be2c2c1c6c169e34e9bb3 (diff)
[PATCH] ptrace: Fix EFL_OFFSET value according to i386 pda changes
The PDA patches introduced a bug in ptrace: it reads eflags from the wrong place on the target's stack, but writes it back to the correct place. The result is a corrupted eflags, which is most visible when it turns interrupts off unexpectedly. This patch fixes this by making the ptrace code a little less fragile. It changes [gs]et_stack_long to take a straightforward byte offset into struct pt_regs, rather than requiring all callers to do a sizeof(struct pt_regs) offset adjustment. This means that the eflag's offset (EFL_OFFSET) on the target stack can be simply computed with offsetof(). Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com> Cc: Frederik Deweerdt <deweerdt@free.fr> Cc: Andi Kleen <ak@suse.de> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'arch')
-rw-r--r--arch/i386/kernel/ptrace.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/arch/i386/kernel/ptrace.c b/arch/i386/kernel/ptrace.c
index f3f94ac5736..af8aabe8580 100644
--- a/arch/i386/kernel/ptrace.c
+++ b/arch/i386/kernel/ptrace.c
@@ -45,7 +45,7 @@
45/* 45/*
46 * Offset of eflags on child stack.. 46 * Offset of eflags on child stack..
47 */ 47 */
48#define EFL_OFFSET ((EFL-2)*4-sizeof(struct pt_regs)) 48#define EFL_OFFSET offsetof(struct pt_regs, eflags)
49 49
50static inline struct pt_regs *get_child_regs(struct task_struct *task) 50static inline struct pt_regs *get_child_regs(struct task_struct *task)
51{ 51{
@@ -54,24 +54,24 @@ static inline struct pt_regs *get_child_regs(struct task_struct *task)
54} 54}
55 55
56/* 56/*
57 * this routine will get a word off of the processes privileged stack. 57 * This routine will get a word off of the processes privileged stack.
58 * the offset is how far from the base addr as stored in the TSS. 58 * the offset is bytes into the pt_regs structure on the stack.
59 * this routine assumes that all the privileged stacks are in our 59 * This routine assumes that all the privileged stacks are in our
60 * data space. 60 * data space.
61 */ 61 */
62static inline int get_stack_long(struct task_struct *task, int offset) 62static inline int get_stack_long(struct task_struct *task, int offset)
63{ 63{
64 unsigned char *stack; 64 unsigned char *stack;
65 65
66 stack = (unsigned char *)task->thread.esp0; 66 stack = (unsigned char *)task->thread.esp0 - sizeof(struct pt_regs);
67 stack += offset; 67 stack += offset;
68 return (*((int *)stack)); 68 return (*((int *)stack));
69} 69}
70 70
71/* 71/*
72 * this routine will put a word on the processes privileged stack. 72 * This routine will put a word on the processes privileged stack.
73 * the offset is how far from the base addr as stored in the TSS. 73 * the offset is bytes into the pt_regs structure on the stack.
74 * this routine assumes that all the privileged stacks are in our 74 * This routine assumes that all the privileged stacks are in our
75 * data space. 75 * data space.
76 */ 76 */
77static inline int put_stack_long(struct task_struct *task, int offset, 77static inline int put_stack_long(struct task_struct *task, int offset,
@@ -79,7 +79,7 @@ static inline int put_stack_long(struct task_struct *task, int offset,
79{ 79{
80 unsigned char * stack; 80 unsigned char * stack;
81 81
82 stack = (unsigned char *) task->thread.esp0; 82 stack = (unsigned char *)task->thread.esp0 - sizeof(struct pt_regs);
83 stack += offset; 83 stack += offset;
84 *(unsigned long *) stack = data; 84 *(unsigned long *) stack = data;
85 return 0; 85 return 0;
@@ -114,7 +114,7 @@ static int putreg(struct task_struct *child,
114 } 114 }
115 if (regno > ES*4) 115 if (regno > ES*4)
116 regno -= 1*4; 116 regno -= 1*4;
117 put_stack_long(child, regno - sizeof(struct pt_regs), value); 117 put_stack_long(child, regno, value);
118 return 0; 118 return 0;
119} 119}
120 120
@@ -137,7 +137,6 @@ static unsigned long getreg(struct task_struct *child,
137 default: 137 default:
138 if (regno > ES*4) 138 if (regno > ES*4)
139 regno -= 1*4; 139 regno -= 1*4;
140 regno = regno - sizeof(struct pt_regs);
141 retval &= get_stack_long(child, regno); 140 retval &= get_stack_long(child, regno);
142 } 141 }
143 return retval; 142 return retval;