Page 1 of 1

I/O permissions

Posted: Tue Apr 10, 2012 12:47 pm
by afritmans
Simple problem in my opinion, but i'm unable to solve it.

I don't want user space programs to execute I/O instructions (IN, OUT,...). Bochs reports me EFLAGS is 0x202 (so IOPL is 0) and CS is 0x1B (so CPL is 3). Conclusion: CPL(3)>IOPL(0). That means the processor should checks the I/O bitmap in the TSS, which I do not have:

Code: Select all

procRing3Tss:
	dd 0
procRing3TssEsp0:
	dd 0			; Kernel ESP
	dw 0x10, 0		; Kernel SS
	times 23 dd 0
procRing3TssEnd:
Unfortunately, programs can still execute I/O-instructions. Anyone knows where i screwed up?

Re: I/O permissions

Posted: Tue Apr 10, 2012 1:31 pm
by jnc100
Have you checked the TSS (+ its limit) is as you intended it to be? In bochs debugger, the 'info tss' command should confirm this.

Regards,
John.

Re: I/O permissions

Posted: Tue Apr 10, 2012 1:48 pm
by afritmans
Result of "info tss":

Code: Select all

tr:s=0x28, base=0x00000000c010d1e4, valid=1
ss:esp(0): 0x0010:0xc0116663
ss:esp(1): 0x0000:0x00000000
ss:esp(2): 0x0000:0x00000000
cr3: 0x00000000
eip: 0x00000000
eflags: 0x00000000
cs: 0x0000 ds: 0x0000 ss: 0x0000
es: 0x0000 fs: 0x0000 gs: 0x0000
eax: 0x00000000  ebx: 0x00000000  ecx: 0x00000000  edx: 0x00000000
esi: 0x00000000  edi: 0x00000000  ebp: 0x00000000  esp: 0x00000000
ldt: 0x0000
i/o map: 0x0000
I think my TSS is actually correct?


Edit: executing STI/CLI isn't possible, but IN/OUT are still usable... Looks like there has to be something wrong with my TSS

Re: I/O permissions

Posted: Tue Apr 10, 2012 3:37 pm
by Owen
What I/O addresses are you trying with?

My psychic prediction of how to fix this: Try pointing the IO Permission Bitmap offset beyond the TSS limit.

Re: I/O permissions

Posted: Tue Apr 10, 2012 3:51 pm
by rdos
Yes, the IO permission bitmap is incorrect (it points to the first byte in the TSS). Normally, you would want it to point to a location beyond the register save area, and the last byte in the TSS should be FF.

Re: I/O permissions

Posted: Tue Apr 10, 2012 4:00 pm
by afritmans
I understand. Since I don't want to use that bitmap, I thought it was OK to use 0 as location. I'll check the manuals :)

Edit: It works! Thanks! Btw, my TSS is now:

Code: Select all

procRing3Tss:
    dd 0
procRing3TssEsp0:
    dd 0			; Kernel ESP
    dw 0x10, 0		; Kernel SS
    times 22 dd 0  	
    dw 0, 0x68		; Offset IO-Map
procRing3TssIOMap:
    dd 0xFFFFFFFF
procRing3TssEnd: