FIX:Crash when far return from ring 0 to ring 3, bochs 2.6.2
Posted: Wed Feb 26, 2014 5:01 am
The related ring 0 code is:
;; SS selector for ring 3, in LDT, ring 3, offset 8
mov qword ptr [rsp + 24], (8 | 4 | 3)
;; RSP for ring 3
mov rax, 0x10000400000
mov [rsp + 16], rax
;; CS selecotr for ring 3, in LDT, ring 3, offset 0
mov qword ptr [rsp + 8], (0 | 4 | 3)
;; RIP for ring 3
mov rax, 0x10000000000
mov [rsp], rax
retf 0
-------------------
GDT info:
+0 null desc
+8 64-bit code desc, non-conforming, DPL 0, for os
+16 data desc, DPL 0, for os
+24 LDT desc
+40 TSS desc
LDT info:
+0 64-bit code desc, non-conforming, DPL 3, for app
+8 data desc, DPL 3, for app
When the "retf" instruction is executed in bochs 2.6.2, processor enters an exception. If run debug command 'c', lots of errors appear and crash:
00012169062e[CPU0] fetch_raw_desciptor: GDT: index (107) 20 > limit (37)
...
I am sure the code in 0x10000000000 is correct 64-bit code, and [0x10000000000, 0x100003fffff] area is mapped successfully, because the ring 3 code had been copy to this area, followed by an instruction 'sfence'.
After debug, I found the exception vector is 0x0D, #GP fault.
rsp before execute 'retf 0': ffff8000 000221d0
rsp after execute 'retf 0': ffff8000 000221a0, exception's stack top
when enter exception, the stack info:
[rsp]: 00000000 00000100 (error code)
[rsp + 8]: ffff8000 00001b58 (old RIP)
[rsp + 10]:00000000 00000008 (old CS)
[rsp + 18]:00000000 00010082 (RFLAGS)
[rsp + 20]:ffff8000 000221d0 (old RSP)
[rsp + 28]:00000000 00000010 (old SS)
bochs 2.6.2, Windows version. Host OS is Win8.1
The last part of crash info, error.zip:
http://pan.baidu.com/s/1kT0qr4r
There are lots of "00012...[CPU0 ] fetch_raw_descriptor: GDT: index (16f) 2d > limit (37)" lines which are not show in the snapshot.
;; SS selector for ring 3, in LDT, ring 3, offset 8
mov qword ptr [rsp + 24], (8 | 4 | 3)
;; RSP for ring 3
mov rax, 0x10000400000
mov [rsp + 16], rax
;; CS selecotr for ring 3, in LDT, ring 3, offset 0
mov qword ptr [rsp + 8], (0 | 4 | 3)
;; RIP for ring 3
mov rax, 0x10000000000
mov [rsp], rax
retf 0
-------------------
GDT info:
+0 null desc
+8 64-bit code desc, non-conforming, DPL 0, for os
+16 data desc, DPL 0, for os
+24 LDT desc
+40 TSS desc
LDT info:
+0 64-bit code desc, non-conforming, DPL 3, for app
+8 data desc, DPL 3, for app
When the "retf" instruction is executed in bochs 2.6.2, processor enters an exception. If run debug command 'c', lots of errors appear and crash:
00012169062e[CPU0] fetch_raw_desciptor: GDT: index (107) 20 > limit (37)
...
I am sure the code in 0x10000000000 is correct 64-bit code, and [0x10000000000, 0x100003fffff] area is mapped successfully, because the ring 3 code had been copy to this area, followed by an instruction 'sfence'.
After debug, I found the exception vector is 0x0D, #GP fault.
rsp before execute 'retf 0': ffff8000 000221d0
rsp after execute 'retf 0': ffff8000 000221a0, exception's stack top
when enter exception, the stack info:
[rsp]: 00000000 00000100 (error code)
[rsp + 8]: ffff8000 00001b58 (old RIP)
[rsp + 10]:00000000 00000008 (old CS)
[rsp + 18]:00000000 00010082 (RFLAGS)
[rsp + 20]:ffff8000 000221d0 (old RSP)
[rsp + 28]:00000000 00000010 (old SS)
bochs 2.6.2, Windows version. Host OS is Win8.1
The last part of crash info, error.zip:
http://pan.baidu.com/s/1kT0qr4r
There are lots of "00012...[CPU0 ] fetch_raw_descriptor: GDT: index (16f) 2d > limit (37)" lines which are not show in the snapshot.