Skip to content

Commit 037c848

Browse files
davejiangdjbw
authored andcommitted
libnvdimm/security: provide fix for secure-erase to use zero-key
Add a zero key in order to standardize hardware that want a key of 0's to be passed. Some platforms defaults to a zero-key with security enabled rather than allow the OS to enable the security. The zero key would allow us to manage those platform as well. This also adds a fix to secure erase so it can use the zero key to do crypto erase. Some other security commands already use zero keys. This introduces a standard zero-key to allow unification of semantics cross nvdimm security commands. Signed-off-by: Dave Jiang <[email protected]> Signed-off-by: Dan Williams <[email protected]>
1 parent 486fa92 commit 037c848

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

drivers/nvdimm/security.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ static bool key_revalidate = true;
2222
module_param(key_revalidate, bool, 0444);
2323
MODULE_PARM_DESC(key_revalidate, "Require key validation at init.");
2424

25+
static const char zero_key[NVDIMM_PASSPHRASE_LEN];
26+
2527
static void *key_data(struct key *key)
2628
{
2729
struct encrypted_key_payload *epayload = dereference_key_locked(key);
@@ -286,8 +288,9 @@ int nvdimm_security_erase(struct nvdimm *nvdimm, unsigned int keyid,
286288
{
287289
struct device *dev = &nvdimm->dev;
288290
struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev);
289-
struct key *key;
291+
struct key *key = NULL;
290292
int rc;
293+
const void *data;
291294

292295
/* The bus lock should be held at the top level of the call stack */
293296
lockdep_assert_held(&nvdimm_bus->reconfig_mutex);
@@ -319,11 +322,15 @@ int nvdimm_security_erase(struct nvdimm *nvdimm, unsigned int keyid,
319322
return -EOPNOTSUPP;
320323
}
321324

322-
key = nvdimm_lookup_user_key(nvdimm, keyid, NVDIMM_BASE_KEY);
323-
if (!key)
324-
return -ENOKEY;
325+
if (keyid != 0) {
326+
key = nvdimm_lookup_user_key(nvdimm, keyid, NVDIMM_BASE_KEY);
327+
if (!key)
328+
return -ENOKEY;
329+
data = key_data(key);
330+
} else
331+
data = zero_key;
325332

326-
rc = nvdimm->sec.ops->erase(nvdimm, key_data(key), pass_type);
333+
rc = nvdimm->sec.ops->erase(nvdimm, data, pass_type);
327334
dev_dbg(dev, "key: %d erase%s: %s\n", key_serial(key),
328335
pass_type == NVDIMM_MASTER ? "(master)" : "(user)",
329336
rc == 0 ? "success" : "fail");

tools/testing/nvdimm/test/nfit.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ static struct workqueue_struct *nfit_wq;
225225

226226
static struct gen_pool *nfit_pool;
227227

228+
static const char zero_key[NVDIMM_PASSPHRASE_LEN];
229+
228230
static struct nfit_test *to_nfit_test(struct device *dev)
229231
{
230232
struct platform_device *pdev = to_platform_device(dev);
@@ -1059,15 +1061,20 @@ static int nd_intel_test_cmd_secure_erase(struct nfit_test *t,
10591061
struct device *dev = &t->pdev.dev;
10601062
struct nfit_test_sec *sec = &dimm_sec_info[dimm];
10611063

1062-
if (!(sec->state & ND_INTEL_SEC_STATE_ENABLED) ||
1063-
(sec->state & ND_INTEL_SEC_STATE_FROZEN)) {
1064+
if (sec->state & ND_INTEL_SEC_STATE_FROZEN) {
10641065
nd_cmd->status = ND_INTEL_STATUS_INVALID_STATE;
10651066
dev_dbg(dev, "secure erase: wrong security state\n");
10661067
} else if (memcmp(nd_cmd->passphrase, sec->passphrase,
10671068
ND_INTEL_PASSPHRASE_SIZE) != 0) {
10681069
nd_cmd->status = ND_INTEL_STATUS_INVALID_PASS;
10691070
dev_dbg(dev, "secure erase: wrong passphrase\n");
10701071
} else {
1072+
if (!(sec->state & ND_INTEL_SEC_STATE_ENABLED)
1073+
&& (memcmp(nd_cmd->passphrase, zero_key,
1074+
ND_INTEL_PASSPHRASE_SIZE) != 0)) {
1075+
dev_dbg(dev, "invalid zero key\n");
1076+
return 0;
1077+
}
10711078
memset(sec->passphrase, 0, ND_INTEL_PASSPHRASE_SIZE);
10721079
memset(sec->master_passphrase, 0, ND_INTEL_PASSPHRASE_SIZE);
10731080
sec->state = 0;

0 commit comments

Comments
 (0)