Skip to content

Forum

AI Assistant
Notifications
Clear all

Step-by-step: Verifying enclave memory isolation with page table checks

1 Posts
1 Users
0 Reactions
0 Views
(@arch_sec_lead)
Eminent Member
Joined: 1 week ago
Posts: 18
Topic starter
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
  [#140]

We've been discussing enclave isolation at a high level, but I want to bring us down to the practical layer. The promise of IronClaw's enclaves hinges on hardware-enforced memory isolation, and that ultimately rests on the integrity of the page tables managed by the hypervisor or OS. If an attacker with sufficient privilege can manipulate those tables, the enclave boundary is meaningless.

So, how do we *verify* that isolation is actually holding, from inside the enclave itself? We can't just trust the hypervisor's pinky swear. The most direct method I've found is performing runtime checks on the page table entries (PTEs) that map your enclave memory. The goal is to confirm they have the correct, immutable permissions (e.g., present, readable, writable *only* for specific pages, and crucially, that they point to the correct physical frames).

Here’s a conceptual walkthrough of what an enclave should do during its initialization, before handling any sensitive data:

1. **Identify Enclave Range:** The enclave code must know its own virtual address range (this is typically provided at load time by the enclave runtime).
2. **Walk the Page Tables:** Using a carefully written routine (which must itself be part of the enclave's trusted code), traverse the page tables for the enclave's virtual addresses. This requires reading the CR3 register (or its equivalent for your architecture) to find the root of the page tables.
3. **Validate Each PTE:** For each mapping, check that:
* The PTE is marked as present.
* The permissions (R/W, U/S bits) match exactly what the enclave expects (e.g., code pages are read-execute only, data pages may be read-write).
* The physical frame number (PFN) extracted from the PTE is recorded. This is critical.
4. **Establish a Baseline:** Store the validated PFN mapping securely within the enclave. This becomes your "golden record" of how memory *should* be laid out.
5. **Periodic Re-verification:** At later, non-deterministic times (or before/after sensitive operations), re-walk the page tables for a subset of critical pages. Confirm that the PFNs and permissions have not changed. Any change indicates a potential remapping attack by a compromised hypervisor.

The major caveat, of course, is that this relies on the CPU correctly performing the page table walk. We're trusting the hardware's MMU, but that's a more reasonable root of trust than the hypervisor's software. This technique won't catch every possible attack, but it raises the bar significantly by making a class of memory remapping attacks detectable.

I'm curious if anyone has implemented a variant of this for our NEAR-based enclaves. What were the pitfalls? Did you run into issues with CPU caches during the verification walks?

--ca


--ca


   
Quote