xref: /OK3568_Linux_fs/kernel/Documentation/driver-api/nvdimm/security.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun===============
2*4882a593SmuzhiyunNVDIMM Security
3*4882a593Smuzhiyun===============
4*4882a593Smuzhiyun
5*4882a593Smuzhiyun1. Introduction
6*4882a593Smuzhiyun---------------
7*4882a593Smuzhiyun
8*4882a593SmuzhiyunWith the introduction of Intel Device Specific Methods (DSM) v1.8
9*4882a593Smuzhiyunspecification [1], security DSMs are introduced. The spec added the following
10*4882a593Smuzhiyunsecurity DSMs: "get security state", "set passphrase", "disable passphrase",
11*4882a593Smuzhiyun"unlock unit", "freeze lock", "secure erase", and "overwrite". A security_ops
12*4882a593Smuzhiyundata structure has been added to struct dimm in order to support the security
13*4882a593Smuzhiyunoperations and generic APIs are exposed to allow vendor neutral operations.
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun2. Sysfs Interface
16*4882a593Smuzhiyun------------------
17*4882a593SmuzhiyunThe "security" sysfs attribute is provided in the nvdimm sysfs directory. For
18*4882a593Smuzhiyunexample:
19*4882a593Smuzhiyun/sys/devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/nmem0/security
20*4882a593Smuzhiyun
21*4882a593SmuzhiyunThe "show" attribute of that attribute will display the security state for
22*4882a593Smuzhiyunthat DIMM. The following states are available: disabled, unlocked, locked,
23*4882a593Smuzhiyunfrozen, and overwrite. If security is not supported, the sysfs attribute
24*4882a593Smuzhiyunwill not be visible.
25*4882a593Smuzhiyun
26*4882a593SmuzhiyunThe "store" attribute takes several commands when it is being written to
27*4882a593Smuzhiyunin order to support some of the security functionalities:
28*4882a593Smuzhiyunupdate <old_keyid> <new_keyid> - enable or update passphrase.
29*4882a593Smuzhiyundisable <keyid> - disable enabled security and remove key.
30*4882a593Smuzhiyunfreeze - freeze changing of security states.
31*4882a593Smuzhiyunerase <keyid> - delete existing user encryption key.
32*4882a593Smuzhiyunoverwrite <keyid> - wipe the entire nvdimm.
33*4882a593Smuzhiyunmaster_update <keyid> <new_keyid> - enable or update master passphrase.
34*4882a593Smuzhiyunmaster_erase <keyid> - delete existing user encryption key.
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun3. Key Management
37*4882a593Smuzhiyun-----------------
38*4882a593Smuzhiyun
39*4882a593SmuzhiyunThe key is associated to the payload by the DIMM id. For example:
40*4882a593Smuzhiyun# cat /sys/devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/nmem0/nfit/id
41*4882a593Smuzhiyun8089-a2-1740-00000133
42*4882a593SmuzhiyunThe DIMM id would be provided along with the key payload (passphrase) to
43*4882a593Smuzhiyunthe kernel.
44*4882a593Smuzhiyun
45*4882a593SmuzhiyunThe security keys are managed on the basis of a single key per DIMM. The
46*4882a593Smuzhiyunkey "passphrase" is expected to be 32bytes long. This is similar to the ATA
47*4882a593Smuzhiyunsecurity specification [2]. A key is initially acquired via the request_key()
48*4882a593Smuzhiyunkernel API call during nvdimm unlock. It is up to the user to make sure that
49*4882a593Smuzhiyunall the keys are in the kernel user keyring for unlock.
50*4882a593Smuzhiyun
51*4882a593SmuzhiyunA nvdimm encrypted-key of format enc32 has the description format of:
52*4882a593Smuzhiyunnvdimm:<bus-provider-specific-unique-id>
53*4882a593Smuzhiyun
54*4882a593SmuzhiyunSee file ``Documentation/security/keys/trusted-encrypted.rst`` for creating
55*4882a593Smuzhiyunencrypted-keys of enc32 format. TPM usage with a master trusted key is
56*4882a593Smuzhiyunpreferred for sealing the encrypted-keys.
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun4. Unlocking
59*4882a593Smuzhiyun------------
60*4882a593SmuzhiyunWhen the DIMMs are being enumerated by the kernel, the kernel will attempt to
61*4882a593Smuzhiyunretrieve the key from the kernel user keyring. This is the only time
62*4882a593Smuzhiyuna locked DIMM can be unlocked. Once unlocked, the DIMM will remain unlocked
63*4882a593Smuzhiyununtil reboot. Typically an entity (i.e. shell script) will inject all the
64*4882a593Smuzhiyunrelevant encrypted-keys into the kernel user keyring during the initramfs phase.
65*4882a593SmuzhiyunThis provides the unlock function access to all the related keys that contain
66*4882a593Smuzhiyunthe passphrase for the respective nvdimms.  It is also recommended that the
67*4882a593Smuzhiyunkeys are injected before libnvdimm is loaded by modprobe.
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun5. Update
70*4882a593Smuzhiyun---------
71*4882a593SmuzhiyunWhen doing an update, it is expected that the existing key is removed from
72*4882a593Smuzhiyunthe kernel user keyring and reinjected as different (old) key. It's irrelevant
73*4882a593Smuzhiyunwhat the key description is for the old key since we are only interested in the
74*4882a593Smuzhiyunkeyid when doing the update operation. It is also expected that the new key
75*4882a593Smuzhiyunis injected with the description format described from earlier in this
76*4882a593Smuzhiyundocument.  The update command written to the sysfs attribute will be with
77*4882a593Smuzhiyunthe format:
78*4882a593Smuzhiyunupdate <old keyid> <new keyid>
79*4882a593Smuzhiyun
80*4882a593SmuzhiyunIf there is no old keyid due to a security enabling, then a 0 should be
81*4882a593Smuzhiyunpassed in.
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun6. Freeze
84*4882a593Smuzhiyun---------
85*4882a593SmuzhiyunThe freeze operation does not require any keys. The security config can be
86*4882a593Smuzhiyunfrozen by a user with root privelege.
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun7. Disable
89*4882a593Smuzhiyun----------
90*4882a593SmuzhiyunThe security disable command format is:
91*4882a593Smuzhiyundisable <keyid>
92*4882a593Smuzhiyun
93*4882a593SmuzhiyunAn key with the current passphrase payload that is tied to the nvdimm should be
94*4882a593Smuzhiyunin the kernel user keyring.
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun8. Secure Erase
97*4882a593Smuzhiyun---------------
98*4882a593SmuzhiyunThe command format for doing a secure erase is:
99*4882a593Smuzhiyunerase <keyid>
100*4882a593Smuzhiyun
101*4882a593SmuzhiyunAn key with the current passphrase payload that is tied to the nvdimm should be
102*4882a593Smuzhiyunin the kernel user keyring.
103*4882a593Smuzhiyun
104*4882a593Smuzhiyun9. Overwrite
105*4882a593Smuzhiyun------------
106*4882a593SmuzhiyunThe command format for doing an overwrite is:
107*4882a593Smuzhiyunoverwrite <keyid>
108*4882a593Smuzhiyun
109*4882a593SmuzhiyunOverwrite can be done without a key if security is not enabled. A key serial
110*4882a593Smuzhiyunof 0 can be passed in to indicate no key.
111*4882a593Smuzhiyun
112*4882a593SmuzhiyunThe sysfs attribute "security" can be polled to wait on overwrite completion.
113*4882a593SmuzhiyunOverwrite can last tens of minutes or more depending on nvdimm size.
114*4882a593Smuzhiyun
115*4882a593SmuzhiyunAn encrypted-key with the current user passphrase that is tied to the nvdimm
116*4882a593Smuzhiyunshould be injected and its keyid should be passed in via sysfs.
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun10. Master Update
119*4882a593Smuzhiyun-----------------
120*4882a593SmuzhiyunThe command format for doing a master update is:
121*4882a593Smuzhiyunupdate <old keyid> <new keyid>
122*4882a593Smuzhiyun
123*4882a593SmuzhiyunThe operating mechanism for master update is identical to update except the
124*4882a593Smuzhiyunmaster passphrase key is passed to the kernel. The master passphrase key
125*4882a593Smuzhiyunis just another encrypted-key.
126*4882a593Smuzhiyun
127*4882a593SmuzhiyunThis command is only available when security is disabled.
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun11. Master Erase
130*4882a593Smuzhiyun----------------
131*4882a593SmuzhiyunThe command format for doing a master erase is:
132*4882a593Smuzhiyunmaster_erase <current keyid>
133*4882a593Smuzhiyun
134*4882a593SmuzhiyunThis command has the same operating mechanism as erase except the master
135*4882a593Smuzhiyunpassphrase key is passed to the kernel. The master passphrase key is just
136*4882a593Smuzhiyunanother encrypted-key.
137*4882a593Smuzhiyun
138*4882a593SmuzhiyunThis command is only available when the master security is enabled, indicated
139*4882a593Smuzhiyunby the extended security status.
140*4882a593Smuzhiyun
141*4882a593Smuzhiyun[1]: https://pmem.io/documents/NVDIMM_DSM_Interface-V1.8.pdf
142*4882a593Smuzhiyun
143*4882a593Smuzhiyun[2]: http://www.t13.org/documents/UploadedDocuments/docs2006/e05179r4-ACS-SecurityClarifications.pdf
144