Let's say I have a running program, and I look at /proc/[pid]/map in BSD (or /proc/[pid]/maps in linux), I'll see a line like:
0xbfbe0000 0xbfc00000 3 0 0xc74c4198 rwx 1 0 0x3000 COW NNC default - CH 1001
which is the stack. All my PC-BSD programs use this same stack boundary 0xbfc00000. On linux, with ASLR turned off, a similar thing happens.
I would like to play with these settings on some programs, but the stack doesn't even seem to be specified in the elf program headers or section headers.
So if I want to change the settings, such as:
Is there a way to change the "stack setting" for an individual program? How about system wide?
For FreeBSD:
On amd64, i386 and powerpc you can control wether the stack is executable with the sysctls kern.elf32.nxstack
and kern.elf64.nxstack
(since FreeBSD 9.0).
You can use limits(1)
to start a program with a different stack size, or use login.conf(5)
to set the limits for different classes of users. The stack boundary looks hard-coded in the kernel. See the field sv_usrstack
of the struct sysentvec
for your architecture.
Edit
Your program can request a larger maximum stack size by using setrlimit(2)
.
The GNU linker supports a --stack
option, but according to the manual page;
This option is specific to the i386 PE targeted port of the linker
So this only works on windows.