Skip to content

Commit 75f95da

Browse files
committed
Merge tag 'libnvdimm-for-4.21' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm
Pull libnvdimm updates from Dan Williams: "The vast bulk of this update is the new support for the security capabilities of some nvdimms. The userspace tooling for this capability is still a work in progress, but the changes survive the existing libnvdimm unit tests. The changes also pass manual checkout on hardware and the new nfit_test emulation of the security capability. The touches of the security/keys/ files have received the necessary acks from Mimi and David. Those changes were necessary to allow for a new generic encrypted-key type, and allow the nvdimm sub-system to lookup key material referenced by the libnvdimm-sysfs interface. Summary: - Add support for the security features of nvdimm devices that implement a security model similar to ATA hard drive security. The security model supports locking access to the media at device-power-loss, to be unlocked with a passphrase, and secure-erase (crypto-scramble). Unlike the ATA security case where the kernel expects device security to be managed in a pre-OS environment, the libnvdimm security implementation allows key provisioning and key-operations at OS runtime. Keys are managed with the kernel's encrypted-keys facility to provide data-at-rest security for the libnvdimm key material. The usage model mirrors fscrypt key management, but is driven via libnvdimm sysfs. - Miscellaneous updates for api usage and comment fixes" * tag 'libnvdimm-for-4.21' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm: (21 commits) libnvdimm/security: Quiet security operations libnvdimm/security: Add documentation for nvdimm security support tools/testing/nvdimm: add Intel DSM 1.8 support for nfit_test tools/testing/nvdimm: Add overwrite support for nfit_test tools/testing/nvdimm: Add test support for Intel nvdimm security DSMs acpi/nfit, libnvdimm/security: add Intel DSM 1.8 master passphrase support acpi/nfit, libnvdimm/security: Add security DSM overwrite support acpi/nfit, libnvdimm: Add support for issue secure erase DSM to Intel nvdimm acpi/nfit, libnvdimm: Add enable/update passphrase support for Intel nvdimms acpi/nfit, libnvdimm: Add disable passphrase support to Intel nvdimm. acpi/nfit, libnvdimm: Add unlock of nvdimm support for Intel DIMMs acpi/nfit, libnvdimm: Add freeze security support to Intel nvdimm acpi/nfit, libnvdimm: Introduce nvdimm_security_ops keys-encrypted: add nvdimm key format type to encrypted keys keys: Export lookup_user_key to external users acpi/nfit, libnvdimm: Store dimm id as a member to struct nvdimm libnvdimm, namespace: Replace kmemdup() with kstrndup() libnvdimm, label: Switch to bitmap_zalloc() ACPI/nfit: Adjust annotation for why return 0 if fail to find NFIT at start libnvdimm, bus: Check id immediately following ida_simple_get ...
2 parents 4ed7bdc + 4b5f747 commit 75f95da

27 files changed

Lines changed: 1971 additions & 54 deletions

File tree

‎Documentation/nvdimm/security.txt‎

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

‎Documentation/security/keys/trusted-encrypted.rst‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Usage::
7676

7777
Where::
7878

79-
format:= 'default | ecryptfs'
79+
format:= 'default | ecryptfs | enc32'
8080
key-type:= 'trusted' | 'user'
8181

8282

@@ -173,3 +173,7 @@ are anticipated. In particular the new format 'ecryptfs' has been defined in
173173
in order to use encrypted keys to mount an eCryptfs filesystem. More details
174174
about the usage can be found in the file
175175
``Documentation/security/keys/ecryptfs.rst``.
176+
177+
Another new format 'enc32' has been defined in order to support encrypted keys
178+
with payload size of 32 bytes. This will initially be used for nvdimm security
179+
but may expand to other usages that require 32 bytes payload.

‎drivers/acpi/nfit/Kconfig‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,14 @@ config ACPI_NFIT
1313

1414
To compile this driver as a module, choose M here:
1515
the module will be called nfit.
16+
17+
config NFIT_SECURITY_DEBUG
18+
bool "Enable debug for NVDIMM security commands"
19+
depends on ACPI_NFIT
20+
help
21+
Some NVDIMM devices and controllers support encryption and
22+
other security features. The payloads for the commands that
23+
enable those features may contain sensitive clear-text
24+
security material. Disable debug of those command payloads
25+
by default. If you are a kernel developer actively working
26+
on NVDIMM security enabling say Y, otherwise say N.

‎drivers/acpi/nfit/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
obj-$(CONFIG_ACPI_NFIT) := nfit.o
22
nfit-y := core.o
3+
nfit-y += intel.o
34
nfit-$(CONFIG_X86_MCE) += mce.o

‎drivers/acpi/nfit/core.c‎

Lines changed: 85 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/nd.h>
2525
#include <asm/cacheflush.h>
2626
#include <acpi/nfit.h>
27+
#include "intel.h"
2728
#include "nfit.h"
2829
#include "intel.h"
2930

@@ -380,6 +381,16 @@ static u8 nfit_dsm_revid(unsigned family, unsigned func)
380381
[NVDIMM_INTEL_QUERY_FWUPDATE] = 2,
381382
[NVDIMM_INTEL_SET_THRESHOLD] = 2,
382383
[NVDIMM_INTEL_INJECT_ERROR] = 2,
384+
[NVDIMM_INTEL_GET_SECURITY_STATE] = 2,
385+
[NVDIMM_INTEL_SET_PASSPHRASE] = 2,
386+
[NVDIMM_INTEL_DISABLE_PASSPHRASE] = 2,
387+
[NVDIMM_INTEL_UNLOCK_UNIT] = 2,
388+
[NVDIMM_INTEL_FREEZE_LOCK] = 2,
389+
[NVDIMM_INTEL_SECURE_ERASE] = 2,
390+
[NVDIMM_INTEL_OVERWRITE] = 2,
391+
[NVDIMM_INTEL_QUERY_OVERWRITE] = 2,
392+
[NVDIMM_INTEL_SET_MASTER_PASSPHRASE] = 2,
393+
[NVDIMM_INTEL_MASTER_SECURE_ERASE] = 2,
383394
},
384395
};
385396
u8 id;
@@ -394,6 +405,17 @@ static u8 nfit_dsm_revid(unsigned family, unsigned func)
394405
return id;
395406
}
396407

408+
static bool payload_dumpable(struct nvdimm *nvdimm, unsigned int func)
409+
{
410+
struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
411+
412+
if (nfit_mem && nfit_mem->family == NVDIMM_FAMILY_INTEL
413+
&& func >= NVDIMM_INTEL_GET_SECURITY_STATE
414+
&& func <= NVDIMM_INTEL_MASTER_SECURE_ERASE)
415+
return IS_ENABLED(CONFIG_NFIT_SECURITY_DEBUG);
416+
return true;
417+
}
418+
397419
int acpi_nfit_ctl(struct nvdimm_bus_descriptor *nd_desc, struct nvdimm *nvdimm,
398420
unsigned int cmd, void *buf, unsigned int buf_len, int *cmd_rc)
399421
{
@@ -478,9 +500,10 @@ int acpi_nfit_ctl(struct nvdimm_bus_descriptor *nd_desc, struct nvdimm *nvdimm,
478500

479501
dev_dbg(dev, "%s cmd: %d: func: %d input length: %d\n",
480502
dimm_name, cmd, func, in_buf.buffer.length);
481-
print_hex_dump_debug("nvdimm in ", DUMP_PREFIX_OFFSET, 4, 4,
482-
in_buf.buffer.pointer,
483-
min_t(u32, 256, in_buf.buffer.length), true);
503+
if (payload_dumpable(nvdimm, func))
504+
print_hex_dump_debug("nvdimm in ", DUMP_PREFIX_OFFSET, 4, 4,
505+
in_buf.buffer.pointer,
506+
min_t(u32, 256, in_buf.buffer.length), true);
484507

485508
/* call the BIOS, prefer the named methods over _DSM if available */
486509
if (nvdimm && cmd == ND_CMD_GET_CONFIG_SIZE
@@ -1573,18 +1596,10 @@ static DEVICE_ATTR_RO(flags);
15731596
static ssize_t id_show(struct device *dev,
15741597
struct device_attribute *attr, char *buf)
15751598
{
1576-
struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev);
1599+
struct nvdimm *nvdimm = to_nvdimm(dev);
1600+
struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
15771601

1578-
if (dcr->valid_fields & ACPI_NFIT_CONTROL_MFG_INFO_VALID)
1579-
return sprintf(buf, "%04x-%02x-%04x-%08x\n",
1580-
be16_to_cpu(dcr->vendor_id),
1581-
dcr->manufacturing_location,
1582-
be16_to_cpu(dcr->manufacturing_date),
1583-
be32_to_cpu(dcr->serial_number));
1584-
else
1585-
return sprintf(buf, "%04x-%08x\n",
1586-
be16_to_cpu(dcr->vendor_id),
1587-
be32_to_cpu(dcr->serial_number));
1602+
return sprintf(buf, "%s\n", nfit_mem->id);
15881603
}
15891604
static DEVICE_ATTR_RO(id);
15901605

@@ -1780,10 +1795,23 @@ static int acpi_nfit_add_dimm(struct acpi_nfit_desc *acpi_desc,
17801795
const guid_t *guid;
17811796
int i;
17821797
int family = -1;
1798+
struct acpi_nfit_control_region *dcr = nfit_mem->dcr;
17831799

17841800
/* nfit test assumes 1:1 relationship between commands and dsms */
17851801
nfit_mem->dsm_mask = acpi_desc->dimm_cmd_force_en;
17861802
nfit_mem->family = NVDIMM_FAMILY_INTEL;
1803+
1804+
if (dcr->valid_fields & ACPI_NFIT_CONTROL_MFG_INFO_VALID)
1805+
sprintf(nfit_mem->id, "%04x-%02x-%04x-%08x",
1806+
be16_to_cpu(dcr->vendor_id),
1807+
dcr->manufacturing_location,
1808+
be16_to_cpu(dcr->manufacturing_date),
1809+
be32_to_cpu(dcr->serial_number));
1810+
else
1811+
sprintf(nfit_mem->id, "%04x-%08x",
1812+
be16_to_cpu(dcr->vendor_id),
1813+
be32_to_cpu(dcr->serial_number));
1814+
17871815
adev = to_acpi_dev(acpi_desc);
17881816
if (!adev) {
17891817
/* unit test case */
@@ -1904,6 +1932,16 @@ static void shutdown_dimm_notify(void *data)
19041932
mutex_unlock(&acpi_desc->init_mutex);
19051933
}
19061934

1935+
static const struct nvdimm_security_ops *acpi_nfit_get_security_ops(int family)
1936+
{
1937+
switch (family) {
1938+
case NVDIMM_FAMILY_INTEL:
1939+
return intel_security_ops;
1940+
default:
1941+
return NULL;
1942+
}
1943+
}
1944+
19071945
static int acpi_nfit_register_dimms(struct acpi_nfit_desc *acpi_desc)
19081946
{
19091947
struct nfit_mem *nfit_mem;
@@ -1970,10 +2008,11 @@ static int acpi_nfit_register_dimms(struct acpi_nfit_desc *acpi_desc)
19702008

19712009
flush = nfit_mem->nfit_flush ? nfit_mem->nfit_flush->flush
19722010
: NULL;
1973-
nvdimm = nvdimm_create(acpi_desc->nvdimm_bus, nfit_mem,
2011+
nvdimm = __nvdimm_create(acpi_desc->nvdimm_bus, nfit_mem,
19742012
acpi_nfit_dimm_attribute_groups,
19752013
flags, cmd_mask, flush ? flush->hint_count : 0,
1976-
nfit_mem->flush_wpq);
2014+
nfit_mem->flush_wpq, &nfit_mem->id[0],
2015+
acpi_nfit_get_security_ops(nfit_mem->family));
19772016
if (!nvdimm)
19782017
return -ENOMEM;
19792018

@@ -2008,6 +2047,11 @@ static int acpi_nfit_register_dimms(struct acpi_nfit_desc *acpi_desc)
20082047
if (!nvdimm)
20092048
continue;
20102049

2050+
rc = nvdimm_security_setup_events(nvdimm);
2051+
if (rc < 0)
2052+
dev_warn(acpi_desc->dev,
2053+
"security event setup failed: %d\n", rc);
2054+
20112055
nfit_kernfs = sysfs_get_dirent(nvdimm_kobj(nvdimm)->sd, "nfit");
20122056
if (nfit_kernfs)
20132057
nfit_mem->flags_attr = sysfs_get_dirent(nfit_kernfs,
@@ -3337,7 +3381,7 @@ static int acpi_nfit_flush_probe(struct nvdimm_bus_descriptor *nd_desc)
33373381
return 0;
33383382
}
33393383

3340-
static int acpi_nfit_clear_to_send(struct nvdimm_bus_descriptor *nd_desc,
3384+
static int __acpi_nfit_clear_to_send(struct nvdimm_bus_descriptor *nd_desc,
33413385
struct nvdimm *nvdimm, unsigned int cmd)
33423386
{
33433387
struct acpi_nfit_desc *acpi_desc = to_acpi_nfit_desc(nd_desc);
@@ -3359,6 +3403,23 @@ static int acpi_nfit_clear_to_send(struct nvdimm_bus_descriptor *nd_desc,
33593403
return 0;
33603404
}
33613405

3406+
/* prevent security commands from being issued via ioctl */
3407+
static int acpi_nfit_clear_to_send(struct nvdimm_bus_descriptor *nd_desc,
3408+
struct nvdimm *nvdimm, unsigned int cmd, void *buf)
3409+
{
3410+
struct nd_cmd_pkg *call_pkg = buf;
3411+
unsigned int func;
3412+
3413+
if (nvdimm && cmd == ND_CMD_CALL &&
3414+
call_pkg->nd_family == NVDIMM_FAMILY_INTEL) {
3415+
func = call_pkg->nd_command;
3416+
if ((1 << func) & NVDIMM_INTEL_SECURITY_CMDMASK)
3417+
return -EOPNOTSUPP;
3418+
}
3419+
3420+
return __acpi_nfit_clear_to_send(nd_desc, nvdimm, cmd);
3421+
}
3422+
33623423
int acpi_nfit_ars_rescan(struct acpi_nfit_desc *acpi_desc,
33633424
enum nfit_ars_state req_type)
33643425
{
@@ -3474,7 +3535,13 @@ static int acpi_nfit_add(struct acpi_device *adev)
34743535

34753536
status = acpi_get_table(ACPI_SIG_NFIT, 0, &tbl);
34763537
if (ACPI_FAILURE(status)) {
3477-
/* This is ok, we could have an nvdimm hotplugged later */
3538+
/* The NVDIMM root device allows OS to trigger enumeration of
3539+
* NVDIMMs through NFIT at boot time and re-enumeration at
3540+
* root level via the _FIT method during runtime.
3541+
* This is ok to return 0 here, we could have an nvdimm
3542+
* hotplugged later and evaluate _FIT method which returns
3543+
* data in the format of a series of NFIT Structures.
3544+
*/
34783545
dev_dbg(dev, "failed to find NFIT at startup\n");
34793546
return 0;
34803547
}

0 commit comments

Comments
 (0)