Page 1 of 1

trying 0x80 syscall interrupt, but getting gpf instead

Posted: Mon Aug 17, 2020 2:19 am
by ITchimp
I have my interrupt table set up, ready to try

Code: Select all

asm("int $0x80;")
I am doing this in kernel mode ... basically, it is just doing syscall without doing it from user space...

when I do it, I got gpf, here is the transcript/

Code: Select all

(0).[1244325120] [0x0000000000100170] 0008:0000000000100170 (unk. ctxt): mov eax, 0x00000000       ; b800000000
Next at t=1244325121
(0) [0x0000000000100175] 0008:0000000000100175 (unk. ctxt): int 0x80                  ; cd80
<bochs:8> 
(0).[1244325121] [0x0000000000100175] 0008:0000000000100175 (unk. ctxt): int 0x80                  ; cd80
CPU 0: Interrupt 0x80 occured (error_code=0x0000)
(0).[1244325122] [0x0000000000000000] 0008:0000000000000000 (unk. ctxt): push ebx                  ; 53
(0).[1244325123] [0x0000000000000001] 0008:0000000000000001 (unk. ctxt): inc dword ptr ds:[eax]    ; ff00
(0).[1244325124] [0x0000000000000003] 0008:0000000000000003 (unk. ctxt): lock push ebx             ; f053
CPU 0: Exception 0x06 - (#UD) undefined opcode occured (error_code=0x0000)
CPU 0: Interrupt 0x06 occured (error_code=0x0000)
(0).[1244325125] [0x00000000001013b0] 0008:00000000001013b0 (unk. ctxt): cli                       ; fa
(0).[1244325126] [0x00000000001013b1] 0008:00000000001013b1 (unk. ctxt): push 0x00000000           ; 6a00
(0).[1244325127] [0x00000000001013b3] 0008:00000000001013b3 (unk. ctxt): push 0x00000006    

Re: trying 0x80 syscall interrupt, but getting gpf instead

Posted: Mon Aug 17, 2020 2:29 am
by Octocontrabass
ITchimp wrote:when I do it, I got gpf, here is the transcript/
I don't see #GP anywhere in that log. I do see #UD, which looks like it's caused by executing something that is not code.

Are you sure you're setting up the IDT entry for interrupt 0x80 correctly?

Re: trying 0x80 syscall interrupt, but getting gpf instead

Posted: Mon Aug 17, 2020 3:26 am
by ITchimp
I think it looks right

Code: Select all

IDT[0x7d]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0x7e]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0x7f]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0x80]=32-Bit Interrupt Gate target=0x0008:0x00000000, DPL=0
IDT[0x81]=??? descriptor hi=0x00000000, lo=0x00000000
IDT[0x82]=??? descriptor hi=0x00000000, lo=0x00000000

Re: trying 0x80 syscall interrupt, but getting gpf instead

Posted: Mon Aug 17, 2020 3:31 am
by iansjack
Do you really mean the code for interrupt 0x80 starts at address 0? That doesn't sound like a good idea.

It's best to make the first page of your address space non-executable to guard against null function pointers or return addresses.

Re: trying 0x80 syscall interrupt, but getting gpf instead

Posted: Mon Aug 17, 2020 5:55 pm
by sj95126
ITchimp wrote:

Code: Select all

lock push ebx
There's your #UD.