Kernel heap question

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
LIC
Member
Member
Posts: 44
Joined: Mon Jun 04, 2018 8:10 am
Libera.chat IRC: lic

Kernel heap question

Post by LIC »

Hi, I am currently trying to implement a heap for my kernel, however I was wondering about one thing concerning security.
In my kernel, paging is enabled and the heap is going from 0x100000 to 0x150000 in physical memory.
My question is: Is it ok to map all pages concerning heap in the kernel page table at the beginning or is it better/safer to map pages as the heap grows?
I hope my question was clear.
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Re: Kernel heap question

Post by Korona »

Security-wise, this does not make a huge difference. If someone can write to kernel memory (or even read it), the security of the system is compromised anyway.

There are, however, reasons to map not everything at once: doing so will obviously consume more physical memory and it might not be desirable to fix the size of the kernel heap to some smallish number of pages.
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].
songziming
Member
Member
Posts: 70
Joined: Fri Jun 28, 2013 1:48 am
Contact:

Re: Kernel heap question

Post by songziming »

I map all physical memory 1:1 to kernel space (above canonical hole). So kernel heap only need to know which pages belongs to it, no need to map them dynamically.

Kernel space is shared between all processes. If dynamic mapping is used within kernel space, then the kernel have to update every process' page table.
Reinventing the Wheel, code: https://github.com/songziming/wheel
LIC
Member
Member
Posts: 44
Joined: Mon Jun 04, 2018 8:10 am
Libera.chat IRC: lic

Re: Kernel heap question

Post by LIC »

Okay, thank you for your replies!
Post Reply