Ring 0 Vs Ring 3
Ring 0 Vs Ring 3
Hi again,
i hope i am not causing any troubles here
1- i want to know what instructions is allowed in ring 0 but not allowed in ring 3 ?
2- i also want to know which memory area is allowend for ring 0 and not ring 3 knowing that the memory model is pure segmentation with base 0 and limit 4 gb
3- for the ports what ports is allowed for ring 0 but not for ring 3, i know that this is controlled by IOBITMP in the TSS, but does linux & bsd prevent all IO for ring 3 process, if they do how to disable all io for ring 3, as i like to trace how things is made up in linux
Thanks
i hope i am not causing any troubles here
1- i want to know what instructions is allowed in ring 0 but not allowed in ring 3 ?
2- i also want to know which memory area is allowend for ring 0 and not ring 3 knowing that the memory model is pure segmentation with base 0 and limit 4 gb
3- for the ports what ports is allowed for ring 0 but not for ring 3, i know that this is controlled by IOBITMP in the TSS, but does linux & bsd prevent all IO for ring 3 process, if they do how to disable all io for ring 3, as i like to trace how things is made up in linux
Thanks
Re:Ring 0 Vs Ring 3
Hi,
My comments below ignore virtual 8086 mode completely (in virtual 8086 mode there's different privileged instructions and some I/O port handling changes).
I don't know what BSD and LInux do though...
Cheers,
Brendan
I hope I'm not causing trouble here too .Unlink wrote:i hope i am not causing any troubles here
My comments below ignore virtual 8086 mode completely (in virtual 8086 mode there's different privileged instructions and some I/O port handling changes).
Intel's system programmers manual, section 4.9 "Privileged Instructions" has a list:Unlink wrote:1- i want to know what instructions is allowed in ring 0 but not allowed in ring 3 ?
- LGDT
LLDT
LTR
LIDT
MOV (to and from control registers only)
MOV (to and from debug registers only)
LMSW
CLTS
INVD
WBINVD
INVLPG
HLT
RDMSR
WRMSR
RDPMC
RDTSC
Protection of memory areas is controlled by segmentation and paging, and nothing else.Unlink wrote:2- i also want to know which memory area is allowend for ring 0 and not ring 3 knowing that the memory model is pure segmentation with base 0 and limit 4 gb
Ring 0 can always access all I/O ports. Ring 3 may be able to access all of them or none of them, depending on how the OS sets IOPL (the "I/O Privilege Level" bits in EFLAGS). If IOPL is set to zero, ring 3 code may be granted access to individual I/O ports if the OS uses the IOBMP in the TSS.Unlink wrote:3- for the ports what ports is allowed for ring 0 but not for ring 3, i know that this is controlled by IOBITMP in the TSS, but does linux & bsd prevent all IO for ring 3 process, if they do how to disable all io for ring 3, as i like to trace how things is made up in linux
I don't know what BSD and LInux do though...
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
- kataklinger
- Member
- Posts: 381
- Joined: Fri Nov 04, 2005 12:00 am
- Location: Serbia
Re:Ring 0 Vs Ring 3
If RING3 descriptors has base 0 and limin of 4gb, then you don't have memory protection at all. But still you can protect execution of privileged instructions and I/O access. User programs can access to all memory including kernel memory and this is problem. Paging can solve this, because you can tell which page can be accessed from which ring (0-supervisor, 3-user).Unlink wrote: 2- i also want to know which memory area is allowend for ring 0 and not ring 3 knowing that the memory model is pure segmentation with base 0 and limit 4 gb
Re:Ring 0 Vs Ring 3
ya thanks,
but how do i disable cli & sti they still run even in ring 3 ?
but how do i disable cli & sti they still run even in ring 3 ?
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Ring 0 Vs Ring 3
you normally don't want user tasks to disable interrupts ... that'd mean, for instance, that a given program could completely hang up the system by issueing
Now, there are "virtual interrupt flag" thingy that you might want to investigate that let user code (and especially VM86) "believe" that interrupts are disabled and later receive deferred interrupts when STI is raised again. That will allow the kernel to make the VM86 code (i mean, the real-mode bios code, not the VirtualMonitor) block IRQs that should have been delegated to VM86 and still having IRQ0 feeding the scheduler, etc.
Code: Select all
cli
hlt
- kataklinger
- Member
- Posts: 381
- Joined: Fri Nov 04, 2005 12:00 am
- Location: Serbia
Re:Ring 0 Vs Ring 3
RING3 tasks can execute CLI & STI instruction only if IOPL=3 in EFLAG. If you set IOPL to 0, CLI&STI can be execute only form RING0.
Re:Ring 0 Vs Ring 3
kataklinger u r amazing, that was really my problem, really thankskataklinger wrote: RING3 tasks can execute CLI & STI instruction only if IOPL=3 in EFLAG. If you set IOPL to 0, CLI&STI can be execute only form RING0.
but here is another one:
i use pure paging and 4 GB address is avaible for both ring0 & ring3.
but when i call my printf() from ring3, i got stack fault with error 0x23.
the printf() takes unlimited parameters and i don't think the error is caused by it, since it works for ring0 & i've tested it on a linux executable.
so can u figure out where is my error?
thanks alot
- kataklinger
- Member
- Posts: 381
- Joined: Fri Nov 04, 2005 12:00 am
- Location: Serbia
Re:Ring 0 Vs Ring 3
If error code is not equal to zero it conatians the value of selector in SS during the exception and it means that segment is not present, so check present flag in descriptor for your stack segment.
Is that happens only if you call printf(), or it happens if you call any function?
P.S. You shouldn't use same code for kernel mode printf and user mode printf or any other code. If you want to call some kernel function from user mode you should do that throught software interrupts or call gates (or fast systemc calls).
Is that happens only if you call printf(), or it happens if you call any function?
P.S. You shouldn't use same code for kernel mode printf and user mode printf or any other code. If you want to call some kernel function from user mode you should do that throught software interrupts or call gates (or fast systemc calls).
Re:Ring 0 Vs Ring 3
i only tested it with my printf() & puts(), i don't know wether it works for other functions, i thought it may be a kind of protection since printf & puts actually write to a memory mapped I/O 0xb8000.
yes, i've used the same printf() for both kernel & user without interrupts or call gates, since is defined a ring3 cs, ds with base 0 & limit 4gb !!! but i don't if that's right or not ?
thanks for your help
yes, i've used the same printf() for both kernel & user without interrupts or call gates, since is defined a ring3 cs, ds with base 0 & limit 4gb !!! but i don't if that's right or not ?
thanks for your help
Re:Ring 0 Vs Ring 3
i forgot to say that when i try to use this test code rather than the printf() :
it still generates a stack fault with error 0x23
and here is my gdt :
and i don't know wether i should set the X bit for code segments or not ?
Code: Select all
char *v=(char *)0xb8000;
*v++='T';
*v=0x7;
and here is my gdt :
Code: Select all
gdt:
null_desc dd 0h
dd 0h
flat_code dw 0ffffh
dw 0h
db 0h
db 10011010b
db 11001111b
db 0h
flat_data dw 0ffffh
dw 0h
db 0h
db 10010010b ; 92h
db 11001111b ; cfh
db 0h
user_code dw 0ffffh
dw 0h
db 0h
db 11111010b
db 11001111b
db 0h
user_data dw 0ffffh
dw 0h
db 0h
db 11110110b ; f2h
db 11001111b ; cfh
db 0h
task_state dd 0h
dd 0h
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Ring 0 Vs Ring 3
if you're in the bochs, i suggest you set a breakpoint and use dump-cpu to see the actual limit for the stack segment.
hint: your 0x20 descriptor seems to be expand-down. Is that on purpose ?
hint: your 0x20 descriptor seems to be expand-down. Is that on purpose ?
- kataklinger
- Member
- Posts: 381
- Joined: Fri Nov 04, 2005 12:00 am
- Location: Serbia
Re:Ring 0 Vs Ring 3
11110110b != 0f2h ;D
11110110b == 0f6h
So yu need 11110010b.
Few pairs of eyes are better then on
Try this:
11110110b == 0f6h
So yu need 11110010b.
Few pairs of eyes are better then on
Try this:
Code: Select all
user_data dw 0ffffh
dw 0h
db 0h
------> db 11110010b ; f2h
db 11001111b ; cfh
db 0h
Re:Ring 0 Vs Ring 3
yup
so my data was really stack
i've also noticed it, after i pasted the code her.
but why shouldn't i set the x bit in the CS ?
so my data was really stack
i've also noticed it, after i pasted the code her.
but why shouldn't i set the x bit in the CS ?
- kataklinger
- Member
- Posts: 381
- Joined: Fri Nov 04, 2005 12:00 am
- Location: Serbia
Re:Ring 0 Vs Ring 3
What is the X bit?