All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Grégoire Sutre" <gregoire.sutre@labri.fr>
To: The development of GNU GRUB <grub-devel@gnu.org>
Subject: Re: Non-static variables and nested function pointers [bug #28392]
Date: Thu, 24 Dec 2009 04:33:26 +0100	[thread overview]
Message-ID: <4B32E106.60608@labri.fr> (raw)
In-Reply-To: <alpine.GSO.2.00.0912231806450.12423@oretfbsg.Jrfg.Fha.PBZ>

Seth Goldberg wrote:

>  Exactly -- the presence of the execstack attribute in the segment is 
> merely a request -- the kernel is free to discard it, and many OSes do, 
> as you've found :).

The problem is more complex: I tried a simple example with a pointer to 
a nested function, and it runs without any segfault on NetBSD/i386.
This would suggest that, by default, the stack is executable -- at least 
if trampolines are used?

The same example segfaults on Debian/amd64 if compiled with 
-Wl,-z,noexecstack (and does not segfault otherwise).

After some digging, I found threads in the archives of the mailing list 
on the problem of executable stack on NetBSD. This led to a patch that 
is now part of trunk if I'm not mistaken.

http://lists.gnu.org/archive/html/grub-devel/2008-02/msg00095.html

I will try to test on NetBSD/amd64 and report here (in a few days), as 
NetBSD's support for non-executable stack and heap seems better on amd64.

Grégoire


#include <stdio.h>

int apply(void (*hook) (int *))
{
    int a = 0;
    hook(&a);
    hook(&a);
    return a;
}

int main (int argc, char *argv[])
{
    int j = 5;
    int res;

    void hook(int *n)
    {
       *n = *n + j;
       j--;
    }

    res = apply(hook);
    printf("result: %d, j=%d\n", res, j);
    return 0;
}



  reply	other threads:[~2009-12-24  3:33 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-23 20:48 Non-static variables and nested function pointers [bug #28392] Grégoire Sutre
2009-12-23 22:17 ` Seth Goldberg
2009-12-24  1:56   ` Grégoire Sutre
2009-12-24  2:07     ` Seth Goldberg
2009-12-24  3:33       ` Grégoire Sutre [this message]
2009-12-24  3:50         ` Seth Goldberg
2009-12-24  3:52         ` Seth Goldberg
2009-12-24 22:12   ` Robert Millan
2009-12-26 18:43     ` Grégoire Sutre

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=4B32E106.60608@labri.fr \
    --to=gregoire.sutre@labri.fr \
    --cc=grub-devel@gnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.