All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mat Martineau <mathew.j.martineau@linux.intel.com>
To: ell@lists.01.org
Subject: [PATCH v2 2/3] key: Make key/keychain revocation optional when freeing
Date: Mon, 24 Oct 2016 14:36:32 -0700	[thread overview]
Message-ID: <20161024213633.10668-2-mathew.j.martineau@linux.intel.com> (raw)
In-Reply-To: <20161024213633.10668-1-mathew.j.martineau@linux.intel.com>

[-- Attachment #1: Type: text/plain, Size: 2285 bytes --]

Revoking keys (or keyrings) unlinks them from every keyring. Sometimes
it is useful to let the kernel keep a key even if ELL isn't directly
tracking that key anymore - for example, a keyring of trusted keys can
be used for validation without keeping l_key objects around for every
single key in that keyring. The kernel will clean up the kernel key
objects when there are no more references to them whether or not we
explicitly revoke from userspace.

l_key_free_norevoke and l_keyring_free_norevoke are added to support the
non-revoking behavior, while the default is still to revoke the key.
---
 ell/key.c | 20 ++++++++++++++++++++
 ell/key.h |  2 ++
 2 files changed, 22 insertions(+)

diff --git a/ell/key.c b/ell/key.c
index 4cf2307..370b3c8 100644
--- a/ell/key.c
+++ b/ell/key.c
@@ -286,6 +286,16 @@ LIB_EXPORT void l_key_free(struct l_key *key)
 	l_free(key);
 }
 
+LIB_EXPORT void l_key_free_norevoke(struct l_key *key)
+{
+	if (unlikely(!key))
+		return;
+
+	kernel_unlink_key(key->serial, internal_keyring);
+
+	l_free(key);
+}
+
 LIB_EXPORT bool l_key_update(struct l_key *key, const void *payload, size_t len)
 {
 	long error;
@@ -703,6 +713,16 @@ LIB_EXPORT void l_keyring_free(struct l_keyring *keyring)
 	l_free(keyring);
 }
 
+LIB_EXPORT void l_keyring_free_norevoke(struct l_keyring *keyring)
+{
+	if (unlikely(!keyring))
+		return;
+
+	kernel_unlink_key(keyring->serial, internal_keyring);
+
+	l_free(keyring);
+}
+
 bool l_keyring_link(struct l_keyring *keyring, const struct l_key *key)
 {
 	long error;
diff --git a/ell/key.h b/ell/key.h
index e7036c6..35c63eb 100644
--- a/ell/key.h
+++ b/ell/key.h
@@ -55,6 +55,7 @@ struct l_key *l_key_new(enum l_key_type type, const void *payload,
 			size_t payload_length);
 
 void l_key_free(struct l_key *key);
+void l_key_free_norevoke(struct l_key *key);
 
 bool l_key_update(struct l_key *key, const void *payload, size_t len);
 
@@ -92,6 +93,7 @@ struct l_keyring *l_keyring_new(enum l_keyring_type type,
 				const struct l_keyring *trust);
 
 void l_keyring_free(struct l_keyring *keyring);
+void l_keyring_free_norevoke(struct l_keyring *keyring);
 
 bool l_keyring_link(struct l_keyring *keyring, const struct l_key *key);
 
-- 
2.10.1


  reply	other threads:[~2016-10-24 21:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-24 21:36 [PATCH v2 1/3] unit: Fix memory leak in trust chain test Mat Martineau
2016-10-24 21:36 ` Mat Martineau [this message]
2016-10-25  1:59   ` [PATCH v2 2/3] key: Make key/keychain revocation optional when freeing Denis Kenzior
2016-10-24 21:36 ` [PATCH v2 3/3] tls: Validate cert chain using l_keyring Mat Martineau
2016-10-25  2:19   ` Denis Kenzior
2016-10-25  1:59 ` [PATCH v2 1/3] unit: Fix memory leak in trust chain test Denis Kenzior

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=20161024213633.10668-2-mathew.j.martineau@linux.intel.com \
    --to=mathew.j.martineau@linux.intel.com \
    --cc=ell@lists.01.org \
    /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.