Ring -2: SMI, SMRAM and RSM, how firmware takes over the CPU below the hypervisor
On this page
Firmware goes first#
When you set up a lab for driver development, the first thing you learn has nothing to do with the kernel. It has to do with the BIOS. In my lab guide I wrote it down like this: virtualization is enabled in the BIOS/UEFI, not in the OS or in the hypervisor. And there's a second lesson in the same vein: with Secure Boot on, Windows won't even let you enable test mode for drivers. The change is rejected with a message that leaves no room for argument: protected by Secure Boot policy.
Both rules say the same thing. The rules of the game are set by something that runs before Windows. What almost nobody mentions is that this something doesn't go away when the operating system starts: part of the firmware stays there, in a CPU mode that neither the kernel nor the hypervisor can see.
In this series we've been going down step by step. In part one we crossed from Ring 3 to Ring 0, the kernel. In part two we met the hypervisor, Ring -1, watching over the kernel from below. Always with the same underlying question: each level watches the one above it, but who watches the one below? Today we reach the CPU's last step: Ring -2, System Management Mode.
What SMM is#
System Management Mode (SMM) is a special mode of x86 CPUs, reserved for firmware. It has existed since the Intel 386SL, back in 1990, and it's still present in every current Intel or AMD processor. Like VMX root in the previous post, it isn't strictly a new ring: it's a different operating mode. But it sits below everything we've seen so far.
You don't enter SMM with a normal instruction or a syscall. You enter it through a special interrupt, the SMI (System Management Interrupt). It can be raised by the chipset or by the hardware itself (on power, thermal or platform events) or by software: on many Intel platforms, writing to I/O port 0xB2 is enough.
When an SMI arrives, the CPU does something it does in no other case:
- It saves its entire state — registers, the mode it was in, where it was — into a special memory region, SMRAM.
- It switches to SMM and runs the firmware's SMI handler, which also lives in SMRAM.
- When it's done, the handler executes the
RSMinstruction (Resume from System Management Mode): the CPU restores the saved state and the system carries on exactly where it was, without knowing it was ever stopped.
The key to SMM's security is SMRAM. It's only accessible while in SMM: the chipset and a set of CPU registers called SMRR (System Management Range Registers) protect it, and the firmware locks it before handing control to the operating system. In the usual configuration, neither the kernel nor the hypervisor can read it, nor can they intercept the SMI. The hypervisor, which saw everything in the previous post, sees nothing here.
SMM is a CPU mode in which the firmware takes over, does its work in memory nobody else can see, and hands the machine back exactly as it was. As far as the operating system is concerned, that time simply never happened.
What it's used for#
It sounds unsettling, but SMM exists for very mundane reasons. It's where the firmware does platform work it can't delegate to the operating system, because it doesn't know which operating system will be running or whether it will behave:
- Power and thermals. Part of power management and of the response to thermal events goes through SMI handlers.
- Legacy hardware emulation. The classic example: a USB keyboard that, during boot, presents itself as a PS/2 keyboard so older software can understand it.
- Firmware services. Protecting writes to the flash chip where the BIOS lives, or storing authenticated UEFI variables (among them the key databases Secure Boot depends on) without the operating system being able to change them on its own.
That last point closes the loop from the beginning. The rules the firmware sets before Windows boots are upheld, in part, by code that keeps running in SMM while Windows is up.
The invisible cost#
There's a price. While an SMI lasts, typically all CPU cores enter SMM, not just the one that received it. The operating system doesn't notice: its clocks keep ticking, but during that time not a single one of its instructions has run. It simply loses that time.
On a desktop it doesn't matter. On a real-time system, where a task has to respond within a guaranteed deadline, it's a serious problem: pauses show up that nothing in the system caused and that no system tool can pin on any process. Linux ships a tracer designed precisely for that, hwlat, which keeps a core spinning and measures the gaps in time it can't explain. It's one of the few ways to notice SMM from outside: not by what it does, but by the time it takes.
Why it's such a sensitive target#
Everything we've seen in this series points to the same conclusion. A bug in Ring 0 compromises the kernel; the hypervisor is there to contain it. A bug in Ring -1 compromises every virtual machine on top of it. A bug in SMM code gives control below even the hypervisor, in a place none of the defenses above can see.
The best-known class of SMM bug has a textbook name: the confused deputy. The SMI handler holds every privilege, but it often works with data the operating system hands it: a buffer with a request, a pointer to where it should leave the answer. If the handler doesn't validate those buffers and pointers, the operating system — or an attacker controlling it — can trick it into reading or writing where it shouldn't, for example inside SMRAM itself. The deputy has the keys; the problem is that it obeys without checking who's asking.
There's no need to go into how that gets exploited. What matters here is the answer: the mitigations the industry has come to require from SMM code target exactly that point.
WSMT: the firmware declares its defenses#
Microsoft defined an ACPI table with a very descriptive name: the Windows SMM Security Mitigations Table (WSMT). With it, the firmware declares that its SMM code applies three protections:
| Bit | Protection | What the firmware declares |
|---|---|---|
| 0 | FIXED_COMM_BUFFERS | It only uses communication buffers in fixed regions, validated by the firmware. |
| 1 | COMM_BUFFER_NESTED_PTR_PROTECTION | It also validates the pointers inside those buffers. |
| 2 | SYSTEM_RESOURCE_PROTECTION | It prevents the operating system from reconfiguring critical platform resources. |
The first two are the direct answer to the confused deputy: the handler only accepts requests in known places and checks every pointer before following it. The third stops the operating system from changing the hardware configuration that SMM's protection depends on.
Windows checks this table to decide whether it trusts the firmware for the Virtualization-Based Security (VBS) features we saw in Ring -1. It makes perfect sense: there's little point in the hypervisor protecting the kernel if, below the hypervisor, there's code that can go around it. Secured-core PCs go further and add Intel and AMD mechanisms that isolate or supervise the SMM code itself, so they don't depend solely on it being well written.
The WSMT is what the firmware says about itself. From the operating system you can't see SMM or check that the code does what it declares. A table with all three protections set is a good sign, not a guarantee that your machine is secure.
Check it yourself#
Windows exposes firmware tables to any program, without administrator rights, through two functions: EnumSystemFirmwareTables lists the ones available and GetSystemFirmwareTable returns the contents of one. This program lists your machine's ACPI tables and reads the WSMT. Unlike the previous parts, this code is Windows-only:
// g++ -std=c++20 firmware.cpp -o firmware.exe (Windows)
// Lists the firmware's ACPI tables and reads the WSMT, where the
// firmware declares which protections it applies to its SMM code.
#include <windows.h>
#include <cstdint>
#include <cstring>
#include <format>
#include <iostream>
#include <string>
#include <vector>
// The provider is encoded with its first character in the high byte...
constexpr DWORD provider(const char s[5]) {
return DWORD(s[0]) << 24 | DWORD(s[1]) << 16
| DWORD(s[2]) << 8 | DWORD(s[3]);
}
// ...and a table's signature, with its bytes in memory order.
DWORD table(const char s[5]) {
DWORD v;
std::memcpy(&v, s, 4);
return v;
}
int main() {
const DWORD acpi = provider("ACPI");
// 1. Which tables exist: each entry is its 4-byte signature.
std::vector<char> ids(EnumSystemFirmwareTables(acpi, nullptr, 0));
EnumSystemFirmwareTables(acpi, ids.data(), DWORD(ids.size()));
std::cout << "ACPI tables:";
for (size_t i = 0; i + 4 <= ids.size(); i += 4)
std::cout << (i % 36 ? " " : "\n ") << std::string(&ids[i], 4);
std::cout << '\n';
// 2. WSMT: ACPI header (36 bytes) + ProtectionFlags (4 bytes).
const DWORD wsmt = table("WSMT");
DWORD size = GetSystemFirmwareTable(acpi, wsmt, nullptr, 0);
if (size < 40) {
std::cout << "WSMT: not present\n";
return 0;
}
std::vector<uint8_t> t(size);
GetSystemFirmwareTable(acpi, wsmt, t.data(), size);
uint32_t flags;
std::memcpy(&flags, t.data() + 36, 4);
const char* names[] = {"FIXED_COMM_BUFFERS",
"COMM_BUFFER_NESTED_PTR_PROTECTION",
"SYSTEM_RESOURCE_PROTECTION"};
std::cout << std::format("WSMT ProtectionFlags = 0x{:X}\n", flags);
for (int bit = 0; bit < 3; ++bit)
std::cout << std::format(" {:<34}{}\n", names[bit],
(flags >> bit) & 1 ? "yes" : "no");
}This is the real output on my machine, an Intel Core i9-14900KF running Windows 11:
ACPI tables:
DBGP MCFG FACP APIC DMAR HPET FPDT FIDT SSDT
SSDT SSDT SSDT SSDT UEFI NHLT LPIT SSDT SSDT
DBG2 SSDT SSDT SSDT SSDT PHAT TPM2 WSMT BGRT
WSMT ProtectionFlags = 0x7
FIXED_COMM_BUFFERS yes
COMM_BUFFER_NESTED_PTR_PROTECTION yes
SYSTEM_RESOURCE_PROTECTION yesProtectionFlags = 0x7 means all three bits are set: the firmware declares all three protections. But the list of tables deserves a second look, because two more links of the security chain show up in it:
DMARis the table describing Intel's IOMMU (VT-d). The IOMMU does for devices what EPT tables do for virtual machines: it decides which memory each device can reach through DMA. It's the hardware Windows relies on for Kernel DMA Protection, which stops a connected device from reading or writing system memory at will.TPM2describes the TPM chip, the root of boot measurements: each boot stage is measured and recorded in it before it runs.
How the signatures are encoded#
The most curious detail in the code is the pair of functions at the top, which turn four letters into a DWORD in two different ways. It isn't a whim: that's how the API expects them.
The provider ('ACPI') is encoded with its first character in the high byte, the way a multi-character literal would be written: 0x41435049, with the A (0x41) in front. A table signature, on the other hand, is passed with its bytes in the same order they appear in memory, which is how it's stored in the ACPI table itself. On x86, which is little-endian, "WSMT" therefore becomes 0x544D5357: the W (0x57) ends up in the low byte. That's why table() uses memcpy, which copies the bytes as they are, instead of shifts. Get the order wrong and nothing obvious breaks: GetSystemFirmwareTable looks for a table that doesn't exist, returns 0, and the program reports no WSMT even when there is one.
The rest follows the anatomy of the WSMT: a standard 36-byte ACPI header, shared by every table, followed by a single 4-byte field, ProtectionFlags. That's why the program requires at least 40 bytes before reading anything and takes the flags from offset 36. (The 36 in the listing loop is something else: 9 four-byte signatures per line.)
There's no unprivileged equivalent here. Linux exposes ACPI tables under /sys/firmware/acpi/tables/, and the WSMT, if present, is at /sys/firmware/acpi/tables/WSMT, but reading it requires root. What you'll find is the same structure: 36 bytes of header and 4 of flags.
Ring -3, in one sentence#
Below SMM there's no CPU left. But outside the main CPU live microcontrollers with their own firmware — Intel ME / CSME on Intel, AMD PSP on AMD — that handle secure boot, the firmware TPM and remote management, and that can keep running while the main CPU is asleep. Some call them Ring -3. They're another computer inside your computer, and with that the ladder is complete.
The full ladder#
I've never written SMM code, and this post doesn't pretend otherwise. But in my lab guides for driver and hypervisor development I put down in writing two warnings that sum up this post: that virtualization is decided in the BIOS/UEFI and not in the operating system, and that with Secure Boot on, driver test mode is blocked. They're the same idea seen from above: before the kernel or the hypervisor decide anything, the firmware has already decided for them.
Three posts later, this is the ladder we've climbed down:
| Level | Who lives there | Who watches it |
|---|---|---|
| Ring 3 | Your applications | The kernel |
| Ring 0 | The kernel and drivers | The hypervisor, with VBS and HVCI |
| Ring -1 | The hypervisor | Verified and measured boot (Secure Boot, TPM) |
| Ring -2 | SMM, the running firmware | What the firmware declares (WSMT) and, on Secured-core PCs, Intel and AMD mechanisms |
| Ring -3 | Intel ME / CSME, AMD PSP | Nobody from above: you trust the vendor |
The right-hand column tells the story of the series. Each level protects the one above it, and each time it gets harder to find someone below to protect the protector. That's why the security of a modern system isn't a wall but a chain: application, kernel, hypervisor, firmware. And the lowest link in that chain, the one holding up all the others, is the firmware.
If you've started with this post, the series starts at From Ring 3 to Ring 0 and continues with Ring -1: the hypervisor watching over your kernel.
Next time you go into the BIOS to turn on virtualization, remember who you're talking to: the only level that will still be there, unseen, while the operating system thinks it's in charge.
References
- Intel® 64 and IA-32 Architectures Software Developer's ManualsIntel · intel.com
- ACPI System Description Tables: Windows SMM Security Mitigations Table (WSMT)Microsoft · learn.microsoft.com
- Windows SMM Security Mitigations Table (WSMT) specification (DOCX)Microsoft · download.microsoft.com
- GetSystemFirmwareTable function (sysinfoapi.h)Microsoft · learn.microsoft.com
- EnumSystemFirmwareTables function (sysinfoapi.h)Microsoft · learn.microsoft.com
- Hardware Latency DetectorLinux kernel documentation · docs.kernel.org
Share
Does your project need to go below the application layer?
Systems software, performance and security on Windows and Linux: diagnostics, custom tooling and low-level code review.
Let's talk→
Comments
Commenting requires a GitHub account. Comments live in GitHub Discussions (SoftDryzz/blog-comments) and are moderated: no promotional links.