I have read about ASLR and understand that it randomizes the location in memory where an executable is loaded every time it is run.
But I have a doubt, take an example of an elf executable. It tells where the program should be loaded in virtual memory, at what virtual memory address it should be loaded. Let us take for example a program that should be loaded at va 0x00000040 and it is necessary for it to be loaded there because if it made a jmp
call or anything related to where the memory address linker had put the address in reference with where it is loaded.
If the program is loaded at va 0x40 and link address is also 0x40 and instruction there is to jmp to 0x45
if program is loaded at va 0x40 then jmp
will be at right place, but imagine if the program is loaded at address 0x100 than jmp 0x45
is not where it should jmp
.
How does ASLR do this?