🍗 Wiki

Disable Memory Protection On Linux

Disable Memory Protection On Linux

You would want to disable memory protections for some reasons.

1. GCC

1.1. Disable NXbit

gcc -z execstack

1.2. Stack Boundary Cleanup (Disable SSP)

We usually says that stack frames in the x86 assembly start with the following instructions:

push ebp
mov ebp, esp

But when you write a code and compile it, sometimes you can see the start of a stack frame looks different from what you know:

lea ecx, ebp-4
and esp, 0xfffffff0
pushl ecx-4
push ebp
mov ebp, esp
push ecx

These instructions are to align the stack frame, and actually does nothing but re-aligning stack frame. But that is that, you might want to see only push ebp and mov ebp esp!

Try this:

gcc -mpreferred-stack-boundary=2

1.3. Disable Stack Smash Protector

gcc -fno-stack-protector

1.4. Disable PIE

gcc -no-pie # no pie
gcc -fpie # .text ramdomize
gcc -fpie -pie # PIE

1.5. Disable RELRO

gcc -z relro #Partial RELRO
gcc -z relro -z now #FULL RELRO
gcc -z norelro #NO RELRO

2. Linux Kernel

2.1. Disable ASLR

# echo 0 > /proc/sys/kernel/randomize_va_space

3. See Also