10bc53ce7SJohn Wedig# eStoraged Design - Encrypted Secondary Storage Management Daemon 20bc53ce7SJohn Wedig 30bc53ce7SJohn WedigAuthor: John Wedig (johnwedig@google.com) 40bc53ce7SJohn Wedig 5*f4febd00SPatrick WilliamsOther contributors: John Broadbent (jebr@google.com) Benjamin Fair 6*f4febd00SPatrick Williams(benjaminfair@google.com) Nancy Yuenn (yuenn@google.com) 70bc53ce7SJohn Wedig 80bc53ce7SJohn WedigCreated: September 2, 2021 90bc53ce7SJohn Wedig 100bc53ce7SJohn Wedig## Problem Description 110bc53ce7SJohn Wedig 120bc53ce7SJohn WedigThis daemon will serve as an abstraction for an encrypted storage device, 130bc53ce7SJohn Wedigencapsulating the security functionality and providing a D-Bus interface to 140bc53ce7SJohn Wedigmanage the encrypted filesystem on the device. Using the D-Bus interface, other 15*f4febd00SPatrick Williamssoftware components can interact with eStoraged to do things like create a new 16*f4febd00SPatrick Williamsencrypted filesystem, wipe its contents, lock/unlock the device, or change the 17*f4febd00SPatrick Williamspassword. 180bc53ce7SJohn Wedig 190bc53ce7SJohn Wedig## Background and References 200bc53ce7SJohn Wedig 210bc53ce7SJohn WedigThis design is intended to manage secondary storage devices and cannot be used 220bc53ce7SJohn Wedigfor the root filesystem, i.e. the BMC needs to be able to boot while the device 230bc53ce7SJohn Wedigis still locked. 240bc53ce7SJohn Wedig 250bc53ce7SJohn WedigThis design makes use of the 260bc53ce7SJohn Wedig[cryptsetup](https://gitlab.com/cryptsetup/cryptsetup) utility, which in turn 270bc53ce7SJohn Wediguses the [dm-crypt](https://en.wikipedia.org/wiki/Dm-crypt) kernel subsystem. 280bc53ce7SJohn WedigDm-crypt provides the encryption and device mapping capability, and Cryptsetup 290bc53ce7SJohn Wedigprovides the [LUKS](https://en.wikipedia.org/wiki/Linux_Unified_Key_Setup) 300bc53ce7SJohn Wedigcapability, which facilitates password management so that we can do things like 310bc53ce7SJohn Wedigchange the password without re-encrypting the entire device. 320bc53ce7SJohn Wedig 330bc53ce7SJohn WedigThis design is specifically targeted for use with eMMC devices, and we plan to 340bc53ce7SJohn Wedigmake use of the lock/unlock feature (CMD42) at the eMMC hardware level as an 350bc53ce7SJohn Wedigadditional security measure. This feature prohibits all read or write accesses 360bc53ce7SJohn Wedigto the device while locked. Some documentation on this feature can be found in 370bc53ce7SJohn Wedigthe 38*f4febd00SPatrick Williams[JEDEC standard JESD84-B51A](https://www.jedec.org/document_search?search_api_views_fulltext=jesd84-b51), 39*f4febd00SPatrick Williamsor in this document: 400bc53ce7SJohn Wedig[Enabling SD/uSD Card Lock/Unlock Feature in Linux](https://media-www.micron.com/-/media/client/global/documents/products/technical-note/sd-cards/tnsd01_enable_sd_lock_unlock_in_linux.pdf?rev=03f03a6bc0f8435fafa93a8fc8e88988). 410bc53ce7SJohn Wedig 420bc53ce7SJohn WedigThere are several types of keys referenced in this doc: 430bc53ce7SJohn Wedig 440bc53ce7SJohn Wedig- Volume key: The main encryption key used to encrypt the data on the block 450bc53ce7SJohn Wedig device. 460bc53ce7SJohn Wedig- Encryption Password: The password needed to load the volume key into RAM and 470bc53ce7SJohn Wedig decrypt the filesystem. 480bc53ce7SJohn Wedig- Device Password: The password to lock or unlock the device hardware. 490bc53ce7SJohn Wedig 500bc53ce7SJohn Wedig## Requirements 510bc53ce7SJohn Wedig 520bc53ce7SJohn WedigThis design should provide an interface for the following capabilities: 53*f4febd00SPatrick Williams 540bc53ce7SJohn Wedig- Create a new LUKS encrypted filesystem on the device 550bc53ce7SJohn Wedig- Securely wipe the device and verify that the data was wiped 560bc53ce7SJohn Wedig- Lock the device 570bc53ce7SJohn Wedig- Unlock the device 580bc53ce7SJohn Wedig- Change the password 590bc53ce7SJohn Wedig 600bc53ce7SJohn WedigIn addition, eStoraged should: 61*f4febd00SPatrick Williams 620bc53ce7SJohn Wedig- Generate a volume key using a random number generator with enough entropy, 630bc53ce7SJohn Wedig making it sufficiently random and secure. 640bc53ce7SJohn Wedig- Utilize any security features provided by the hardware (as a defense-in-depth 650bc53ce7SJohn Wedig measure). 660bc53ce7SJohn Wedig- Use interfaces that are generic enough, so that they can be extended to 670bc53ce7SJohn Wedig support additional types of storage devices, as desired. For example, 680bc53ce7SJohn Wedig different devices will have different command sets for device locking, e.g. 690bc53ce7SJohn Wedig MMC, SATA, NVMe. Initially, we plan to only use eStoraged with eMMC devices, 70*f4febd00SPatrick Williams but we may wish to use this with other types of storage devices in the future. 710bc53ce7SJohn Wedig 720bc53ce7SJohn WedigThe users of this design can be any other software component in the BMC. Some 730bc53ce7SJohn Wedigclient daemon on the BMC will interact with eStoraged to set up a new encrypted 740bc53ce7SJohn Wedigfilesystem on the eMMC. In addition, the client daemon could be configured to 750bc53ce7SJohn Wedigunlock the eMMC device when the BMC boots. It is the responsibility of the 76*f4febd00SPatrick Williamsclient daemon to provide a password. For example, this password could come from 77*f4febd00SPatrick Williamsuser input, fetched from a secure location, or the client daemon could generate 78*f4febd00SPatrick Williamsthe passwords itself. 790bc53ce7SJohn Wedig 800bc53ce7SJohn Wedig## Proposed Design 810bc53ce7SJohn Wedig 82*f4febd00SPatrick WilliamseStoraged will represent each eMMC device as an object on D-Bus that implements 83*f4febd00SPatrick Williamsan interface providing these methods and properties: 84*f4febd00SPatrick Williams 850bc53ce7SJohn Wedig- (method) Format 860bc53ce7SJohn Wedig- (method) Erase 870bc53ce7SJohn Wedig- (method) Lock 880bc53ce7SJohn Wedig- (method) Unlock 890bc53ce7SJohn Wedig- (method) Change Password 900bc53ce7SJohn Wedig- (property) Locked 910bc53ce7SJohn Wedig- (property) Status 920bc53ce7SJohn Wedig 93*f4febd00SPatrick WilliamsUpon startup, eStoraged will create a D-Bus object for each eMMC device in the 94*f4febd00SPatrick Williamssystem. Specifically, we will use udev to launch an eStoraged instance for each 95*f4febd00SPatrick WilliamseMMC. The bus name and object name will be as follows: 960bc53ce7SJohn Wedig 97*f4febd00SPatrick WilliamsBus Name: xyz.openbmc_project.eStorage.\<device name\> Object Path: 98*f4febd00SPatrick Williams/xyz/openbmc_project/storage/\<device name\> 990bc53ce7SJohn Wedig 1000bc53ce7SJohn WedigThe object path is intended to be generic enough, so that we could ultimately 1010bc53ce7SJohn Wedighave multiple daemons managing the same storage device, while using the same 1020bc53ce7SJohn Wedigobject path. For example, this daemon would handle the encryption, whereas 1030bc53ce7SJohn Wediganother daemon could provide stats for the same device. 1040bc53ce7SJohn Wedig 1050bc53ce7SJohn WedigTo manage the encrypted filesystem, we will make use of the 1060bc53ce7SJohn Wedig[cryptsetup API](https://mbroz.fedorapeople.org/libcryptsetup_API/). This 1070bc53ce7SJohn Wediglibrary provides functions to create a new LUKS header, set the password, etc. 1080bc53ce7SJohn Wedig 109*f4febd00SPatrick WilliamsFor eMMC devices, we plan to enable the password locking feature (CMD42), to 110*f4febd00SPatrick Williamsprevent all read or write accesses to the device while locked. So, the "Locked" 111*f4febd00SPatrick Williamsproperty will mean both locked at the hardware level and locked at the 1120bc53ce7SJohn Wedigencryption level. We will likely use the ioctl interface to send the relevant 1130bc53ce7SJohn Wedigcommands to the eMMC, similar to what 1140bc53ce7SJohn Wedig[mmc utils](https://git.kernel.org/pub/scm/utils/mmc/mmc-utils.git/) does. 1150bc53ce7SJohn Wedig 1160bc53ce7SJohn WedigSupport for hardware locking on other types of devices can be added as needed, 1170bc53ce7SJohn Wedigbut at the very least, encryption-only locking will be available, even if 1180bc53ce7SJohn Wedighardware locking isn't supported for a particular device. 1190bc53ce7SJohn Wedig 120*f4febd00SPatrick WilliamsAs mentioned earlier, the client will provide a password. This password will be 121*f4febd00SPatrick Williamsused by eStoraged to generate two different passwords: the encryption password 122*f4febd00SPatrick Williamsand the device password (if hardware locking is available). The passwords will 123*f4febd00SPatrick Williamsbe different, so that in the event that one password is compromised, we still 124*f4febd00SPatrick Williamshave some protection from the other password. 1250bc53ce7SJohn Wedig 1260bc53ce7SJohn WedigThe Erase method should provide a way to specify the type of erase, e.g. write 1270bc53ce7SJohn Wedigall zeros, or do something else. Different organizations may have different 1280bc53ce7SJohn Wedigopinions of what a secure erase entails. 1290bc53ce7SJohn Wedig 1300bc53ce7SJohn WedigSince some of the D-Bus methods may take a while (e.g. installing a new 1310bc53ce7SJohn Wedigencrypted filesystem), the D-Bus interface will be asynchronous, with the 132*f4febd00SPatrick Williams"Status" property that can be queried to indicate one of the following: success, 133*f4febd00SPatrick Williamserror, or in-progress. 1340bc53ce7SJohn Wedig 1350bc53ce7SJohn Wedig## Alternatives Considered 136*f4febd00SPatrick Williams 1370bc53ce7SJohn WedigAn alternative would be to use systemd targets to manage the eMMC. For example, 1380bc53ce7SJohn Wedigthe 1390bc53ce7SJohn Wedig[systemd-cryptsetup@.service](https://www.freedesktop.org/software/systemd/man/systemd-cryptsetup@.service.html) 1400bc53ce7SJohn Wedigis often used to unlock an encrypted block device, where it takes the password 1410bc53ce7SJohn Wedigfrom a key file or from user input. However, the OpenBMC architecture calls for 1420bc53ce7SJohn Wedigusing D-Bus as the primary form of inter-process communication. In addition, 1430bc53ce7SJohn Wedigusing a daemon with a well-defined D-Bus interface keeps the security 1440bc53ce7SJohn Wedigfunctionality more isolated, maintainable, and testable. 1450bc53ce7SJohn Wedig 1460bc53ce7SJohn WedigAnother related piece of software is UDisks2, which also exports a D-Bus object 1470bc53ce7SJohn Wedigfor each storage device in a system. It is capable of setting up an encrypted 1480bc53ce7SJohn Wedigblock device with the Format method: 1490bc53ce7SJohn Wedig[org.freedesktop.UDisks2.Format](http://storaged.org/doc/udisks2-api/latest/gdbus-org.freedesktop.UDisks2.Block.html#gdbus-method-org-freedesktop-UDisks2-Block.Format). 1500bc53ce7SJohn WedigAnd it provides several additional methods related to encryption: Lock, Unlock, 1510bc53ce7SJohn Wedigand ChangePassphrase. See the D-Bus interface 1520bc53ce7SJohn Wedig[org.freedesktop.UDisks2.Encrypted](http://storaged.org/doc/udisks2-api/2.7.5/gdbus-org.freedesktop.UDisks2.Encrypted.html). 1530bc53ce7SJohn WedigThe main problem preventing us from leveraging this tool is that it increases 154*f4febd00SPatrick Williamsour image size too much. We found that the compressed image size increased by 22 155*f4febd00SPatrick WilliamsMB due to the transitive dependencies being pulled in, e.g. mozjs and python. 1560bc53ce7SJohn Wedig 1570bc53ce7SJohn Wedig## Impacts 158*f4febd00SPatrick Williams 1590bc53ce7SJohn WedigTo make use of eStoraged, it may be necessary to provide another client daemon 1600bc53ce7SJohn Wedigthat manages the password and invokes the D-Bus API for eStoraged. Since the 1610bc53ce7SJohn Wedigpassword management scheme can be unique for different platforms and 1620bc53ce7SJohn Wedigorganizations, it is outside the scope of this design. 1630bc53ce7SJohn Wedig 1640bc53ce7SJohn Wedig## Testing 165*f4febd00SPatrick Williams 1660bc53ce7SJohn Wedig- Unit tests to validate the various code paths in eStoraged. 1670bc53ce7SJohn Wedig- Regression tests will exercise the various D-Bus methods: encrypt, erase, 1680bc53ce7SJohn Wedig lock, unlock, and change password. 169