Architecture Security & Reliability

a privilege level

Think of a building where a tenant can enter only their own apartment, the building manager can enter any apartment, and the city utility crew can shut off power to the whole block. Each holds a different level of authority, and the locks enforce it. A CPU works the same way: at any moment it runs in one of a few privilege levels, and the hardware itself decides which instructions and which memory that level is allowed to touch. This is the bedrock of protection and isolation in a computer.

Concretely, ordinary applications run in user mode — the least privileged level. In user mode, certain powerful instructions (halt the CPU, change the page tables, talk directly to a device, alter the privilege level) are simply not allowed; if a user program tries one, the hardware traps and the operating system steps in. The operating system kernel runs in a more privileged mode (often called kernel or supervisor mode) where those instructions are permitted, because the kernel must manage memory, schedule processes, and drive devices. Crossing the boundary is deliberate and controlled: a user program asks the kernel for a privileged service through a system call, which is the only sanctioned doorway up (see system-call). Many systems add a third, still-more-privileged level for a hypervisor, so one machine can safely run several isolated virtual machines.

Why is this in hardware and not just software? Because software you do not trust cannot be relied on to police itself. The privilege check lives in silicon, so a buggy or malicious user program physically cannot execute a privileged instruction or read kernel memory — the CPU refuses. This hardware-enforced boundary is what lets your machine run an untrusted web page and your bank's app side by side without one stealing the other's secrets. It is also the line that the most serious microarchitectural attacks, Meltdown above all, were so alarming for crossing (see meltdown-vulnerability).

A user program executes an instruction to disable interrupts (a privileged operation). Because the CPU is in user mode, the hardware refuses: it raises a trap, transfers control to the kernel in supervisor mode, and the kernel decides what to do — usually kill the misbehaving program. The user program could not flip that switch even though the bits of the instruction were valid; the privilege level blocked it.

Same instruction bits, different outcome by mode: privilege is enforced by the CPU, not by the program's good behaviour.

Privilege levels protect against bugs and ordinary attacks, but they are a logical boundary the microarchitecture can leak around. Meltdown showed speculative execution could read kernel memory a user level should never see — the level held, but a side channel went under it.

Also called
protection ringprivilege ringCPU mode保護環處理器模式