Reputation: 313
The processor maintains current privilege level in CPL field. I want to know about all possible scenarios when CPL field changes from 3 to 0 and vice versa. For example, CPL field might change from 3 to 0 when a system call is invoked by a user process.
Moreover, please try to elaborate what goes on inside the kernel/CPU before CPL field is changed.
Note: I have read a few posts explaining how protection is enforced by the CPU using CPL, RPL and DPL. I am unable to understand when and how does the CPL change.
Upvotes: 1
Views: 2078
Reputation: 166
This is a pretty in-depth question. The answer depends on which kernel you're looking at. Typically, CPL is only going to change during context switches (probably the initial switch from kernel to userspace) and during system calls.
The kernel needs to have usermode (CPL 3) segments set up in the Global Descriptor Table. Segment selectors (CS, DS, ES, FS, GS) are then set to the CPL=3 segment values.
Here is a great reference: http://duartes.org/gustavo/blog/post/cpu-rings-privilege-and-protection/
Also take a look at the Intel manuals. https://www-ssl.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html (Specifically Vol 3A, Page 5-7 is what you're looking for)
Upvotes: 2