From: Frederik Deweerdt <deweerdt@free.fr>
To: Andrew Morton <akpm@osdl.org>
Cc: Jeremy Fitzhardinge <jeremy@goop.org>, linux-kernel@vger.kernel.org
Subject: Re: [-mm patch] ptrace: make {put,get}reg work again for gs and fs
Date: Fri, 22 Dec 2006 06:06:18 +0000 [thread overview]
Message-ID: <20061222060618.GD18827@slug> (raw)
In-Reply-To: <20061221181108.6cede9ba.akpm@osdl.org>
On Thu, Dec 21, 2006 at 06:11:08PM -0800, Andrew Morton wrote:
> On Thu, 21 Dec 2006 18:00:49 -0800
> Jeremy Fitzhardinge <jeremy@goop.org> wrote:
>
> > Frederik Deweerdt wrote:
> > > This is a -mm1 kernel + your efl_offset fix + the attached patch.
> > > So the problem came from putreg still saving %gs to the stack where
> > > there's no slot for it, whereas getreg got things right.
> > >
> >
> > That patch looks good, but I think it is already effectively in Andrew's
> > queue, because I noticed some problems in there when I reviewed the
> > convert-to-%fs patch.
> >
>
> The below is what I have queued for urgent mainlining to address these
> problems.
>
> Is it sufficient?
>
No, it's not. The patch below fixes the place where we get eflags, this
triggered the "BUG while gdb'ing" reports.
The one I sent was to fix a problem that only I reported, AFAIK: when
you use gdb/ptrace to modify %fs, the value gets written in the wrong
place (see gdb sessions). So, unless you have another patch fixing the
way putreg() writes %fs, the patch[1] I sent should also be queued for
mainline.
Regards,
Frederik
[1] http://lkml.org/lkml/2006/12/21/267
>
>
>
> From: Jeremy Fitzhardinge <jeremy@goop.org>
>
> 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>
> ---
>
> arch/i386/kernel/ptrace.c | 21 ++++++++++-----------
> 1 file changed, 10 insertions(+), 11 deletions(-)
>
> diff -puN arch/i386/kernel/ptrace.c~ptrace-fix-efl_offset-value-according-to-i386-pda-changes arch/i386/kernel/ptrace.c
> --- a/arch/i386/kernel/ptrace.c~ptrace-fix-efl_offset-value-according-to-i386-pda-changes
> +++ a/arch/i386/kernel/ptrace.c
> @@ -45,7 +45,7 @@
> /*
> * Offset of eflags on child stack..
> */
> -#define EFL_OFFSET ((EFL-2)*4-sizeof(struct pt_regs))
> +#define EFL_OFFSET offsetof(struct pt_regs, eflags)
>
> static inline struct pt_regs *get_child_regs(struct task_struct *task)
> {
> @@ -54,24 +54,24 @@ static inline struct pt_regs *get_child_
> }
>
> /*
> - * this routine will get a word off of the processes privileged stack.
> - * the offset is how far from the base addr as stored in the TSS.
> - * this routine assumes that all the privileged stacks are in our
> + * This routine will get a word off of the processes privileged stack.
> + * the offset is bytes into the pt_regs structure on the stack.
> + * This routine assumes that all the privileged stacks are in our
> * data space.
> */
> static inline int get_stack_long(struct task_struct *task, int offset)
> {
> unsigned char *stack;
>
> - stack = (unsigned char *)task->thread.esp0;
> + stack = (unsigned char *)task->thread.esp0 - sizeof(struct pt_regs);
> stack += offset;
> return (*((int *)stack));
> }
>
> /*
> - * this routine will put a word on the processes privileged stack.
> - * the offset is how far from the base addr as stored in the TSS.
> - * this routine assumes that all the privileged stacks are in our
> + * This routine will put a word on the processes privileged stack.
> + * the offset is bytes into the pt_regs structure on the stack.
> + * This routine assumes that all the privileged stacks are in our
> * data space.
> */
> static inline int put_stack_long(struct task_struct *task, int offset,
> @@ -79,7 +79,7 @@ static inline int put_stack_long(struct
> {
> unsigned char * stack;
>
> - stack = (unsigned char *) task->thread.esp0;
> + stack = (unsigned char *)task->thread.esp0 - sizeof(struct pt_regs);
> stack += offset;
> *(unsigned long *) stack = data;
> return 0;
> @@ -114,7 +114,7 @@ static int putreg(struct task_struct *ch
> }
> if (regno > ES*4)
> regno -= 1*4;
> - put_stack_long(child, regno - sizeof(struct pt_regs), value);
> + put_stack_long(child, regno, value);
> return 0;
> }
>
> @@ -137,7 +137,6 @@ static unsigned long getreg(struct task_
> default:
> if (regno > ES*4)
> regno -= 1*4;
> - regno = regno - sizeof(struct pt_regs);
> retval &= get_stack_long(child, regno);
> }
> return retval;
> _
>
>
next prev parent reply other threads:[~2006-12-22 6:08 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-12-15 6:59 2.6.20-rc1-mm1 Andrew Morton
2006-12-15 6:59 ` BUG: NMI Watchdog detected LOCKUP (was: 2.6.20-rc1-mm1) Tilman Schmidt
2006-12-19 18:52 ` Thomas Gleixner
2006-12-19 19:56 ` [patch] hrtimers: add state tracking, fix Ingo Molnar
2006-12-20 1:38 ` Tilman Schmidt
2006-12-20 20:05 ` Tilman Schmidt
2006-12-15 14:46 ` OOPS: deref 0x14 at pdc_port_start+0x82 [Was: 2.6.20-rc1-mm1] Jiri Slaby
2006-12-15 19:24 ` Andrew Morton
2006-12-15 22:49 ` Jiri Slaby
2006-12-15 20:39 ` 2.6.20-rc1-mm1 Damien Wyart
2006-12-15 21:01 ` 2.6.20-rc1-mm1 Andrew Morton
2006-12-17 11:07 ` 2.6.20-rc1-mm1 Damien Wyart
2006-12-18 8:03 ` 2.6.20-rc1-mm1 Laurent Riffard
2006-12-18 18:35 ` 2.6.20-rc1-mm1 Damien Wyart
2006-12-19 23:29 ` 2.6.20-rc1-mm1 Luben Tuikov
2006-12-18 7:44 ` 2.6.20-rc1-mm1 Jens Axboe
2006-12-15 23:26 ` WARNING (1) at .../arch/i386/mm/highmem.c:49 [Was: 2.6.20-rc1-mm1] Jiri Slaby
2006-12-16 0:16 ` Andrew Morton
2006-12-16 0:04 ` 2.6.20-rc1-mm1: unused sysrq_timer_list_show() Adrian Bunk
2006-12-16 7:56 ` [patch] debugging feature: SysRq-Q to print timers Ingo Molnar
2006-12-18 23:31 ` Andrew Morton
2006-12-18 23:45 ` Dave Jones
2006-12-19 0:00 ` Andrew Morton
2006-12-19 12:01 ` Ingo Molnar
2006-12-16 12:37 ` (Cross) compiling fails on first try (was Re: 2.6.20-rc1-mm1) Jan Dittmer
2006-12-16 13:56 ` [-mm patch] drivers/ide/pci/tc86c001.c: make a function static Adrian Bunk
2006-12-16 14:18 ` Alan
2006-12-17 18:08 ` Sergei Shtylyov
2006-12-17 20:52 ` Sergei Shtylyov
2006-12-16 13:56 ` [-mm patch] make uio_irq_handler() static Adrian Bunk
2006-12-20 6:09 ` Greg KH
2006-12-16 13:56 ` [-mm patch] drivers/video/{s3fb,svgalib}.c: possible cleanups Adrian Bunk
2006-12-16 17:39 ` Randy Dunlap
2006-12-16 18:16 ` Ondrej Zajicek
2006-12-16 13:57 ` [-mm patch] mm/vmscan.c: make a function static Adrian Bunk
2006-12-16 19:30 ` [-mm patch] noinitramfs cleanup Frederik Deweerdt
2006-12-18 13:38 ` [-mm patch] kill pxa2xx Kconfig warning Frederik Deweerdt
2006-12-18 20:06 ` 2.6.20-rc1-mm1 Bartlomiej Zolnierkiewicz
2006-12-19 0:29 ` 2.6.20-rc1-mm1 Randy Dunlap
2006-12-19 0:42 ` 2.6.20-rc1-mm1 Andrew Morton
2006-12-21 18:35 ` [-mm patch] ptrace: make {put,get}reg work again for gs and fs Frederik Deweerdt
2006-12-21 19:22 ` Jeremy Fitzhardinge
2006-12-21 20:53 ` Frederik Deweerdt
2006-12-21 21:59 ` Frederik Deweerdt
2006-12-22 2:00 ` Jeremy Fitzhardinge
[not found] ` <20061221181108.6cede9ba.akpm@osdl.org>
2006-12-22 6:06 ` Frederik Deweerdt [this message]
[not found] ` <20061221225414.de09c7df.akpm@osdl.org>
2006-12-22 7:00 ` Jeremy Fitzhardinge
2006-12-22 8:05 ` Frederik Deweerdt
2006-12-22 6:52 ` Jeremy Fitzhardinge
2006-12-22 6:55 ` Jeremy Fitzhardinge
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20061222060618.GD18827@slug \
--to=deweerdt@free.fr \
--cc=akpm@osdl.org \
--cc=jeremy@goop.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox