6

I have heard that Ring 1 and Ring 2 memory protections are basically no-longer used within modern systems.

However, when I checked into things, all I found was that these rings are somehow associated with drivers and driver access.

Have these really been phased out completely, or are there elements of these two protection rings present within system OSes still in common use (say, OSX, Windows 7-10 and common Linux distros like Mint or Ubuntu)? If so, what sort of code would I be writing to require access to these part of the system? If they have indeed been phased out, or are in the process of being phased out, what is the reason for this change?

I assume the two rings act as some sort of intermediary layer, like middleware, between the Kernal (ring 0) and the application layer (ring 3)...

4

The four ring system was designed by Intel for anyone to use, and Microsoft chose a scheme to simplify development work and provide a faster OS at the cost of some security. As far as Microsoft is concerned, they haven't been phased out, so much as they were never used to begin with. Microsoft didn't ask Intel to make a two ring system; Intel provided a four ring general-purpose system, and Microsoft decided to use it in a way they saw fit.

Intel had provided a way for OS's to provide extra security to prevent malicious drivers from crashing the system, and Microsoft chose to go a different way (signed drivers), which is optional in 32-bit mode, and required in 64-bit mode. Microsoft requires validation that the drivers will not affect the system before they will sign a binary. You'll recall that Windows 95/98 were notorious for crashing. This is because drivers were usually buggy and the OS had no protection from those drivers, since they were all in Ring 0.

I believe there are some modern operating systems still in use today that use more than two ring levels, and as a matter of backwards compatibility, hardware manufacturers can't exclude those two "unused" rings. Just because Microsoft nor the main Linux kernel uses more than two levels doesn't mean that someone couldn't write an OS that does use the extra protection that Rings 1 and 2 provide. Hardware protection from malicious or just faulty software was absolutely necessary in an age where we could not verify program behavior beforehand, and processors were too slow to do all of the protection in software.

Microsoft also released a research project called Singularity, and operating system where all code runs in Ring 0, and all pages in memory do not use segment selectors. In other words, there are no hardware protection against malicious programs. This results in a significant boost in speed, as programs no longer have to pass through ring levels to call kernel code, but all code has to be statically verifiable, as it would be if written in .NET without using the "unsafe" keyword. The OS can statically verify that a program is not malicious before execution. The full source code is available for free.

Hardware protection is likely never going to phased out, because there are simply too many systems that depend on it. It would take a coordinated effort between hardware and software vendors, and it would probably cost billions or even trillions of dollars in the long run, without any significant reduction of cost in terms of operating power/speed/etc. The two rings, 0 and 3, will likely continue to be used in the foreseeable future as long as there are only three major competing OSes (Microsoft, Apple, Linux). It would take a significant market change to upset the status quo.

  • 4
    To be clear in regard to Singularity (and, to an extent, CosmOS) the reason for not requiring ring-based privilege separation is that they implement the .NET CLR and all "usermode" code is written in MSIL, which is expected to be type-safe and memory-safe as long as certain interop calls aren't used. – Polynomial Jun 15 '16 at 16:35
  • 1
    @Polynomial I'll take that under advisement... – Guy Incognito Jun 15 '16 at 21:54
  • 1
    I don't think anything uses more than 2 rings now days. OS/2 I believe used ring 2 for certain types of drivers, and VMWare used to use ring 2 (or maybe it was ring 1?) on systems which lacked hardware-accelerated virtualization. But now it's so uncommon that it's pretty much only x86 that keeps the 4 rings. ARM for example only has supervisor mode and non-supervisor mode. – forest May 11 '18 at 22:28
  • @forest Apparently some VM systems move the guest kernel to Ring 1 and keep themselves in Ring 0. Also, a cursory search suggests that at least DR-DOS and OpenDOS (both which appear to be available today), use Ring 1 for some DOS Protected Mode Services (DPMS). Your statement is certainly almost true, as I'd guess some odd 99% of computers that are running today use the Ring 0/3 model, but there are apparent exceptions to the rule. One main point, though, is that for backwards compatibility, CPU manufacturers aren't necessarily going to throw out Rings 1/2 any time soon. – phyrfox May 11 '18 at 22:45
1

It is true that x86 had 4 protection rings, however x86-64 only has 2, AMD removed rings 1 and 2 when they were designing x86-64, this however raised issues when it came to virtualising, Intel and AMD have now introduced VT-x and AMD-V respectively, which effectively adds a ring -1 for the virtualisation. So no, none of those OSes use the extra rings, although they sort of use an extra one for virtualisation.

The idea of the rings 1 and 2 is that you can give additional access without allowing a given driver to crash the whole system, I won't reiterate what @phyrfox has written.

In terms of Operating Systems which use all 4 protection rings OpenVMS is probably the most prominent, and this is one of the reasons why it has such a good reputation for security. OpenVMS was originally written for the VAX architecture, which had 4 rings, it was then ported to AXP (Dec Alpha) which was a 64 bit architecture with only 2 rings, however using PAL code it was fairly easy to emulate the other 2 required, DEC were after all the designers of both the hardware and software, it has since been ported to IA-64 (Intel Itanium), which has 4 privilege levels.

OpenVMS is now being ported to x86-64, with one of the main difficulties being emulating the additional 2 protection rings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.