grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Non-static variables and nested function pointers [bug #28392]


From: Grégoire Sutre
Subject: Re: Non-static variables and nested function pointers [bug #28392]
Date: Thu, 24 Dec 2009 04:33:26 +0100
User-agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090707)

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 via email to

[Prev in Thread] Current Thread [Next in Thread]