How to randomly remap the kernel?
Page 1 of 1

Author:  zaptor [ Wed Aug 08, 2018 2:30 am ]
Post subject:  How to randomly remap the kernel?

I understand how to identity map the kernel - just map the physical addresses of the kernel code to the same virtual addresses in your page tables and then set cr3 to these page tables and everything works.

My question is, how do you remap the kernel code to a different (potentially random) place in virtual memory? If you change the virtual address, the next instruction after the page table is updated will immediately seg fault as the instruction pointer is invalid. It seems impossible to change the virtual address of the kernel code.

In this case, must you copy the kernel byte code to some different physical address and then map the original address of the kernel as a virtual address to this new physical address? Basically you can only randomize the physical location of the kernel in ram. What are the advantages/disadvantages of doing this?

Author:  iansjack [ Wed Aug 08, 2018 3:15 am ]
Post subject:  Re: How to randomly remap the kernel?

Your boot loader can create the page map, load the kernel to the appropriate location and then, as it's last instruction, far jump to the kernel code.

Author:  Velko [ Wed Aug 08, 2018 5:26 am ]
Post subject:  Re: How to randomly remap the kernel?

First you map it to the new location, but keep the original mapping intact. Then jmp to the new location. And finally - remove the mappings of the old addresses.

Note, that if you want to place the code at random location, it has to be compiled/linked as PIC code.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group