rstorssp
Restore Shadow Stack Pointer
Restores SSP from memory token.
Pseudocode Operation
token ← [src]
// Validate token format; if invalid raise #CP
SSP ← token
Example
Encoding
Operands
-
dest
64-bit memory operand (quadword)
Related
More in CET-SS
Reference
Instruction Forms
| Opcode | Instruction | Op/En | 64/32-bit Mode | CPUID | Description |
|---|---|---|---|---|---|
| F3 0F 01 /5 | RSTORSSP m64 | M | V/V | CET_SS | Restore SSP. |
Description
Restores SSP from the shadow-stack-restore token pointed to by m64. If the SSP restore was successful then the instruction replaces the shadow-stack-restore token with a previous-ssp token. The instruction sets the CF flag to indicate whether the SSP address recorded in the shadow-stack-restore token that was processed was 4 byte aligned, i.e., whether an alignment hole was created when the restore-shadow-stack token was pushed on this shadow stack. Following RSTORSSP if a restore-shadow-stack token needs to be saved on the previous shadow stack, use the SAVEPREVSSP instruction. If pushing a restore-shadow-stack token on the previous shadow stack is not required, the previous-ssp token can be popped using the INCSSPQ instruction. If the CF flag was set to indicate presence of an alignment hole, an additional INCSSPD instruction is needed to advance the SSP past the alignment hole.
Operation
IF CPL = 3 IF (CR4.CET & IA32_U_CET.SH_STK_EN) = 0 THEN #UD; FI; ELSE IF (CR4.CET & IA32_S_CET.SH_STK_EN) = 0 THEN #UD; FI; FI; SSP_LA = Linear_Address(mem operand) IF SSP_LA not aligned to 8 bytes THEN #GP(0); FI; previous_ssp_token = SSP | (IA32_EFER.LMA AND CS.L) | 0x02 Start Atomic Execution restore_ssp_token = Locked shadow_stack_load 8 bytes from SSP_LA fault = 0 IF ((restore_ssp_token & 0x03) != (IA32_EFER.LMA & CS.L)) THEN fault = 1; FI; (* If L flag in token does not match IA32_EFER.LMA & CS.L or bit 1 is not 0 *) IF ((IA32_EFER.LMA AND CS.L) = 0 AND restore_ssp_token[63:32] != 0) THEN fault = 1; FI; (* If compatibility/legacy mode and SSP to be restored not below 4G *) TMP = restore_ssp_token & ~0x01 TMP = (TMP - 8) TMP = TMP & ~0x07 IF TMP != SSP_LA THEN fault = 1; FI; (* If address in token does not match the requested top of stack *) TMP = (fault == 0) ? previous_ssp_token : restore_ssp_token shadow_stack_store 8 bytes of TMP to SSP_LA and release lock End Atomic Execution IF fault == 1 THEN #CP(RSTORSSP); FI; SSP = SSP_LA // Set the CF if the SSP in the restore token was 4 byte aligned, i.e., there is an alignment hole RFLAGS.CF = (restore_ssp_token & 0x04) ? 1 : 0; RFLAGS.ZF,PF,AF,OF,SF := 0;