diff mbox series

[RFC,2/5] keys: add keyring_gc_custom()

Message ID 20230420202004.239116-3-smayhew@redhat.com (mailing list archive)
State New, archived
Headers show
Series SUNRPC: Add option to store GSS credentials in | expand

Commit Message

Scott Mayhew April 20, 2023, 8:20 p.m. UTC
Allow a keyring to be garbage collected using a custom select iterator.

This will be used to destroy all the GSS creds for a particular RPC
client when that RPC client is shut down.

Signed-off-by: Scott Mayhew <smayhew@redhat.com>
---
 include/linux/key.h     |  4 ++++
 security/keys/keyring.c | 11 +++++++++++
 2 files changed, 15 insertions(+)
diff mbox series

Patch

diff --git a/include/linux/key.h b/include/linux/key.h
index 3f4c6d6df921..6cfc60aca505 100644
--- a/include/linux/key.h
+++ b/include/linux/key.h
@@ -433,6 +433,10 @@  extern int restrict_link_reject(struct key *keyring,
 
 extern int keyring_clear(struct key *keyring);
 
+extern void keyring_gc_custom(struct key *keyring,
+			      bool (*iterator)(void *object, void *iterator_data),
+			      void *iterator_data);
+
 extern key_ref_t keyring_search(key_ref_t keyring,
 				struct key_type *type,
 				const char *description,
diff --git a/security/keys/keyring.c b/security/keys/keyring.c
index c57f3cef32fa..8e93f1bbd7f1 100644
--- a/security/keys/keyring.c
+++ b/security/keys/keyring.c
@@ -1795,3 +1795,14 @@  void keyring_restriction_gc(struct key *keyring, struct key_type *dead_type)
 
 	kleave(" [restriction gc]");
 }
+
+void keyring_gc_custom(struct key *keyring,
+		       bool (*iterator)(void *object, void *iterator_data),
+		       void *iterator_data)
+{
+	down_write(&keyring->sem);
+	assoc_array_gc(&keyring->keys, &keyring_assoc_array_ops,
+		       iterator, iterator_data);
+	up_write(&keyring->sem);
+}
+EXPORT_SYMBOL_GPL(keyring_gc_custom);