NDCTL-SETUP-PASSPHRASE(1)

๐Ÿ’– NDCTL-SETUP-PASSPHRASE ๐Ÿ’– (from the ndctl manual)

okay so bestie, welcome to the glow-up zone where we set up and enable a security passphrase for an NVDIMM โœจ this is the ndctl-setup-passphrase page and yes it's a whole vibe, let's get into it ๐Ÿซถ


๐ŸŒธ NAME ๐ŸŒธ

ndctl-setup-passphrase โ€” setup and enable the security passphrase for an NVDIMM ๐Ÿ”โœจ


๐ŸŒˆ SYNOPSIS ๐ŸŒˆ

ndctl setup-passphrase <nmem0> [<nmem1>..<nmemN>] -k <key_handle> [<options>]

๐Ÿ’… DESCRIPTION ๐Ÿ’…

so the whole point of this command is to setup and enable a security passphrase for one or more NVDIMMs. iconic. but there's a lil prerequisite, no cap:

for this command to actually succeed, it's expected that the master key has previously been loaded into the user keyring. like, beforehand. already done. if you wanna know how to do that, the kernel documentation has you covered right here:

https://www.kernel.org/doc/html/latest/security/keys/trusted-encrypted.html

the passphrase blobs get created in the /etc/ndctl/keys directory ๐Ÿ“ and the file name format is literally this:

nvdimm_<dimm-unique-id>_<hostname>.blob

๐Ÿ’€ heads up bestie: the command will fail if the passphrase is already in the user keyring, OR if a passphrase blob already exists in /etc/ndctl/keys. so if it's throwing hands, check those two things first.

โœจ OPTIONS โœจ

  • <dimm> โ€” an nmemX device name, or a dimm id number. restricts the operation to the specified dimm(s). you can pass the keyword all to say "no restriction whatsoever", but lowkey that's the exact same thing as just not supplying a --dimm option at all ๐Ÿซ 
  • -b, --bus= โ€” a bus id number, or a provider string (e.g. "ACPI.NFIT"). restricts the operation to the specified bus(es). and yep, the keyword all works here too to mean no restriction, but again that's literally the same as not supplying a --bus option at all ๐Ÿ’ซ
  • -k, --key_handle= โ€” the handle for the master kek (key-encryption-key) that's gonna be used for sealing the passphrase(s) for the given DIMM(s). the format is <key type>:<key description>, e.g. trusted:nvdimm-master.
NOTE: the kek is expected to have been loaded into the user keyring. don't skip this step bestie, it will Not go well ๐Ÿ˜ญ
  • -m, --master-passphrase โ€” tells us we're managing the master passphrase instead of the user passphrase ๐Ÿ‘‘
  • -v, --verbose โ€” emit debug messages. for when you wanna see everything ๐Ÿ›โœจ

๐Ÿ”ฎ THEORY OF OPERATION ๐Ÿ”ฎ

okay this is the part where it gets juicy. 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 lot of lore, i know.

the security management for NVDIMMs is comprised of two parts, bestie:

  • 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 is maintained by the kernel. slay ๐Ÿ”‘

the security process begins with the generation of a master key that's used to seal (encrypt) the passphrase for the DIMM. there can either be one common master key used to encrypt 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 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, in addition to the regions, the dimm also needs to be disabled. don't forget, bestie ๐Ÿซถ

[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 specifics of each security feature ๐Ÿ’–


๐Ÿ”“ UNLOCK ๐Ÿ”“

unlock is performed by the kernel, however a preparation step must happen before the unlock DSM can be issued by the kernel. it's expected that from the initramfs, a setup command (ndctl load-keys) is executed before the libnvdimm module is loaded by modprobe. this command will inject the kek and the encrypted passphrases into the kernel's user keyring. 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 ๐Ÿ’€ a kernel module parameter is available to override this behavior, so like, there's an escape hatch.


๐ŸŽ€ SETUP USER PASSPHRASE ๐ŸŽ€

to setup the passphrase for a DIMM, it's expected that the kek to be used 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 โ€” it's instead 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).

๐Ÿ‘‘ the user is responsible for backing up the passphrase blobs to a secure location. yes YOU. do it. 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. the user has the option of providing a new kek for the new passphrase, but continuing to use the existing kek is also 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. clean sweep โœจ


๐Ÿ’€ CRYPTO (SECURE) ERASE ๐Ÿ’€

this operation is similar to remove-passphrase. the kernel issues a WBINVD instruction before and after the operation to ensure no data corruption from a stale CPU cache. use ndctl's sanitize-dimm command with the --crypto-erase option to perform this operation. poof, gone ๐Ÿซง


๐Ÿ”ฅ OVERWRITE ๐Ÿ”ฅ

this is invoked using the --overwrite option for ndctl sanitize-dimm. the overwrite operation wipes the entire NVDIMM. the operation can take a significant amount of time โ€” like, be patient bestie.

NOTE: when the command returns successfully, it just means overwrite has been successfully started, and not that the overwrite is complete. ๐Ÿ˜ญ

subsequently, 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. if both --crypto-erase and --overwrite options are supplied, then crypto-erase is performed before overwrite.


๐ŸงŠ 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. so like, nothing's getting through until you reboot. periodt. ๐Ÿ’…


๐Ÿ‘‘ 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. the master passphrase has no relation to the master key (kek), which is used for encryption of either passphrase. don't get them confused bestie, they are not the same thing ๐Ÿ™ˆ


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.


๐Ÿซถ SEE ALSO ๐Ÿซถ

ndctl-update-passphrase(1), ndctl-remove-passphrase(1)


and that's the whole page bestie, you ate that ๐Ÿ’…โœจ this was NDCTL-SETUP-PASSPHRASE(1) from the ndctl manual, brought to you by the ndctl crew, dated 2026-07-07 โ€” go forth and secure those NVDIMMs, mwah ๐ŸŽ€๐Ÿ’–

๐Ÿ“ฆ where this page comes from