understanding problems with page protection mechanism

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
MNemo
Posts: 5
Joined: Sat Oct 07, 2006 3:03 pm
Location: Germany

understanding problems with page protection mechanism

Post by MNemo »

hi,

up to now i mapped every page as writable. i.e. i set the writable bit in every paging entry(pml4e,pdpe,pde,pte). so far no problem.
but now i like to take more advantages of the page protection mechanism.

AMD's System Programming Manual reads:
This bit controls read/write access to all physical pages mapped by the
table entry. For example, a page-map level-4 R/W bit controls read/write access to all 128M
(512 × 512 × 512) physical pages it maps through the lower-level translation tables.
i am confused. each page is mapped via four levels, that means each page has four R/W bits. but which one is taken for protection?

e.g.
a page may be mapped like this: pml4e.writable, pdpe.not_writable, pde.writable, pte.not_writable
is the page writable or is it not? and why? and what is when the page is
mapped like this: pml4e.not_writable, pdpe.writable, pde.not_writable, pte.writable?

thanks for your help
I know my English is bad. So any corrections concerning language won't offend me.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: understanding problems with page protection mechanism

Post by Brendan »

Hi,
MNemo wrote:i am confused. each page is mapped via four levels, that means each page has four R/W bits. but which one is taken for protection?
All of them ANDed together. Basically if any read/write bit is clear at any level, then CPL=3 code can't write to the page.
MNemo wrote:e.g.
a page may be mapped like this: pml4e.writable, pdpe.not_writable, pde.writable, pte.not_writable
is the page writable or is it not? and why?
It's not writable because the at least one of the bits says "not writable".
MNemo wrote:and what is when the page is
mapped like this: pml4e.not_writable, pdpe.writable, pde.not_writable, pte.writable?
It's not writable either, because the at least one of the bits says "not writable".

The same applies to the user/supervisor flag (if any user/supervisor bit is clear at any level, then CPL=3 code can't access the page). The "no-execute" flag is different - they're ORed together (if any NX bit at any level is set, then you can't execute code in that page).


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.
MNemo
Posts: 5
Joined: Sat Oct 07, 2006 3:03 pm
Location: Germany

Re: understanding problems with page protection mechanism

Post by MNemo »

ok. :D
thx for your answer and the quick replay
I know my English is bad. So any corrections concerning language won't offend me.
Post Reply