NDCTL-LOAD-KEYS(1)

✨ NDCTL-LOAD-KEYS ✨

okay bestie, welcome to the ndctl-load-keys manual page, part of the ndctl crew πŸ’– this one's a little backstage-pass situation β€” it's the thing that happens before everything else, so let's get into it πŸŽ€


🌸 NAME 🌸

ndctl-load-keys β€” loads the kek and encrypted passphrases into the keyring πŸ”‘


πŸ¦‹ SYNOPSIS πŸ¦‹

ndctl load-keys [<options>]

πŸ’œ DESCRIPTION πŸ’œ

so like. the load-keys command loads the master key (aka the kek) and all the encrypted passphrases for every NVDIMM into the user keyring that the kernel is keeping alive for you. πŸ’…

the vibe here is: this is meant to be called during initialization, and before the libnvdimm kernel module gets loaded β€” typically from an initrd. usually it's set up with a modprobe config that calls the command before the module load happens. it's giving "prep work before the main character arrives" ✨

πŸ“ Note: all key files are expected to be in the format nvdimm_<id>_hostname. the _ character is what delimits the different components in the file name. inside the hostname, _ is allowed, since it's the last component of the file name. no cap. 🫢
πŸ“ Note: this command is typically never called directly by a user. it's an iykyk situation, bestie.

πŸ’… OPTIONS πŸ’…

  • -p, --key-path= β€” the path to where all the key-related files live. this one's optional, and the default location is /etc/ndctl/keys. πŸ—‚οΈ
  • -t, --tpm-handle= β€” hand over a TPM handle (it should be a string, like 0x81000001). if the key path (/etc/ndctl/keys) contains a file called tpm.handle that has the handle string inside it, then you can just... not use this option, and the tpm handle will be grabbed from the file instead. and if both are present? this option wins β€” it overrides (but does not overwrite, okay bestie, those are different things) anything that's in the file. πŸ”₯

πŸ‘‘ THEORY OF OPERATION πŸ‘‘

so the Intel Device Specific Methods (DSM) specification v1.7 and v1.8 [1] introduced these security management operations: enable passphrase, update passphrase, unlock DIMM, disable security, freeze security, secure (crypto) erase, overwrite, master passphrase enable, master passphrase update, and master passphrase secure erase. that's a whole lineup, periodt. πŸ’€

the security management for NVDIMMs is made of two parts:

  • the front end uses the Linux key management framework (trusted and encrypted keys [2]) to store the encrypted passphrases in the kernel-managed keyring. the interface for this is the keyutils utility, which uses the key management APIs in the Linux kernel.
  • the back end takes the decrypted payload (which is the DIMM passphrase) and passes it to the DIMM.

unlike other DSMs which are composed by libndctl and sent to the kernel via an ioctl, the security DSMs are managed through the security sysfs attribute under the dimm device. a key-ID is written to the security attribute, and the kernel pulls the associated key material from the user keyring that it maintains. 🧚

the security process kicks off with the generation of a master key, which is used to seal (encrypt) the passphrase for the DIMM. there can either be one common master key that encrypts every DIMM's passphrase, or a separate key can be generated for each DIMM. the master key is also referred to as the key-encryption-key (kek). the kek can either be generated by the TPM (Trusted Platform Module) on the system, or alternatively, the System Master Key can also be used as the kek. ✨

for testing purposes, a user key with a randomized payload can also be used as a kek. see [2] for details. to perform any security operations, it's expected that the kek has been added to the kernel's user keyring, as shown in the example below:

# keyctl show
Session Keyring
 736023423 --alswrv      0     0  keyring: _ses
 675104189 --alswrv      0 65534   \_ keyring: _uid.0
 680187394 --alswrv      0     0       \_ trusted: nvdimm-master

before performing any of the security operations, all the regions associated with the DIMM in question need to be disabled. and for the overwrite operation, on top of the regions, the dimm itself also needs to be disabled. πŸ™ˆ

[1] http://pmem.io/documents/NVDIMM_DSM_Interface-V1.8.pdf

[2] https://www.kernel.org/doc/Documentation/security/keys/trusted-encrypted.rst

the following sub-sections describe the specifics of each security feature. πŸ’–


πŸ”“ UNLOCK πŸ”“

unlock is performed by the kernel β€” but a preparation step has to happen before the unlock DSM can be issued by the kernel. from the initramfs, it's expected that a setup command (ndctl load-keys) is executed before the libnvdimm module is loaded by modprobe. this command injects the kek and the encrypted passphrases into the kernel's user keyring. then, during the probe of the libnvdimm driver, it will:

  1. check the security state of the device and see if the DIMM is locked πŸ”’
  2. request the associated encrypted passphrase from the kernel's user key ring
  3. use the kek to decrypt the passphrase
  4. create the unlock DSM, copy the decrypted payload into the DSM
  5. issue the DSM to unlock the DIMM

if the DIMM is already unlocked, the kernel will attempt to revalidate the passphrase. and if we fail to revalidate the passphrase, the kernel will freeze the security and disallow any further security configuration changes. 😭 there is a kernel module parameter available to override this behavior, so like, you have options.


πŸŽ€ SETUP USER PASSPHRASE πŸŽ€

to set up the passphrase for a DIMM, it's expected that the kek you want to use is present in the kernel's user keyring. the kek encrypts the DIMM passphrase using the enc32 key format. the plaintext passphrase is never provided by, or made visible to, the user β€” instead it's randomly generated by the kernel, and userspace does not have access to it. upon encryption, a binary blob of the passphrase is written to the passphrase blob storage directory (/etc/ndctl/keys). and bestie, you are responsible for backing up the passphrase blobs to a secure location. don't skip that step, fr fr. 🫢


🌈 UPDATE USER PASSPHRASE 🌈

the update user passphrase operation uses the same DSM command as enable user passphrase. most of the work is done on the key management side. you have the option of providing a new kek for the new passphrase, but continuing to use the existing kek is also totally acceptable. ✨

the following operations are performed for update-passphrase:

  1. remove the encrypted passphrase from the kernel's user keyring
  2. rename the passphrase blob to old
  3. load this old passphrase blob into the keyring with an "old" name
  4. create the new passphrase and encrypt with the kek
  5. send DSM with the old and new decrypted passphrases
  6. remove old passphrase and the passphrase blob from the keyring

πŸ’€ REMOVE USER PASSPHRASE πŸ’€

the key-ID for the passphrase to be removed is written to sysfs. the kernel then sends the DSM to disable security, and the passphrase is then removed from the keyring, and the associated passphrase blob is deleted. gone, bye, slay. πŸ’…


πŸ”₯ CRYPTO (SECURE) ERASE πŸ”₯

this operation is similar to remove-passphrase. the kernel issues a WBINVD instruction before and after the operation, to make sure there's no data corruption from a stale CPU cache. use ndctl's sanitize-dimm command with the --crypto-erase option to perform this operation. 🧚


πŸ¦‹ OVERWRITE πŸ¦‹

this one is invoked using the --overwrite option for ndctl sanitize-dimm. the overwrite operation wipes the entire NVDIMM. it can take a significant amount of time, so like, plan a snack break. 😭

⚠️ NOTE: when the command returns successfully, it just means overwrite has been successfully started β€” not that the overwrite is complete. do not be fooled bestie.

afterwards, ndctl wait-overwrite can be used to wait for the NVDIMMs that are performing overwrite. upon successful completion of an overwrite, the WBINVD instruction is issued by the kernel. and if both --crypto-erase and --overwrite options are supplied, then crypto-erase is performed before overwrite. order matters, periodt. πŸ’œ


❄️ SECURITY FREEZE ❄️

this operation does not require a passphrase. it will cause any security command other than a status query to be locked out until the next boot. it's giving ice queen energy, ngl. 🧊


⭐ MASTER PASSPHRASE SETUP, UPDATE, and CRYPTO ERASE ⭐

these operations are similar to the user passphrase enable and update. the only difference is that a different passphrase is used. and here's the key detail: the master passphrase has no relation to the master key (kek), which is used for encryption of either passphrase. two totally separate things, don't mix them up. πŸ’–


Copyright Β© 2016 - 2022, Intel Corporation. License GPLv2: GNU GPL version 2 http://gnu.org/licenses/gpl.html. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.


okay that's the whole page, bestie, you ate it πŸ’…βœ¨ this was the ndctl manual, dated 2026-07-07 β€” go forth and load those keys, ily πŸ«ΆπŸŽ€

πŸ“¦ where this page comes from