when is CPL changed to 0 when a user program divide by zero exception happens?
Does anyone know when CPL is changed when divide by zero exception happens? Thanks.
divide by zero exception handler can only be accessed when the thread's CPL is 0 because divide_erro is initialized by set_trap_gate(0,÷_error);
It looks like that user mode is switching to kernel stack at step 5 (below). I assume that is when CPL is set to 0 (kernel mode). The question is how can the user application pass the DPL check at step 4. User application should be still in CPL 3 and fail to pass the divide_error DPL 0 check at step 4?
=== From page 142 Understanding Linux kernel
4. Makes sure the interrupt was issued by an authorized source. First, it compares the Current Privilege Level (CPL), which is stored in the two least significant bits of the cs register, with the Descriptor Privilege Level (DPL ) of the Segment Descriptor included in the GDT. Raises a "General protection " exception if the CPL is lower than the DPL, because the interrupt handler cannot have a lower privilege than the program that caused the interrupt. For programmed exceptions, makes a further security check: compares the CPL with the DPL of the gate descriptor included in the IDT and raises a "General protection" exception if the DPL is lower than the CPL. This last check makes it possible to prevent access by user applications to specific trap or interrupt gates.
--> User application CPL 3. How to use divide_error DPL 0?
5. Checks whether a change of privilege level is taking place that is, if CPL is different from the selected Segment Descriptor's DPL. If so, the control unit must start using the stack that is associated with the new privilege level. It does this by performing the following steps:
a. Reads the tr register to access the TSS segment of the running process.
b. Loads the ss and esp registers with the proper values for the stack segment and stack pointer associated with the new privilege level. These values are found in the TSS (see the section "Task State Segment" in Chapter 3).
c. In the new stack, it saves the previous values of ss and esp, which define the logical address of the stack associated with the old privilege level.
Last edited by titan22; 04-12-2009 at 07:32 PM.