6

RPMB is a special partition in eMMC 4.5. Internet research suggests that it is used for saving keys and is the only special partition that responds to commands like READ, WRITE. etc. Can anyone explain to me how to use RPMB and how it can actually mitigate replay attacks?

forest
  • 64,616
  • 20
  • 206
  • 257
Satya
  • 61
  • 1
  • 1
  • 5

2 Answers2

7

RPMB can be used using mmc-utils.

It can withstand replay attacks by requiring a key to write to this region. The rpmb has a key that can be programmed once. Later, the host reads a counter value from the rpmb. It uses this counter value and the programmed key to generate a MAC. The device then checks the MAC given vs the MAC it calculated using the same key, and if it matches, write access is granted (reference, slide 4).

alecxe
  • 1,515
  • 5
  • 19
  • 34
Ryan Schaefer
  • 71
  • 1
  • 3
  • 3
    To the answer of Ryan Schaefer is additionally to say, that in a Read-Request a random number (Nonce) will be generated. At a read request you send Nonce in the packet to the eMMC-driver, which calculates the HMAC of the read request and send a copy of Nonce back to the Host. The host again checks HMAC and nonce. So you can't replay data from a read request. A very good reference is: [RPMB](https://ieeexplore.ieee.org/document/7411305/) – c0Ley Feb 02 '18 at 10:25
7

Typically, before any access (e.g. read or write) to RPMB partition, a RPMB authentication key must be programmed into RPMB controller in eMMC/UFS or NVMe device.

Note that this key must only be programmed once (at least according to the RPMB specification), and in the programming command/request, the RPMB key must be sent with cleartext, hence it normally should be provisioned in a safe environment (e.g. the factory manufacturing line, or the trusted firmware environment in the field after eMMC/UFS/NVMe is replaced with a new one).

After programming, this RPMB key should also be well protected, so typically RPMB usage should come with a TEE (trusted execution environment), like OP-TEE, Google Android Trusty or here for x86 Intel platform. However, such TEE environment normally doesn't have RPMB driver, but it has the RPMB key, and keeps this key safe inside the TEE (or secure world) for protection, while the RPMB driver itself should be in normal non-secure world like Linux (see Tomas Winkler's RPMB driver upstream).

Then, take writing access to RPMB as an example, TEE will use the RPMB key to sign the RPMB data, and send RPMB data together with the HMAC-SHA256 authentication signature (MAC) to Linux over IPC (between secure world TEE and non-secure world Linux), the Linux kernel driver is responsible for sending that piece of data (aka RPMB frame) together to RPMB physical device for authentication write.

As for REPLAY protection, it can be achieved like these for read/write access: Storage controller H/W built-in monotonic Write Counter is used for replay-protection on WRITE access, whenever an authenticated write is successful, the H/W write counter gets increased by 1, (initially it is zero), so any replayed write access will be rejected because the write counter can never be decreased. This can ensure the data freshness, however, once the counter reaches its max value (32-bit), any write access will be denied (it means that the RPMB will be a read-only storage);

While the Software generated Random Number (nonce) is used for replay-protection on READ access, because on read access, the software in TEE is responsible for authenticating the data and verifying its freshness, it must never use the same nonce or a poor random number generator to generate nonce to prevent data replay for read access.

For more details, you can see my talk in Linux Security Summit Europe 2018: Implement Android Tamper-Resistant Secure Storage and Secure it in Virtualization, in this slides, by the way, it also talks about one of RPMB virtualization solutions on top of hypervisor if you're interested in.

Hope this helps.

Bing
  • 71
  • 1
  • 5
  • If RPMB AuthKey is stored by RPMB partition and TEE, why can't it be compromised by physically extracting it from RPMB partiton? – defalt Mar 01 '21 at 06:32
  • Long story short, OP-TEE encrypts and integrity protects all files it stores, https://optee.readthedocs.io/en/latest/architecture/secure_storage.html. Likely applies to other TEEs as well. – Eero Aaltonen Jul 07 '21 at 12:32