'\" t .\" Title: ndctl-load-keys .\" Author: [see the "AUTHOR(S)" section] .\" Generator: Asciidoctor 2.0.12 .\" Date: 2022-04-08 .\" Manual: ndctl Manual .\" Source: ndctl .\" Language: English .\" .TH "NDCTL\-LOAD\-KEYS" "1" "2022-04-08" "ndctl" "ndctl Manual" .ie \n(.g .ds Aq \(aq .el .ds Aq ' .ss \n[.ss] 0 .nh .ad l .de URL \fI\\$2\fP <\\$1>\\$3 .. .als MTO URL .if \n[.g] \{\ . mso www.tmac . am URL . ad l . . . am MTO . ad l . . . LINKSTYLE blue R < > .\} .SH "NAME" ndctl\-load\-keys \- load the kek and encrypted passphrases into the keyring .SH "SYNOPSIS" .sp .sp .nf \fIndctl load\-keys\fP [] .fi .br .SH "DESCRIPTION" .sp The \fIload\-keys\fP command loads the master key (\fIkek\fP) and the encrypted passphrases for all NVDIMMs into the user keyring maintained by the kernel. The command is expected to be called during initialization and before the libnvdimm kernel module is loaded, typically from an initrd. This is typically set up using a modprobe config that calls the command before module load. .if n .sp .RS 4 .it 1 an-trap .nr an-no-space-flag 1 .nr an-break-flag 1 .br .ps +1 .B Note .ps -1 .br .sp All key files are expected to be in the format: nvdimm__hostname .br The \f(CR\(aq_\fP\(aq character is used to delimit the different components in the file name. Within the hostname, the \f(CR\(aq_\fP\(aq character is allowed since it is the last component of the file name. .sp .5v .RE .if n .sp .RS 4 .it 1 an-trap .nr an-no-space-flag 1 .nr an-break-flag 1 .br .ps +1 .B Note .ps -1 .br .sp This command is typically never called directly by a user. .sp .5v .RE .SH "OPTIONS" .sp \-p, \-\-key\-path= .RS 4 Path to where key related files reside. This parameter is optional and the default location is /etc/ndctl/keys. .RE .sp \-t, \-\-tpm\-handle= .RS 4 Provide a TPM handle (should be a string such as 0x81000001). If the key path (/etc/ndctl/keys) contains a file called tpm.handle which contains the handle string, then this option may be left out, and the tpm handle will be obtained from the file. If both are present, then this option will override (but not overwrite) anything that is in the file. .RE .SH "THEORY OF OPERATION" .sp The Intel Device Specific Methods (DSM) specification v1.7 and v1.8 [1] introduced the following security management operations: enable passhprase, update passphrase, unlock DIMM, disable security, freeze security, secure (crypto) erase, overwrite, master passphrase enable, master passphrase update, and master passphrase secure erase. .sp The security management for NVDIMMs is comprised 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 \fIkeyutils\fP 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. .sp Unlike other DSMs which are composed by libndctl and sent to the kernel via an ioctl, the security DSMs are managed through the \fIsecurity\fP sysfs attribute under the \fIdimm\fP device. A \fIkey\-ID\fP is written to the \fIsecurity\fP attribute and the kernel pulls the associated key material from the user keyring that is maintained by the kernel. .sp The security process begins with the generation of a \fImaster key\fP that is used to seal (encrypt) the passphrase for the DIMM. There can either be one common \fImaster key\fP that is used to encrypt every DIMM\(cqs passphrase, or a separate key can be generated for each DIMM. The \fImaster key\fP is also referred to as the \fIkey\-encryption\-key\fP (kek). The \fIkek\fP can either be generated by the TPM (Trusted Platform Module) on the system, or alternatively, the \fISystem Master Key\fP can also be used as the \fIkek\fP .sp For testing purposes a user key with randomized payload can also be used as a \fIkek\fP. See [2] for details. To perform any security operations, it is expected that the \fIkek\fP has been added to the kernel\(cqs user keyring as shown in example below: .sp .if n .RS 4 .nf .fam C # keyctl show Session Keyring 736023423 \-\-alswrv 0 0 keyring: _ses 675104189 \-\-alswrv 0 65534 \(rs_ keyring: _uid.0 680187394 \-\-alswrv 0 0 \(rs_ trusted: nvdimm\-master .fam .fi .if n .RE .sp Before performing any of the security operations, all the regions associated with the DIMM in question need to be disabled. For the \fIoverwrite\fP operation, in addition to the \fIregions\fP, the \fIdimm\fP also needs to be disabled. .sp [1] \c .URL "http://pmem.io/documents/NVDIMM_DSM_Interface\-V1.8.pdf" "" .br [2] \c .URL "https://www.kernel.org/doc/Documentation/security/keys/trusted\-encrypted.rst" "" "" .sp The following sub\-sections describe specifics of each security feature. .SS "UNLOCK" .sp Unlock is performed by the kernel, however a preparation step must happen before the unlock DSM can be issued by the kernel. It is expected that from the initramfs, a setup command (ndctl \fIload\-keys\fP) is executed before the libnvdimm module is loaded by modprobe. This command will inject the \fIkek\fP and the encrypted passphrases into the kernel\(cqs user keyring. During the \fIprobe\fP of the libnvdimm driver, it will: .sp .RS 4 .ie n \{\ \h'-04' 1.\h'+01'\c .\} .el \{\ . sp -1 . IP " 1." 4.2 .\} Check the security state of the device and see if the DIMM is locked .RE .sp .RS 4 .ie n \{\ \h'-04' 2.\h'+01'\c .\} .el \{\ . sp -1 . IP " 2." 4.2 .\} Request the associated encrypted passphrase from the kernel\(cqs user key ring .RE .sp .RS 4 .ie n \{\ \h'-04' 3.\h'+01'\c .\} .el \{\ . sp -1 . IP " 3." 4.2 .\} Use the \fIkek\fP to decrypt the passphrase .RE .sp .RS 4 .ie n \{\ \h'-04' 4.\h'+01'\c .\} .el \{\ . sp -1 . IP " 4." 4.2 .\} Create the unlock DSM, copy the decrypted payload into the DSM .RE .sp .RS 4 .ie n \{\ \h'-04' 5.\h'+01'\c .\} .el \{\ . sp -1 . IP " 5." 4.2 .\} Issue the DSM to unlock the DIMM .RE .sp If the DIMM is already unlocked, the kernel will attempt to revalidate the passphrase. 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. .SS "SETUP USER PASSPHRASE" .sp To setup the passphrase for a DIMM, it is expected that the \fIkek\fP to be used is present in the kernel\(cqs user keyring. The \fIkek\fP encrypts the DIMM passphrase using the \fIenc32\fP key format. The plaintext passphrase is never provided by or made visible to the user. It is 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. .SS "UPDATE USER PASSPHRASE" .sp 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 \fIkek\fP for the new passphrase, but continuing to use the existing \fIkek\fP is also acceptable. The following operations are performed for \fIupdate\-passphrase\fP: .sp .RS 4 .ie n \{\ \h'-04' 1.\h'+01'\c .\} .el \{\ . sp -1 . IP " 1." 4.2 .\} Remove the encrypted passphrase from the kernel\(cqs user keyring. .RE .sp .RS 4 .ie n \{\ \h'-04' 2.\h'+01'\c .\} .el \{\ . sp -1 . IP " 2." 4.2 .\} Rename the passphrase blob to old. .RE .sp .RS 4 .ie n \{\ \h'-04' 3.\h'+01'\c .\} .el \{\ . sp -1 . IP " 3." 4.2 .\} Load this old passphrase blob into the keyring with an "old" name. .RE .sp .RS 4 .ie n \{\ \h'-04' 4.\h'+01'\c .\} .el \{\ . sp -1 . IP " 4." 4.2 .\} Create the new passphrase and encrypt with the \fIkek\fP. .RE .sp .RS 4 .ie n \{\ \h'-04' 5.\h'+01'\c .\} .el \{\ . sp -1 . IP " 5." 4.2 .\} Send DSM with the old and new decrypted passphrases. .RE .sp .RS 4 .ie n \{\ \h'-04' 6.\h'+01'\c .\} .el \{\ . sp -1 . IP " 6." 4.2 .\} Remove old passphrase and the passphrase blob from the keyring. .RE .SS "REMOVE USER PASSPHRASE" .sp The \fIkey\-ID\fP 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. .SS "CRYPTO (SECURE) ERASE" .sp 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\(cqs sanitize\-dimm command with the \f(CR\-\-crypto\-erase\fP option to perform this operation. .SS "OVERWRITE" .sp This is invoked using \f(CR\-\-overwrite\fP option for ndctl \fIsanitize\-dimm\fP. The overwrite operation wipes the entire NVDIMM. The operation can take a significant amount of time. NOTE: When the command returns successfully, it just means overwrite has been successfully started, and not that the overwrite is complete. Subsequently, \(aqndctl wait\-overwrite\(cqcan 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. .SS "SECURITY FREEZE" .sp This operation does not require a passphrase. This will cause any security command other than a status query to be locked out until the next boot. .SS "MASTER PASSPHRASE SETUP, UPDATE, and CRYPTO ERASE" .sp 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 (\fIkek\fP) which is used for encryption of either passphrase. .SH "COPYRIGHT" .sp Copyright \(co 2016 \- 2020, Intel Corporation. License GPLv2: GNU GPL version 2 \c .URL "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.