All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alison Schofield <alison.schofield@intel.com>
To: Vishal Verma <vishal.l.verma@intel.com>,
	Dan Williams <dan.j.williams@intel.com>
Cc: Alison Schofield <alison.schofield@intel.com>, nvdimm@lists.linux.dev
Subject: [ndctl PATCH] ndctl: remove key from kernel keyring if blob storage fails
Date: Fri, 18 Jun 2021 18:40:55 -0700	[thread overview]
Message-ID: <20210619014056.31907-2-alison.schofield@intel.com> (raw)
In-Reply-To: <20210619014056.31907-1-alison.schofield@intel.com>

When a new passphrase key is created, the encrypted blob is always
written to storage. If the write to storage fails the passphrase is
not applied to the NVDIMM. That is all good. The unused key however
is left lingering on the kernel keyring. That blocks subsequent
attempts to add a passphrase key for the same NVDIMM. (presumably
after correcting the storage issue)

Unlink the key from the kernel keyring upon failures in key storage.

Fixes: 86b078b44275 ("ndctl: add passphrase management commands")
Signed-off-by: Alison Schofield <alison.schofield@intel.com>
---
 ndctl/util/keys.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/ndctl/util/keys.c b/ndctl/util/keys.c
index 30cb4c8..dbd622a 100644
--- a/ndctl/util/keys.c
+++ b/ndctl/util/keys.c
@@ -264,6 +264,7 @@ static key_serial_t dimm_create_key(struct ndctl_dimm *dimm,
 		rc = -errno;
 		fprintf(stderr, "Unable to open file %s: %s\n",
 				path, strerror(errno));
+		keyctl_unlink(key, KEY_SPEC_USER_KEYRING);
 		free(buffer);
 		return rc;
 	}
@@ -276,6 +277,7 @@ static key_serial_t dimm_create_key(struct ndctl_dimm *dimm,
 			rc = -EIO;
 		fprintf(stderr, "Failed to write to %s: %s\n",
 				path, strerror(-rc));
+		keyctl_unlink(key, KEY_SPEC_USER_KEYRING);
 		fclose(fp);
 		free(buffer);
 		return rc;

base-commit: 4e646fa490ba4b782afa188dd8818b94c419924e
-- 
2.25.1


  reply	other threads:[~2021-06-19  1:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-19  1:40 [ndctl PATCH] ndctl: do not try to load a key already on the kernel keyring Alison Schofield
2021-06-19  1:40 ` Alison Schofield [this message]
2021-06-19  1:40 ` [ndctl PATCH] ndctl: return -errno when keyctl_read_alloc() fails Alison Schofield

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210619014056.31907-2-alison.schofield@intel.com \
    --to=alison.schofield@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=nvdimm@lists.linux.dev \
    --cc=vishal.l.verma@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.