0

x86 IA-32

In my understanding accessing memory from user space program does not involve operating system.. Otherwise it would be slow.

So if paging enabled or not CPU should know somehow that this segment/page can be accessed by currently running code.

Let's say paging is off - so the only thing CPU can refer to (to determine access rights) is Segment Descriptor in GDT. But does Segment Descriptor contains any info about which process can use which segment?

Paging is on - Does Page Table Entry contains any info about who can access this particular page?

Bit 2 (U/S) User/supervisor; if 0, user-mode accesses are not allowed to the 4-KByte page referenced by this entry

It does contain privilege level, but it's not enough to determine does current code have access to this particular page.

How does CPU+MMU protect memory accesses without involving OS on every memory read/write?

What if some malicious process loads its own value in Segment selector?

Does MMU have some data structures that OS fills up on process creation/context switch?

1 Answer 1

1

But does Segment Descriptor contains any info about which process can use which segment?

Yes, the segment descriptor’s DPL bits determine the required privilege level.

Does Page Table Entry contains any info about who can access this particular page?

Yes, the U/S bit you mention.

but it's not enough to determine does current code have access to this particular page.

On x86, the current privilege level is determined by the bottom bits of the CS register; see Get Current Privilege Level for a process (ring).

How does CPU+MMU protect memory accesses without involving OS on every memory read/write?

The operating system fills in the appropriate data structures to tell the MMU what should be protected. The OS is then only involved when code attempts to do something “forbidden” (which might not actually be forbidden, e.g. if it’s attempting to access memory which isn’t there but which it is allowed to access).

What if some malicious process loads its own value in Segment selector?

Processes can’t load segment selectors with values beyond their privilege level.

Does MMU have some data structures that OS fills up on process creation/context switch?

Yes, and you’ve referred to some of them already: the GDT, page tables etc.

1
  • Processes can’t load segment selectors with values beyond their privilege level. That was new for me
    – v.doro2
    Commented Feb 13, 2023 at 10:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .