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;
}
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel