Click here to Skip to main content
15,887,485 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: 1 stable 2 super stable Pin
Calin Negru9-Sep-23 3:37
Calin Negru9-Sep-23 3:37 
GeneralRe: 1 stable 2 super stable Pin
Jacquers9-Sep-23 4:21
Jacquers9-Sep-23 4:21 
GeneralRe: 1 stable 2 super stable Pin
honey the codewitch9-Sep-23 4:44
mvahoney the codewitch9-Sep-23 4:44 
GeneralRe: 1 stable 2 super stable Pin
trønderen9-Sep-23 5:17
trønderen9-Sep-23 5:17 
GeneralRe: 1 stable 2 super stable Pin
honey the codewitch9-Sep-23 5:52
mvahoney the codewitch9-Sep-23 5:52 
GeneralRe: 1 stable 2 super stable Pin
Daniel Pfeffer9-Sep-23 7:15
professionalDaniel Pfeffer9-Sep-23 7:15 
GeneralRe: 1 stable 2 super stable Pin
honey the codewitch9-Sep-23 8:11
mvahoney the codewitch9-Sep-23 8:11 
GeneralRe: 1 stable 2 super stable Pin
trønderen9-Sep-23 8:06
trønderen9-Sep-23 8:06 
You've got several different protection mechanisms:

First, that of addressability. A process presents a logical address the memory management system, which will translate it to a physical address. The contents of the MMS tables switches when the CPU switches to another process, so each process will see a different selection of physical pages, even if the logical address is the same. No user process has page table entries pointing to OS data structures, so it cannot reference / modify them.

The translation from logical to physical pages goes through another translation before getting to the page tables: The logical address space is split into segments. Each segment has a minimum privilege level (i.e. ring). On Intel CPUs, 0 is the highest privilege, 3 is minimum. Even if a driver runs in the same logical address space as OS code, some segments of that space could be marked as requiring level 0 (or 1 or 2) for access. Drivers usually run in ring 1 or 2, and if the OS data lies in a ring 0 segment, the driver cannot access it. A process in a given ring have access to all segments of lower (higher numbered) rings, so a ring 0 kernel process can access whatever it wants, as long as it has a page table entry to it. The segment descriptor tells the length of the segment: An attempt to go to a less restricted segment and address out of bounds, into another segment, will fail.

The segment descriptor also indicates the type of segment, one of 16 values (4 bits): A "Read-Only" segment may not be modified, even it it can be read. Typically, the OS will make configuration and state information available to drivers this way, but the drivers cannot modify/corrupt this information. Also, the contents of the segment can not be executed as instructions. An "Execute-Only" segment cannot be read or written, but may be executed. Code segments may allow reading. (The OS may need write access to the data structures, so it constructs a different segment descriptor for its own use.)

On the x86/x64 you can also restrict write access on the page level. Even if the segment generally is accessible, sensitive OS structures may be stored in pages that denies writing. (Both the segment and the page must allow writing.) There is another bit restricting code execution, if this bit is set in the page descriptor.

The ring (also called Privilege Level) of the current process also can restrict access to I/O devices. E.g. the OS may allow users to write drivers to run in ring 2, to gain access to (at least some) OS structures, but do I/O on devices defined as ring 2 (or 3); the driver cannot access e.g. the system disk in ring 1.

Ring 0 is frequently referred to as "Kernel Mode". While the OS may have its own drivers for central devices running in ring 0, it should never let any external driver do so. The great majority of drivers should not run in "Kernel Mode", ring 0. They may still have access to a lot of the OS data structures, a lot of it read only, that ordinary user processes can't access. They may make use of OS code segments in ring 1 or 2, not available to user processes. They won't have the permission to update segment and page table descriptions, manipulate the interrupt system or set ring (privilege) level. They don't need to.

Independent of memory accesses: Some instructions are legal only for processes running in ring 0. Typical examples are setting the pointers to segment or page table structures, done at process switching. (A ring 1 driver may try to construct its own segment descriptors with less restrictions, but it has no way to enter the pointer into the hardware registers.)

Simpler machines often have just two privilege levels, comparable to ring 0 and ring 3 on the x86/x64. Then, drivers usually have all the privileges of the OS, running in "kernel mode". Multi-level ring protection was introduced by Multics in 1969 (so it ought to be well known Smile | :) ), and most processors at the level of 386 and above have some sort of multi-level privilege mechanism.

(Fun final note:
I went to Wikipedia to see when Multics came up with its ring mechanisms, to find that its latest release was 30 days ago, August 10th this year! I would claim that Multics is the most influential OS ever, way beyond Unix/Linux. The very most of *nix is making Multics concepts known to the world, they did not invent it! I am itching to download and study Multics source code, but unfortunately, I know that I won't ever get around to understanding it.)
GeneralRe: 1 stable 2 super stable Pin
honey the codewitch9-Sep-23 8:11
mvahoney the codewitch9-Sep-23 8:11 
GeneralRe: 1 stable 2 super stable Pin
pmauriks10-Sep-23 21:41
pmauriks10-Sep-23 21:41 
GeneralRe: 1 stable 2 super stable Pin
Calin Negru11-Sep-23 3:52
Calin Negru11-Sep-23 3:52 
GeneralRe: 1 stable 2 super stable Pin
sasadler11-Sep-23 5:45
sasadler11-Sep-23 5:45 
GeneralOuch! Team USA shocked by Germany in Basketball World Cup semifinal | CNN Pin
0x01AA8-Sep-23 6:18
mve0x01AA8-Sep-23 6:18 
GeneralCCC 08-09-23 Pin
pkfox7-Sep-23 21:29
professionalpkfox7-Sep-23 21:29 
GeneralRe: CCC 08-09-23 Pin
Peter_in_27807-Sep-23 21:39
professionalPeter_in_27807-Sep-23 21:39 
GeneralRe: CCC 08-09-23 - Winner Pin
pkfox7-Sep-23 21:53
professionalpkfox7-Sep-23 21:53 
GeneralBadger! Pin
Super Lloyd7-Sep-23 20:04
Super Lloyd7-Sep-23 20:04 
GeneralRe: Badger! Pin
OriginalGriff7-Sep-23 21:08
mveOriginalGriff7-Sep-23 21:08 
GeneralRe: Badger! Pin
Richard Deeming7-Sep-23 21:33
mveRichard Deeming7-Sep-23 21:33 
GeneralRe: Badger! Pin
dandy728-Sep-23 8:11
dandy728-Sep-23 8:11 
GeneralRe: Badger! Pin
k50548-Sep-23 10:05
mvek50548-Sep-23 10:05 
GeneralRe: Badger! Pin
jmaida8-Sep-23 10:12
jmaida8-Sep-23 10:12 
GeneralRe: Badger! Pin
BernardIE53178-Sep-23 13:26
BernardIE53178-Sep-23 13:26 
GeneralRe: Badger! Pin
Super Lloyd9-Sep-23 12:53
Super Lloyd9-Sep-23 12:53 
GeneralRe: Badger! Pin
BernardIE531711-Sep-23 4:21
BernardIE531711-Sep-23 4:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.