{
  "url": "https://danielmangum.com/posts/how-immutable-rot/",
  "title": "How Immutable is Your Immutable Root of Trust?",
  "byline": "Daniel Mangum",
  "leadImage": "https://danielmangum.com/images/twitter-card.png",
  "wordCount": 1542,
  "readingTimeMinutes": 7,
  "cacheStatus": "HIT",
  "markdown": "# How Immutable is Your Immutable Root of Trust?\n\nWhen I was growing up, one of my favorite movies was [The Pink Panther (2006)](https://www.imdb.com/title/tt0383216/). Though there are quite a few classic exchanges in the film, [one in particular](https://youtu.be/eu-afVml4MM?si=XQFJFq_fygs3QyN4&t=111) has stuck with me over the years.\n\n> **Ponton:** He was just found dead in the training facility locker room. Shot in the head.\n> \n> **Clouseau:** Was it fatal?\n> \n> **Ponton:** Yes.\n> \n> **Clouseau:** How fatal?\n> \n> **Ponton:** _(confused)_ Completely.\n> \n> **Clouseau:** I want to talk to him now.\n> \n> **Ponton:** He’s dead.\n> \n> **Clouseau:** Ah!\n\nNon-gradable adjectives, such as “fatal”, are useful because they are unambiguous. When it comes to mortality, we are all operating under the same context; there is no scenario in our universe in which a human can survive or return to life from a fatal event. Therein lies the comedy of Clouseau’s clarification. However, sometimes clarification is required in the use of a non-gradable adjective.\n\nIn my [most recent post](https://danielmangum.com/posts/tragedy-oxide-rot/), I wrote about the complexity of secure manufacturing and device provisioning. A key component to building a secure system is establishing a root of trust (RoT). In order for a RoT to be trusted, there needs to be some mechanism that enforces _immutability_ of the code and data that it is comprised of. It is fairly obvious that you cannot trust a component if that component can be arbitrarily modified. For this reason, you will frequently see the first stage of a RoT referred to as an **Immutable Root of Trust (IRoT)**.\n\nIn order for any system to offer immutable qualities, the underlying substrate must expose features to configure the mutability of data. For example, many programming languages support immutable data types or bindings. In Rust, for example, all variables are [immutable by default](https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html). Depending on whether the language is compiled or interpreted, immutability properties may be enforced by the compiler or the runtime.\n\nWhen it comes to devices, the underlying substrate is the hardware. In order for the first instructions that run on the processor to be trusted, the hardware must expose some functionality that allows for making those instructions, and typically some of the data they access, immutable. However, because hardware architecture varies from one silicon vendor to another, and even from one part to another within a single vendor, immutability may be enforced through very different mechanisms. While one mechanism is not strictly better than another, understanding how each behaves is important when performing threat modeling.\n\n## The Mechanisms of Hardware-Enforced Immutability\n\nThe first, and perhaps most intuitive, mechanism is **mask ROM**. [Mask ROM](https://en.wikipedia.org/wiki/Read-only_memory#Solid-state_ROM) encodes data into the circuitry of silicon at time of fabrication. Just like the instruction set architecture of a CPU, or the registers of a peripheral, it is the same across every unit and cannot be modified. Because of this, mask ROM is most commonly used for initialization or bootloader code rather than public key material or other data that may differ across customers1 or even individual units.\n\nThough mask ROM is technically fixed, the ramifications of shipping code that contains a bug frequently causes silicon vendors to offer the ability to patch the ROM code at runtime. This is a good example of a threat vector that may be overlooked without a deep understanding of a part. In fact, in the [NXP LPC55S69](https://www.nxp.com/products/LPC55S6x) MCU that [Oxide](https://oxide.computer/), the company I wrote about in the aforementioned post, uses for its hardware RoT, there is a ROM patching capability that [Oxide engineers discovered](https://oxide.computer/blog/exploiting-undocumented-hardware-blocks-in-the-lpc55s69) could leave the part vulnerable to attack because it was exposed to the [TrustZone-M](https://www.arm.com/technologies/trustzone-for-cortex-m) [non-secure processing environment (NSPE)](https://danielmangum.com/posts/arm-cortex-m-security-state-gdb/).\n\n**One time programmable (OTP)** memory is a slightly more flexible option for hardware-enforced immutability. Rather than being fixed across every unit, OTP, which is typically implemented as [antifuses or eFuses](https://semiengineering.com/the-benefits-of-antifuse-otp/), can be written once, causing a physical change to the circuitry that cannot be reversed2. This makes it a natural candidate for storing something like a public signing key that may be used by an initial bootloader stored in mask ROM to verify that the next code to execute is signed by the silicon vendor’s customer. It could also be used by a silicon vendor to program values that differ from one unit to the next after fabrication (e.g. a unique identifier).\n\nThe term OTP is used fairly liberally in datasheets, and it may not always mean that you are literally blowing fuses. For example, at [Nordic Semiconductor](https://www.nordicsemi.com/)3, we use the term **emulated OTP** to describe the common [User Information Configuration Registers (UICR)](https://docs.nordicsemi.com/r/bundle/ps_nrf54lm20a/page/uicr.html) that are present in many of our products and allow the customer to configure [access port](https://danielmangum.com/posts/whats-on-that-access-port/) protection, erase protection, signing keys, immutable bootloader regions, and more. In this case, programming the registers does not physically change the hardware, but rather causes the memory controller to prevent subsequent writes to the region. This offers immutability with an arguably more friendly user experience; the customer can erase the memory, including the OTP regions, and write to it again, but only if they erase the _entire_ device and only if erase protection has not been enabled. It also gives the customer more visibility into _exactly_ what instructions are being executed at boot, as they are responsible for installing the immutable bootloader.\n\nOne downside to this solution, as opposed to true OTP or mask ROM, is that the customer must ensure that they configure the device correctly. For example, if access port and erase protection is not enabled, an attacker could erase all memory, then program malicious firmware onto a device in the possession of an end user. One could make a valid argument that a customer programming mistake bricking a device is a superior scenario to leaving a device vulnerable. However, mask ROM and OTP do not eliminate the possibility of a customer leaving a device unprotected. In other words, the memory technology is not the only attribute that must be considered when evaluating protection capabilities of the hardware.\n\nThe same mechanism that enables emulated OTP functionality can also be used for general **configurable immutability**4. While the memory addresses of the UICRs themselves are always enforced as an immutable region by the hardware, the addresses programmed by the customer into that region, such as the value stored in the [`BOOTCONF` UICR](https://docs.nordicsemi.com/r/bundle/ps_nrf54lm20a/page/uicr.html-register.bootconf) on the [nRF54LM20](https://www.nordicsemi.com/Products/nRF54LM20B), may cause the hardware to enforce immutability of a region before the device comes out of reset (i.e. before the first instruction is executed). In the case of the nRF54LM20, the _emulated OTP_ of the `BOOTCONF` UICR and the _configurable immutability_ of the address region programmed into the `BOOTCONF` UICR combine to provide an immutable RoT. The former restricts changing the configured location of the immutable bootloader, while the latter restricts changing the immutable bootloader code itself5.\n\nThe final hardware mechanism that can be used to enforce immutability is **runtime immutability**6. Once again powered by features of memory controller hardware, runtime immutability enables software to configure immutable regions at, well, runtime. This sounds a lot like configurable immutability, with the primary difference being that any immutability configured at runtime is cleared on device reset. A common use case for this functionality is protection of a second stage bootloader. Looking at the nRF54LM20 again, the [RRAMC](https://docs.nordicsemi.com/r/bundle/ps_nrf54lm20a/page/rramc.html) (resistive random access memory controller) includes `REGION[n].ADDRESS` and `REGION[n].CONFIG` [registers](https://docs.nordicsemi.com/r/bundle/ps_nrf54lm20a/page/rramc.html-rram_region_protection). If using the standard [nRF Secure Immutable Bootloader (NSIB or `b0`)](https://academy.nordicsemi.com/courses/nrf54l-series-express-course/lessons/lesson-4-security-features/topic/secure-boot-and-secure-attestation/), [MCUboot](https://docs.mcuboot.com/), and [TrustedFirmware-M](https://www.trustedfirmware.org/projects/tf-m/) setup, NSIB, which is immutable due to prior provisioning of the `BOOTCONF` register, will validate the MCUboot image, then can configure additional read and execute protection to its own region, before finally applying write protection to the MCUboot region. The protections in both of these cases are necessary to be applied at runtime. The CPU must be able to read and execute the NSIB code on reset, and only the active MCUboot slot should be locked for writing. The [latter](https://github.com/nrfconnect/sdk-nrf/blob/c94d45d77c68cdaee17091b4fc31aedad0b89235/subsys/bootloader/bl_boot/bl_boot.c#L79-L114) is shown below.\n\n```c\nstatic int disable_next_w(const uint32_t address)\n{\n\tuint32_t region_size_kb = 0;\n\n\tif (address == S0_IMAGE_ADDRESS) {\n\t\tregion_size_kb = S0_IMAGE_SIZE / NRF_RRAM_REGION_SIZE_UNIT;\n\t} else if (address == S1_IMAGE_ADDRESS) {\n\t\tregion_size_kb = S1_IMAGE_SIZE / NRF_RRAM_REGION_SIZE_UNIT;\n\t} else {\n\t\treturn -EINVAL;\n\t}\n\n\tnrf_rramc_region_config_t config = {\n\t\t.address = address,\n\t\t.permissions =  NRF_RRAMC_REGION_PERM_READ_MASK |\n\t\t\t\tNRF_RRAMC_REGION_PERM_EXECUTE_MASK,\n\t\t.writeonce = false,\n\t\t/* There are no issues with locking the region here,\n\t\t * as the next stage can still impose more strict\n\t\t * protection by writing 0 to R/X disable bits.\n\t\t */\n\t\t.lock = true,\n\t\t.size_kb = region_size_kb,\n\t};\n\n\tnrf_rramc_region_config_set(NRF_RRAMC, RRAMC_REGION_FOR_NEXT_W, &config);\n\tnrf_rramc_region_config_get(NRF_RRAMC, RRAMC_REGION_FOR_NEXT_W, &config);\n\tif (config.permissions & (NRF_RRAMC_REGION_PERM_WRITE_MASK)) {\n\t\treturn -ENOSPC;\n\t}\n\tif (config.size_kb != region_size_kb) {\n\t\treturn -ENOSPC;\n\t}\n\n\treturn 0;\n}\n```\n\n## Navigating the Complexity\n\nWhile there are good reasons why each of these mechanisms are leveraged, the complexity they introduce can sometimes get in the way of accomplishing the ultimate goal: building a secure system. Reiterating the call to action from my [last post](https://danielmangum.com/posts/tragedy-oxide-rot/), it is not enough for those of us working in the semiconductor industry to make it possible for customers to build secure systems. We must make building securely easier than not. On our way there, join me in sharing more publicly about how these mechanisms work, and how your organization is going about building secure systems.\n\n* * *\n\n1.  “Customer”, used extensively throughout this post, refers to the customer of a silicon vendor. The customer of the silicon vendor’s customer (i.e. the purchaser of the final good) is referred to as the “end user”. ↩︎\n    \n2.  With enough time and money, [almost anything can be compromised](https://www.ioactive.com/raspberry-pi-2350-hacking-challenge/) when it comes to hardware security. ↩︎\n    \n3.  Disclaimer: I [work here](https://danielmangum.com/posts/farewell-golioth-hello-nordic/)! ↩︎\n    \n4.  This is my own moniker, rather than an industry standard term. Most silicon vendors do not make strong distinctions between these types of hardware mechanisms. ↩︎\n    \n5.  While certainly not the only thing to look for, determining whether you can mutate code or data, or mutate the pointer to the code or data, constitutes a large portion of RoT threat modeling. ↩︎\n    \n6.  This is again my own term for the functionality. ↩︎",
  "html": "<h1>How Immutable is Your Immutable Root of Trust?</h1>\n<p>When I was growing up, one of my favorite movies was <a href=\"https://www.imdb.com/title/tt0383216/\">The Pink Panther (2006)</a>. Though there are quite a few classic exchanges in the film, <a href=\"https://youtu.be/eu-afVml4MM?si=XQFJFq_fygs3QyN4&amp;t=111\">one in particular</a> has stuck with me over the years.</p>\n<blockquote>\n<p><strong>Ponton:</strong> He was just found dead in the training facility locker room. Shot in the head.</p>\n<p><strong>Clouseau:</strong> Was it fatal?</p>\n<p><strong>Ponton:</strong> Yes.</p>\n<p><strong>Clouseau:</strong> How fatal?</p>\n<p><strong>Ponton:</strong> <em>(confused)</em> Completely.</p>\n<p><strong>Clouseau:</strong> I want to talk to him now.</p>\n<p><strong>Ponton:</strong> He’s dead.</p>\n<p><strong>Clouseau:</strong> Ah!</p>\n</blockquote>\n<p>Non-gradable adjectives, such as “fatal”, are useful because they are unambiguous. When it comes to mortality, we are all operating under the same context; there is no scenario in our universe in which a human can survive or return to life from a fatal event. Therein lies the comedy of Clouseau’s clarification. However, sometimes clarification is required in the use of a non-gradable adjective.</p>\n<p>In my <a href=\"https://danielmangum.com/posts/tragedy-oxide-rot/\">most recent post</a>, I wrote about the complexity of secure manufacturing and device provisioning. A key component to building a secure system is establishing a root of trust (RoT). In order for a RoT to be trusted, there needs to be some mechanism that enforces <em>immutability</em> of the code and data that it is comprised of. It is fairly obvious that you cannot trust a component if that component can be arbitrarily modified. For this reason, you will frequently see the first stage of a RoT referred to as an <strong>Immutable Root of Trust (IRoT)</strong>.</p>\n<p>In order for any system to offer immutable qualities, the underlying substrate must expose features to configure the mutability of data. For example, many programming languages support immutable data types or bindings. In Rust, for example, all variables are <a href=\"https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html\">immutable by default</a>. Depending on whether the language is compiled or interpreted, immutability properties may be enforced by the compiler or the runtime.</p>\n<p>When it comes to devices, the underlying substrate is the hardware. In order for the first instructions that run on the processor to be trusted, the hardware must expose some functionality that allows for making those instructions, and typically some of the data they access, immutable. However, because hardware architecture varies from one silicon vendor to another, and even from one part to another within a single vendor, immutability may be enforced through very different mechanisms. While one mechanism is not strictly better than another, understanding how each behaves is important when performing threat modeling.</p>\n<h2>The Mechanisms of Hardware-Enforced Immutability</h2>\n<p>The first, and perhaps most intuitive, mechanism is <strong>mask ROM</strong>. <a href=\"https://en.wikipedia.org/wiki/Read-only_memory#Solid-state_ROM\">Mask ROM</a> encodes data into the circuitry of silicon at time of fabrication. Just like the instruction set architecture of a CPU, or the registers of a peripheral, it is the same across every unit and cannot be modified. Because of this, mask ROM is most commonly used for initialization or bootloader code rather than public key material or other data that may differ across customers1 or even individual units.</p>\n<p>Though mask ROM is technically fixed, the ramifications of shipping code that contains a bug frequently causes silicon vendors to offer the ability to patch the ROM code at runtime. This is a good example of a threat vector that may be overlooked without a deep understanding of a part. In fact, in the <a href=\"https://www.nxp.com/products/LPC55S6x\">NXP LPC55S69</a> MCU that <a href=\"https://oxide.computer/\">Oxide</a>, the company I wrote about in the aforementioned post, uses for its hardware RoT, there is a ROM patching capability that <a href=\"https://oxide.computer/blog/exploiting-undocumented-hardware-blocks-in-the-lpc55s69\">Oxide engineers discovered</a> could leave the part vulnerable to attack because it was exposed to the <a href=\"https://www.arm.com/technologies/trustzone-for-cortex-m\">TrustZone-M</a> <a href=\"https://danielmangum.com/posts/arm-cortex-m-security-state-gdb/\">non-secure processing environment (NSPE)</a>.</p>\n<p><strong>One time programmable (OTP)</strong> memory is a slightly more flexible option for hardware-enforced immutability. Rather than being fixed across every unit, OTP, which is typically implemented as <a href=\"https://semiengineering.com/the-benefits-of-antifuse-otp/\">antifuses or eFuses</a>, can be written once, causing a physical change to the circuitry that cannot be reversed2. This makes it a natural candidate for storing something like a public signing key that may be used by an initial bootloader stored in mask ROM to verify that the next code to execute is signed by the silicon vendor’s customer. It could also be used by a silicon vendor to program values that differ from one unit to the next after fabrication (e.g. a unique identifier).</p>\n<p>The term OTP is used fairly liberally in datasheets, and it may not always mean that you are literally blowing fuses. For example, at <a href=\"https://www.nordicsemi.com/\">Nordic Semiconductor</a>3, we use the term <strong>emulated OTP</strong> to describe the common <a href=\"https://docs.nordicsemi.com/r/bundle/ps_nrf54lm20a/page/uicr.html\">User Information Configuration Registers (UICR)</a> that are present in many of our products and allow the customer to configure <a href=\"https://danielmangum.com/posts/whats-on-that-access-port/\">access port</a> protection, erase protection, signing keys, immutable bootloader regions, and more. In this case, programming the registers does not physically change the hardware, but rather causes the memory controller to prevent subsequent writes to the region. This offers immutability with an arguably more friendly user experience; the customer can erase the memory, including the OTP regions, and write to it again, but only if they erase the <em>entire</em> device and only if erase protection has not been enabled. It also gives the customer more visibility into <em>exactly</em> what instructions are being executed at boot, as they are responsible for installing the immutable bootloader.</p>\n<p>One downside to this solution, as opposed to true OTP or mask ROM, is that the customer must ensure that they configure the device correctly. For example, if access port and erase protection is not enabled, an attacker could erase all memory, then program malicious firmware onto a device in the possession of an end user. One could make a valid argument that a customer programming mistake bricking a device is a superior scenario to leaving a device vulnerable. However, mask ROM and OTP do not eliminate the possibility of a customer leaving a device unprotected. In other words, the memory technology is not the only attribute that must be considered when evaluating protection capabilities of the hardware.</p>\n<p>The same mechanism that enables emulated OTP functionality can also be used for general <strong>configurable immutability</strong>4. While the memory addresses of the UICRs themselves are always enforced as an immutable region by the hardware, the addresses programmed by the customer into that region, such as the value stored in the <a href=\"https://docs.nordicsemi.com/r/bundle/ps_nrf54lm20a/page/uicr.html-register.bootconf\"><code>BOOTCONF</code> UICR</a> on the <a href=\"https://www.nordicsemi.com/Products/nRF54LM20B\">nRF54LM20</a>, may cause the hardware to enforce immutability of a region before the device comes out of reset (i.e. before the first instruction is executed). In the case of the nRF54LM20, the <em>emulated OTP</em> of the <code>BOOTCONF</code> UICR and the <em>configurable immutability</em> of the address region programmed into the <code>BOOTCONF</code> UICR combine to provide an immutable RoT. The former restricts changing the configured location of the immutable bootloader, while the latter restricts changing the immutable bootloader code itself5.</p>\n<p>The final hardware mechanism that can be used to enforce immutability is <strong>runtime immutability</strong>6. Once again powered by features of memory controller hardware, runtime immutability enables software to configure immutable regions at, well, runtime. This sounds a lot like configurable immutability, with the primary difference being that any immutability configured at runtime is cleared on device reset. A common use case for this functionality is protection of a second stage bootloader. Looking at the nRF54LM20 again, the <a href=\"https://docs.nordicsemi.com/r/bundle/ps_nrf54lm20a/page/rramc.html\">RRAMC</a> (resistive random access memory controller) includes <code>REGION[n].ADDRESS</code> and <code>REGION[n].CONFIG</code> <a href=\"https://docs.nordicsemi.com/r/bundle/ps_nrf54lm20a/page/rramc.html-rram_region_protection\">registers</a>. If using the standard <a href=\"https://academy.nordicsemi.com/courses/nrf54l-series-express-course/lessons/lesson-4-security-features/topic/secure-boot-and-secure-attestation/\">nRF Secure Immutable Bootloader (NSIB or <code>b0</code>)</a>, <a href=\"https://docs.mcuboot.com/\">MCUboot</a>, and <a href=\"https://www.trustedfirmware.org/projects/tf-m/\">TrustedFirmware-M</a> setup, NSIB, which is immutable due to prior provisioning of the <code>BOOTCONF</code> register, will validate the MCUboot image, then can configure additional read and execute protection to its own region, before finally applying write protection to the MCUboot region. The protections in both of these cases are necessary to be applied at runtime. The CPU must be able to read and execute the NSIB code on reset, and only the active MCUboot slot should be locked for writing. The <a href=\"https://github.com/nrfconnect/sdk-nrf/blob/c94d45d77c68cdaee17091b4fc31aedad0b89235/subsys/bootloader/bl_boot/bl_boot.c#L79-L114\">latter</a> is shown below.</p>\n<pre><code class=\"language-c\">static int disable_next_w(const uint32_t address)\n{\n\tuint32_t region_size_kb = 0;\n\n\tif (address == S0_IMAGE_ADDRESS) {\n\t\tregion_size_kb = S0_IMAGE_SIZE / NRF_RRAM_REGION_SIZE_UNIT;\n\t} else if (address == S1_IMAGE_ADDRESS) {\n\t\tregion_size_kb = S1_IMAGE_SIZE / NRF_RRAM_REGION_SIZE_UNIT;\n\t} else {\n\t\treturn -EINVAL;\n\t}\n\n\tnrf_rramc_region_config_t config = {\n\t\t.address = address,\n\t\t.permissions =  NRF_RRAMC_REGION_PERM_READ_MASK |\n\t\t\t\tNRF_RRAMC_REGION_PERM_EXECUTE_MASK,\n\t\t.writeonce = false,\n\t\t/* There are no issues with locking the region here,\n\t\t * as the next stage can still impose more strict\n\t\t * protection by writing 0 to R/X disable bits.\n\t\t */\n\t\t.lock = true,\n\t\t.size_kb = region_size_kb,\n\t};\n\n\tnrf_rramc_region_config_set(NRF_RRAMC, RRAMC_REGION_FOR_NEXT_W, &amp;config);\n\tnrf_rramc_region_config_get(NRF_RRAMC, RRAMC_REGION_FOR_NEXT_W, &amp;config);\n\tif (config.permissions &amp; (NRF_RRAMC_REGION_PERM_WRITE_MASK)) {\n\t\treturn -ENOSPC;\n\t}\n\tif (config.size_kb != region_size_kb) {\n\t\treturn -ENOSPC;\n\t}\n\n\treturn 0;\n}\n</code></pre>\n<h2>Navigating the Complexity</h2>\n<p>While there are good reasons why each of these mechanisms are leveraged, the complexity they introduce can sometimes get in the way of accomplishing the ultimate goal: building a secure system. Reiterating the call to action from my <a href=\"https://danielmangum.com/posts/tragedy-oxide-rot/\">last post</a>, it is not enough for those of us working in the semiconductor industry to make it possible for customers to build secure systems. We must make building securely easier than not. On our way there, join me in sharing more publicly about how these mechanisms work, and how your organization is going about building secure systems.</p>\n<hr />\n<ol>\n<li><p>“Customer”, used extensively throughout this post, refers to the customer of a silicon vendor. The customer of the silicon vendor’s customer (i.e. the purchaser of the final good) is referred to as the “end user”. ↩︎</p>\n</li>\n<li><p>With enough time and money, <a href=\"https://www.ioactive.com/raspberry-pi-2350-hacking-challenge/\">almost anything can be compromised</a> when it comes to hardware security. ↩︎</p>\n</li>\n<li><p>Disclaimer: I <a href=\"https://danielmangum.com/posts/farewell-golioth-hello-nordic/\">work here</a>! ↩︎</p>\n</li>\n<li><p>This is my own moniker, rather than an industry standard term. Most silicon vendors do not make strong distinctions between these types of hardware mechanisms. ↩︎</p>\n</li>\n<li><p>While certainly not the only thing to look for, determining whether you can mutate code or data, or mutate the pointer to the code or data, constitutes a large portion of RoT threat modeling. ↩︎</p>\n</li>\n<li><p>This is again my own term for the functionality. ↩︎</p>\n</li>\n</ol>\n"
}