From: Hannes Reinecke <hare@suse.de>
Date: Thu, 24 Aug 2023 16:39:13 +0200
Subject: security/keys: export key_lookup()
Patch-mainline: v6.7-rc1
Git-commit: 037c34318a479294cdb98dc8018edd5d191b68c0
References: bsc#1193203 jsc#PED-6252 jsc#PED-5728 jsc#PED-5062 jsc#PED-3535

For in-kernel consumers one cannot readily assign a user (eg when
running from a workqueue), so the normal key search permissions
cannot be applied.
This patch exports the 'key_lookup()' function for a simple lookup
of keys without checking for permissions.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Acked-by: David Howells <dhowells@redhat.com>
Signed-off-by: Keith Busch <kbusch@kernel.org>
Acked-by: Daniel Wagner <dwagner@suse.de>
---
 include/linux/key.h |    1 +
 security/keys/key.c |    1 +
 2 files changed, 2 insertions(+)

--- a/include/linux/key.h
+++ b/include/linux/key.h
@@ -518,6 +518,7 @@ extern void key_init(void);
 #define key_init()			do { } while(0)
 #define key_free_user_ns(ns)		do { } while(0)
 #define key_remove_domain(d)		do { } while(0)
+#define key_lookup(k)			NULL
 
 #endif /* CONFIG_KEYS */
 #endif /* __KERNEL__ */
--- a/security/keys/key.c
+++ b/security/keys/key.c
@@ -693,6 +693,7 @@ struct key *key_lookup(key_serial_t id)
 	spin_unlock(&key_serial_lock);
 	return key;
 }
+EXPORT_SYMBOL(key_lookup);
 
 /*
  * Find and lock the specified key type against removal.
