IRET

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
justin
Member
Member
Posts: 43
Joined: Sun Jan 11, 2009 2:09 pm

IRET

Post by justin »

In the Intel manuals (5-18 vol 3), it says "If a stack switch occurred when calling the handler procedure, the IRET instruction
switches back to the interrupted procedure’s stack on the return."

How does the processor know that a stack switch occurred when the handler procedure was called, so that it can take the appropriate action during an IRET instruction?
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: IRET

Post by AJ »

Hi,

The only way it knows is by the PL of the return CS selector. If the return CS PL is greater than that of the handler, SS and ESP are popped off the stack.

Cheers,
Adam
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

Re: IRET

Post by blackoil »

when executing IRET, it need to pop CS:EIP pair, if CS value to be popped is greater the current value in CS register, then after pop CS:EIP pair, SS:ESP pair follows implicitly.

customly switch to any greater previlege ring task, you need to set up CS:EIP SS:ESP pairs on your current stack, manually.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: IRET

Post by AJ »

blackoil wrote:when executing IRET, it need to pop CS:EIP pair, if CS value to be popped is greater the current value in CS register, then after pop CS:EIP pair, SS:ESP pair follows implicitly.
This is a bit misleading. It's not the CS value that matters - only the DPL of CS (the lower 2 bits). Also, the order of popped arguments is EIP, CS, EFLAGS, ESP and then SS.

Cheers,
Adam
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

Re: IRET

Post by blackoil »

yes, the DPL of CS register

SS <---high address
ESP
EFLAGs
EIP
CS <---low address, current SS:ESP
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: IRET

Post by egos »

Open your eyes:

SS <---high address
ESP
EFLAGs
CS
EIP <---low address, current SS:ESP

Edited: the low two bits of selector are RPL, not DPL.
If you have seen bad English in my words, tell me what's wrong, please.
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

Re: IRET

Post by blackoil »

Oh yeah, I got asleep while typing
Post Reply