| 1 | # Memory clearing |
| 2 | |
| 3 | The main memory on computer platforms in high security environments contains |
| 4 | sensible data. On unexpected reboot the data might persist and could be |
| 5 | read by a malicious application in the bootflow or userspace. |
| 6 | |
| 7 | In order to prevent leaking information from pre-reset, the boot firmware can |
| 8 | clear the main system memory on boot, wiping all information. |
| 9 | |
| 10 | A common API indicates if the main memory has to be cleared. That could be |
| 11 | on user request or by a Trusted Execution Environment indicating that secrets |
| 12 | are in memory. |
| 13 | |
| 14 | As every platform has different bring-up mechanisms and memory-layouts, every |
| 15 | The device must indicate support for memory clearing as part of the boot |
| 16 | process. |
| 17 | |
| 18 | ## Requirements |
| 19 | |
| 20 | 1. The platform must clear all platform memory (DRAM) if requested |
| 21 | 2. Code that is placed in DRAM might be skipped (as workaround) |
| 22 | 3. Stack that is placed in DRAM might be skipped (as workaround) |
| 23 | 4. All DRAM is cleared with zeros |
| 24 | |
| 25 | ## Implementation |
| 26 | |
| 27 | A platform that supports memory clearing selects Kconfig |
| 28 | ``PLATFORM_HAS_DRAM_CLEAR`` and calls |
| 29 | |
| 30 | ```C |
| 31 | bool security_clear_dram_request(void); |
| 32 | ``` |
| 33 | |
| 34 | to detect if memory should be cleared. |
| 35 | |
| 36 | The memory is cleared in ramstage as part of `DEV_INIT` stage. It's possible to |
| 37 | clear it earlier on some platforms, but on x86 MTRRs needs to be programmed |
| 38 | first, which happens in `DEV_INIT`. |
| 39 | |
| 40 | Without MTRRs (and caches enabled) clearing memory takes multiple seconds. |
| 41 | ## Exceptions |
| 42 | |
| 43 | As some platforms place code and stack in DRAM (FSP1.0), the regions can be |
| 44 | skipped. |
| 45 | |
| 46 | ## Architecture specific implementations |
| 47 | |
| 48 | ```{toctree} |
| 49 | :maxdepth: 1 |
| 50 | |
| 51 | x86 PAE <../arch/x86/pae.md> |
| 52 | ``` |