Procesess in Ring 0

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
User avatar
jerryleecooper
Member
Member
Posts: 233
Joined: Mon Aug 06, 2007 6:32 pm
Location: Canada

Post by jerryleecooper »

edited out the nonsense. :oops: :oops:
Last edited by jerryleecooper on Thu Feb 28, 2008 4:28 pm, edited 1 time in total.
User avatar
ucosty
Member
Member
Posts: 271
Joined: Tue Aug 08, 2006 7:43 am
Location: Sydney, Australia

Post by ucosty »

Not really, because you only have two levels of memory protection - Supervisor and User.
The cake is a lie | rackbits.com
User avatar
jerryleecooper
Member
Member
Posts: 233
Joined: Mon Aug 06, 2007 6:32 pm
Location: Canada

Post by jerryleecooper »

ucosty wrote:Not really, because you only have two levels of memory protection - Supervisor and User.
Yes, and I wanted to write an article on paging :oops:
That would make a better system if there was more than two level though.
Now I remember, the |4 I put with the |3.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

At the moment I run all tasks in ring0 (which is insanely fast), but very soon I'm going to switch all userspace tasks (ie, the shell, and anything started by execve) to ring3.

It depends on whether you want protection with a minor speed hit or an easily hacked OS.
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

pcmattman wrote:At the moment I run all tasks in ring0 (which is insanely fast), but very soon I'm going to switch all userspace tasks (ie, the shell, and anything started by execve) to ring3.

It depends on whether you want protection with a minor speed hit or an easily hacked OS.
I think your missing the point, if you want a desktop OS for every day use and you do not want to use a good and free desktop OS like linux, and you have a spare 600 year's or 600 good coder's with a year to spare.
Then you should use ring3, or on the other hand maybe you do not want a desktop OS, but a OS you have full controll over, that run's a single program as fast as possible.
Then stick with ring0.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Dex wrote:on the other hand maybe you do not want a desktop OS, but a OS you have full controll over, that run's a single program as fast as possible.
Then stick with ring0.
Good point Dex, I didn't think of the possibility of a non-desktop OS.
User avatar
Masterkiller
Member
Member
Posts: 153
Joined: Sat May 05, 2007 6:20 pm

Post by Masterkiller »

If the process is in the level 0 it owns the system just like OS does. As I know four-levels are:
0: Operating system level
1: Device drivers level
2: Developer environment level
3: User-mode level
So ring/level 1 means that process can in/out to all ports in the system, but cannot execute Privilege level 0 instruction like LGDT and so on.
And what about rings 2 and 3. What a ring 2 processes can do more than ring 3 process?
Sorry but for me it seems the only topic where it is logical to ask such question without posting new topic :wink: :oops:
Last edited by Masterkiller on Fri Feb 29, 2008 2:44 am, edited 1 time in total.
User avatar
jerryleecooper
Member
Member
Posts: 233
Joined: Mon Aug 06, 2007 6:32 pm
Location: Canada

Post by jerryleecooper »

Probably ring2 can issue interrupts that are dpl 0? :?
Or is it that the dpl of an interrupt can be between 0-3? I dont remember.
It must be about the debugger? Also there's the playing with the data segment, code segment, they are always present. so you can give a different segment for ring2 but now my thinking isnt clear.
http://en.wikipedia.org/wiki/Ring_(computer_security)
ring 0 -3? there's also ring -1, the hypervisor :D
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

Masterkiller wrote:If the process is in the level 0 it owns the system just like OS does. As I know four-levels are:
0: Operating system level
1: Device drivers level
2: Developer environment level
3: User-mode level
So ring/level 1 means that process can in/out to all ports in the system, but cannot execute Privilege level 0 instruction like LGDT and so on.
And what about rings 2 and 3. What a ring 2 processes can do more than ring 3 process?
Sorry but for me it seems the only topic where it is logical to ask such question without posting new topic :wink: :oops:
The four rings only make sense in a segmented memory model. If you use a flat memory model with paging, you can't isolate more than two rings since each page table entry only has one bit for this: the U/S (user-supervisor). Should you be in ring 2, you could freely modify memory that belongs to ring 1.

There are the IOPL bits in EFLAGS that tell the processor what rings can execute I/O instructions. Normally one would set it to ring-0 only, but you can even allow ring 3 to freely access I/O ports.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
tjhastings
Posts: 12
Joined: Sat Feb 02, 2008 5:49 pm

Post by tjhastings »

Nobody has mentioned this yet:

To run processes in ring0 and have some level of protection one can scan the executable for protected instructions (in, out, lgdt, etc.) before it is executed. The scanning would have to be pretty sophisticated because there are a number of tricks to fool simple scanners, but it is possible.

- TJ
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

tjhastings wrote:Nobody has mentioned this yet:

To run processes in ring0 and have some level of protection one can scan the executable for protected instructions (in, out, lgdt, etc.) before it is executed. The scanning would have to be pretty sophisticated because there are a number of tricks to fool simple scanners, but it is possible.

- TJ
This would be much slower then just using ring3 etc, also you would still be able to over write any memory address.
tjhastings
Posts: 12
Joined: Sat Feb 02, 2008 5:49 pm

Post by tjhastings »

Dex wrote: This would be much slower then just using ring3 etc, also you would still be able to over write any memory address.
Yes, scanning does take time but only when an application is loaded. Small applications that are ran frequently can be cached in memory and thus do not have to be scanned every time they are executed. Applications that run for a long time (such as database/web/mail servers) will not notice any slowdown except for the initial scan.

Processes can run in ring0 and still have seperate address spaces using paging or segmentation. Because no process is allowed to run if it contains instructions which modifies the page directories/tables or GDT/LDT then it cannot break out of it's own address space and thus cannot harm anything else in the system.

- TJ
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Post by Korona »

Ring0 processes would be able to crash the kernel even if they are separated by paging. Scanning executables for unsafe instructions is often not possible. Imagine a function that takes a pointer as an argument and does some kind of operation to the memory pointed to by the pointer. It is often impossible for a scanner to analyze which pointer is passed to that function. Self modifying code would also be difficult to analyze. One way to handle this would be using a virtual machine that "emulates" or just-in-time compiles the application.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

Have you all read about "Singularity"? That's one real OS that can run entirely in ring 0.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Post by bewing »

Combuster wrote: The four rings only make sense in a segmented memory model. If you use a flat memory model with paging, you can't isolate more than two rings ...
Well, you can perhaps do a little better than that, if you only use segmentation on Ring1, in physical memory, say -- for drivers.
Post Reply