OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 5:55 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: How to randomly remap the kernel?
PostPosted: Wed Aug 08, 2018 2:30 am 
Offline

Joined: Wed Aug 01, 2018 9:09 pm
Posts: 10
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?


Top
 Profile  
 
 Post subject: Re: How to randomly remap the kernel?
PostPosted: Wed Aug 08, 2018 3:15 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
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.


Top
 Profile  
 
 Post subject: Re: How to randomly remap the kernel?
PostPosted: Wed Aug 08, 2018 5:26 am 
Offline
Member
Member
User avatar

Joined: Fri Oct 03, 2008 4:13 am
Posts: 153
Location: Ogre, Latvia, EU
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.

_________________
If something looks overcomplicated, most likely it is.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], DotBot [Bot], Google [Bot] and 60 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group