Is there any advantage to placing x86 driver code in rings 1 and 2 instead of 0?

Drivers for monolithic kernels can be in rings 0, 1 or 2 (with microkernels they will be in ring 3 - a user ring).

Are there any advantages / disadvantages to putting the driver code in ring 0 with the kernel or in โ€œslightly lessโ€ privileged rings 1 and 2?

Rings 1 and 2 can still access supervisor pages, but they cannot execute some special privileged instructions (if they do, they will raise a general security error - for example, with ring 3)

+6
source share
1 answer

The most obvious benefit of using rings 1 and 2 would be an architectural separation that could protect the kernel from a failed device driver. A theoretically correctly written kernel would allow a graceful crash when the driver in the outer ring had a catastrophic crash. Running the driver in ring 0 can potentially allow it to remove the entire kernel if it does not work.

The disadvantage of moving drivers to rings 1 and 2 will be the performance overhead associated with the constant need for ring transitions between the kernel and drivers. Of course, in a microkernel system this is necessary and can be fast enough depending on your needs . With proper optimization, disconnecting the kernel from its services can have very low performance. At the same time, Intel SYSENTER / SYSEXIT (and equivalent AMD SYSCALL / SYSRET ) used to quickly switch contexts allow only transitions between rings 0 and 3; A complete interrupt is required to perform context switching in or out of rings 1 or 2.

Another drawback to keep in mind is that, since many other architectures only have a supervisor and user modes (or equivalent), any platform architecture you write that controls which level elements of your code are launched will have and both:

  • recorded differently depending on whether the platform has rings 1 and / or 2 and
  • make another decision about what level of privilege the code has depending on the platform.

If you plan to create a system that will be built for different architectures, this can lead to some difficulties.

+5
source

Source: https://habr.com/ru/post/974105/


All Articles