Factor out CONFIG_KEYCTL_PKEY from CONFIG_ASYMMETRIC_KEY_TYPE as an
off-by-default option so that systems that only need asymmetric keys for
in-kernel signature verification can choose not expose KEYCTL_PKEY_*
operations, and other key types can use them without pulling in
crypto/asymmetric_keys.

Suggested-by: Eric Biggers <[email protected]>
Signed-off-by: Jarkko Sakkinen <[email protected]>
---
 security/keys/Kconfig    | 9 +++++++++
 security/keys/Makefile   | 2 +-
 security/keys/internal.h | 2 +-
 security/keys/keyctl.c   | 2 +-
 4 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/security/keys/Kconfig b/security/keys/Kconfig
index 3f64d60d0f8a..75cc4043ca64 100644
--- a/security/keys/Kconfig
+++ b/security/keys/Kconfig
@@ -22,6 +22,15 @@ menuconfig KEYS
 
 if KEYS
 
+config KEYCTL_PKEY
+       bool "Public-key operations on retained keys"
+       help
+         This option provides support for querying, encrypting, decrypting,
+         signing, and verifying signatures via keyctl using public or
+         asymmetric keys retained in the kernel.
+
+         If you are unsure as to whether this is required, answer N.
+
 config KEYS_REQUEST_CACHE
        bool "Enable temporary caching of the last request_key() result"
        help
diff --git a/security/keys/Makefile b/security/keys/Makefile
index 5f40807f05b3..aafd28f7ee2f 100644
--- a/security/keys/Makefile
+++ b/security/keys/Makefile
@@ -22,7 +22,7 @@ obj-$(CONFIG_PROC_FS) += proc.o
 obj-$(CONFIG_SYSCTL) += sysctl.o
 obj-$(CONFIG_PERSISTENT_KEYRINGS) += persistent.o
 obj-$(CONFIG_KEY_DH_OPERATIONS) += dh.o
-obj-$(CONFIG_ASYMMETRIC_KEY_TYPE) += keyctl_pkey.o
+obj-$(CONFIG_KEYCTL_PKEY) += keyctl_pkey.o
 
 #
 # Key types
diff --git a/security/keys/internal.h b/security/keys/internal.h
index c452d71cce03..28c6cd942c59 100644
--- a/security/keys/internal.h
+++ b/security/keys/internal.h
@@ -314,7 +314,7 @@ static inline long compat_keyctl_dh_compute(
 #endif
 #endif
 
-#ifdef CONFIG_ASYMMETRIC_KEY_TYPE
+#ifdef CONFIG_KEYCTL_PKEY
 extern long keyctl_pkey_query(key_serial_t,
                              const char __user *,
                              struct keyctl_pkey_query __user *);
diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
index d6b10fd67627..417bba539bb1 100644
--- a/security/keys/keyctl.c
+++ b/security/keys/keyctl.c
@@ -28,7 +28,7 @@ static const unsigned char keyrings_capabilities[2] = {
        [0] = (KEYCTL_CAPS0_CAPABILITIES |
               (IS_ENABLED(CONFIG_PERSISTENT_KEYRINGS)  ? 
KEYCTL_CAPS0_PERSISTENT_KEYRINGS : 0) |
               (IS_ENABLED(CONFIG_KEY_DH_OPERATIONS)    ? 
KEYCTL_CAPS0_DIFFIE_HELLMAN : 0) |
-              (IS_ENABLED(CONFIG_ASYMMETRIC_KEY_TYPE)  ? 
KEYCTL_CAPS0_PUBLIC_KEY : 0) |
+              (IS_ENABLED(CONFIG_KEYCTL_PKEY)          ? 
KEYCTL_CAPS0_PUBLIC_KEY : 0) |
               (IS_ENABLED(CONFIG_BIG_KEYS)             ? KEYCTL_CAPS0_BIG_KEY 
: 0) |
               KEYCTL_CAPS0_INVALIDATE |
               KEYCTL_CAPS0_RESTRICT_KEYRING |
-- 
2.47.3


Reply via email to