Paging Idea for a Microkernel (not sure if it would work)

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
chrissacchi
Posts: 15
Joined: Sat Sep 15, 2012 5:02 pm
Libera.chat IRC: csacchi

Paging Idea for a Microkernel (not sure if it would work)

Post by chrissacchi »

Note: This may be a bad idea, but I'm not sure... it should *ONLY* work for a microkernel or a similar design...

Idea:

Let's say you have a page directory initialization function that creates a map of the current address space, giving a pointer that can be moved to CR3. What if the page directory for user processes does not map the kernel address space, AKA marking it as not present? On the event of a task switch or a software interrupt, for example, the task switch IRQ handler or the interrupt handler are already placed into user memory, running at CPL=0 when called so they can re-map the kernel-space as present. Once everything needed to be executed in the kernel and user-mode servers has run, the kernel remaps CR3 to not include kernel space every level of the software interrupt or task switch. While the kernel and the servers are communicating (IPC), they don't switch CR3 until they are *completely* finished (no one wants to make the system slower by adding too many CR3 swaps for no good reason).

This would involve work in the kernel to re-map many functions outside of it, which is a good thing for a microkernel design. Of course, there would need to be adequate memory protection for userspace as well.

This is, of course, a theoretical concept at the moment.
https://github.com/christophersacchi/RazorOS
"... you notice that this scanner will... woah!"
"Moving right along!"
"That must be, uh. That must be why we're not shipping Windows 98 yet..."
"Absolutely. Absolutely."
Boris
Member
Member
Posts: 145
Joined: Sat Nov 07, 2015 3:12 pm

Re: Paging Idea for a Microkernel (not sure if it would work

Post by Boris »

So basically you want a " iceberg" design where only the tip of it is permanently mapped ( for interrupts & syscalls )
This can work . But what benefit does it brings you ?
Do you want to save TLB space until the next syscall ?

The only reason I would do that is to be able to hook/mock / sandbox syscalls for a given process.
mariuszp
Member
Member
Posts: 587
Joined: Sat Oct 16, 2010 3:38 pm

Re: Paging Idea for a Microkernel (not sure if it would work

Post by mariuszp »

Then every single address space (of every process) would need to include those interrupt handlers, and since they're in userspace, they could easily be corruped.

My solution to this is that there is only one paging structure per CPU; i.e. there is only one value for CR3 on each CPU, and is never changed. I only change the first PDPT depending on process, which gives 512 GB of virtual userspace memory per process, and that is certainly enough, and avoids the overhead of copying all kernel page structure into every address space. It also avoids the security flaw I mentioned above.
onlyonemac
Member
Member
Posts: 1146
Joined: Sat Mar 01, 2014 2:59 pm

Re: Paging Idea for a Microkernel (not sure if it would work

Post by onlyonemac »

Sounds interesting from a security point of view - only privileged (and presumably trusted) code can enter the kernel address space.
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.

Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Paging Idea for a Microkernel (not sure if it would work

Post by Brendan »

Hi,
onlyonemac wrote:Sounds interesting from a security point of view - only privileged (and presumably trusted) code can enter the kernel address space.
Not really - the "always present" part of the kernel would have to enable/map the majority of the kernel every time the kernel needs to do anything; which means the only time the "temporarily not mapped" part of the kernel would actually be "not present" is when you're running at CPL=3 and wouldn't be able to touch it if it was present.

Essentially; it probably won't be any better for security than a traditional micro-kernel. It'll just be much much slower due to frequent "kernel TLB flush" problems.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply