0

I have following code:

#include <stdio.h>
#include <stdlib.h>

int main()
{
        int *ptr1 = malloc(16);
        int val1 = 0x12345678;
        printf("stack: %p\nheap: %p\n", &val1, ptr1);
        return 0;
}

Compilation: gcc -fpie -pie main.c

I wanted to test how aslr behaves under debugger, so i started gdb session, broke at main and ran the program. At main I show memory layout using 'info proc mappings': enter image description here

And those values should be randomized as far as i know due to aslr. But every time I re-run the program those values remains the same. I'm using Centos 8, x86_64. I also disabled built-in kernel ASLR by 'echo 0 > /proc/sys/kernel/randomize_va_space', but I don't think it matters.

I also checked if ALSR is enabled using checksec: enter image description here

Is it normal behavior or am I missing something?

EDIT: I saw that when I run binary without gdb everything works totally fine. What can I do to make it work under debugger?

1

To make debugging easier, GDB turns off ASLR by default. To turn it back on, do set disable-randomization off before you start running the program being debugged. See https://sourceware.org/gdb/onlinedocs/gdb/Starting.html for more details.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.