[SOLVED] Safe to flag high-level paging structures as USER ?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
wichtounet
Member
Member
Posts: 90
Joined: Fri Nov 01, 2013 4:05 pm
Location: Fribourg, Switzerland
Contact:

[SOLVED] Safe to flag high-level paging structures as USER ?

Post by wichtounet »

Hi,

I'm currently working on multitasking support on my OS and I had to map some pages with USER flag (OR 0x4).

What I've done now is to flag all high level tables (PML4T,PDPT,PDT) entries with USER flag and only the Page Directory entries with either USER or SUPERVISOR depending on the need.

I was wondering if it was safe ? Does that mean that a user could modify paging ? Should I totally separate them, by reserving some entries in each structure for kernel and some other for user mode.

Thank you
Last edited by wichtounet on Sun Jan 19, 2014 2:33 pm, edited 1 time in total.
Thor Operating System: C++ 64 bits OS: https://github.com/wichtounet/thor-os
Good osdeving!
brunexgeek
Member
Member
Posts: 45
Joined: Wed Dec 25, 2013 11:51 am

Re: Is it safe to flag high-level paging structures as USER

Post by brunexgeek »

I don't know the structures used in 64bits (my kernel is 32bits), but if you set the page for page directory as USER and your GDT allows, any user program could change it's entries (e.g. overwrite all page tables references).
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Is it safe to flag high-level paging structures as USER

Post by bluemoon »

brunexgeek wrote:I don't know the structures used in 64bits (my kernel is 32bits), but if you set the page for page directory as USER and your GDT allows, any user program could change it's entries (e.g. overwrite all page tables references).
This is misleading. To alter the content of a page directory/entry, you have to map such content into logical address. The access flag of such address determinate if user may alter that content.

If you happen to use recursive paging method, you may still prevent user modifying page table by having the flag for such logical address (ie. last entry in most tutorials) to supervisor
User avatar
wichtounet
Member
Member
Posts: 90
Joined: Fri Nov 01, 2013 4:05 pm
Location: Fribourg, Switzerland
Contact:

Re: Is it safe to flag high-level paging structures as USER

Post by wichtounet »

bluemoon wrote:If you happen to use recursive paging method, you may still prevent user modifying page table by having the flag for such logical address (ie. last entry in most tutorials) to supervisor
I don't use the recursive paging method, but the logical addresses of the page tables are flagged with supervisor. I know that this is already some protection, but I don't know if it is enough.
Thor Operating System: C++ 64 bits OS: https://github.com/wichtounet/thor-os
Good osdeving!
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Is it safe to flag high-level paging structures as USER

Post by Brendan »

Hi,
wichtounet wrote:
bluemoon wrote:If you happen to use recursive paging method, you may still prevent user modifying page table by having the flag for such logical address (ie. last entry in most tutorials) to supervisor
I don't use the recursive paging method, but the logical addresses of the page tables are flagged with supervisor. I know that this is already some protection, but I don't know if it is enough.
It's safe. The CPU combines all the flags at each level together to determine the final permissions. If something (writes, execution or "user" access) is prevented at any level then there's no way to allow it at any other level; and if something is allowed at any level then it can be overridden/prevented at any other level.


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.
User avatar
wichtounet
Member
Member
Posts: 90
Joined: Fri Nov 01, 2013 4:05 pm
Location: Fribourg, Switzerland
Contact:

Re: Is it safe to flag high-level paging structures as USER

Post by wichtounet »

Fine, I didn't know of the "combination mechanism". I'll make sure all last level are flagged correctly.

Thanks Brendan :)

And all the others that answered too, of course.
Thor Operating System: C++ 64 bits OS: https://github.com/wichtounet/thor-os
Good osdeving!
Post Reply