mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Richard B. Johnson" <root@chaos.analogic.com>
To: Chris Lattner <sabre@nondot.org>
Cc: Davide Libenzi <davidel@xmailserver.org>, linux-kernel@vger.kernel.org
Subject: Re: [x86] Access off the bottom of stack causes a segfault?
Date: Tue, 14 Oct 2003 15:28:55 -0400 (EDT)	[thread overview]
Message-ID: <Pine.LNX.4.53.0310141521130.2240@chaos> (raw)
In-Reply-To: <Pine.LNX.4.44.0310141358420.4165-100000@nondot.org>

On Tue, 14 Oct 2003, Chris Lattner wrote:

> > > Generated code:
> > >         .intel_syntax
> > > ...
> > > main:
> > >         mov DWORD PTR [%ESP - 16004], %EBP    # Save EBP to stack
> >                          ^^^^^^^^^^^^
> >
> > Yes, this is the problem (even Windows does that IIRC).
>
> Ok, I realize what's going on here.  The question is, why does the linux
> kernel consider this to be a bug?  Where (in the X86 specs) is it
> documented that it's illegal to access off the bottom of the stack?
>
> My compiler does a nice leaf function optimization where it does not even
> bother to adjust the stack for leaf functions, which eliminates the adds
> and subtracts entirely from these (common) functions.  This completely
> invalidates the optimization.
>
> Since I'm going to have to live with lots of preexisting kernels, it looks
> like I'm going to have to disable it entirely, which is disappointing.
> I'm still curious though why this is thought to be illegal.
>
> -Chris

Any interrupt causes the return address to be pushed onto the
stack. This will overwrite any data you've put there. In principle,
in user-mode, you can write below the stack-pointer because an
interrupt uses the kernel stack. However, your data will still
get corrupted by signal delivery, etc. So as to not corrupt your
user-mode stack, the kernel calls your signal code, just like
a nested call. This means the new return address will be below
the non-signal user-mode stack-pointer value. This will surely
corrupt anything you have written below the stack-pointer.


Cheers,
Dick Johnson
Penguin : Linux version 2.4.22 on an i686 machine (797.90 BogoMips).
            Note 96.31% of all statistics are fiction.



  parent reply	other threads:[~2003-10-14 19:27 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-14 18:31 Chris Lattner
2003-10-14 18:37 ` Davide Libenzi
2003-10-14 19:00   ` Chris Lattner
2003-10-14 18:45     ` Davide Libenzi
2003-10-14 19:28     ` Richard B. Johnson [this message]
2003-10-14 19:48       ` Chris Lattner
2003-10-17 23:55         ` Jamie Lokier
2003-10-14 20:47     ` Mikael Pettersson
2003-10-14 18:42 ` Brian Gerst
2003-10-14 18:49 ` Chris Lattner
2003-10-14 18:42   ` Petr Vandrovec
2003-10-14 19:02     ` Chris Lattner
2003-10-14 19:18 ` Richard B. Johnson
2003-10-14 20:43   ` H. Peter Anvin
2003-10-17  0:23 ` Eric W. Biederman

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=Pine.LNX.4.53.0310141521130.2240@chaos \
    --to=root@chaos.analogic.com \
    --cc=davidel@xmailserver.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sabre@nondot.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

all inboxes | Powered by JetHome®