How to make the stack of a C program executable?

3

Is there a way to make the stack of a C program executable through compilation?

I did

$ gcc -o convert -g convert

and then run

$ readelf -l convert

to check if the stack is executable but the output was:

GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RW  0x4
c
asked on Stack Overflow Mar 26, 2015 by orestiss • edited Sep 9, 2019 by phuclv

2 Answers

2

The correct way to make the stack executable doesn't require that stack canaries be disabled, unlike what the accepted answer suggests.

Here's the correct way:

gcc -z execstack ...

What this does is, the -z option of gcc is passed to the linker [source]:

keyword

-z is passed directly on to the linker along with the keyword keyword. See the section in the documentation of your linker for permitted values and their meanings.

From man ld [source]:

execstack

Marks the object as requiring executable stack.

answered on Stack Overflow Sep 8, 2019 by multithr3at3d
-3

-fno-stack-protector should do the trick for you.


User contributions licensed under CC BY-SA 3.0