Linux Security Modules development
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko@kernel.org>
To: sashiko-reviews@lists.linux.dev, "Marek Behún" <kabel@kernel.org>
Cc: keyrings@vger.kernel.org, dm-devel@lists.linux.dev,
	linux-crypto@vger.kernel.org,
	linux-security-module@vger.kernel.org,
	Ahmad Fatoum <a.fatoum@pengutronix.de>,
	Alasdair Kergon <agk@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Benjamin Marzinski <bmarzins@redhat.com>,
	David Gstir <david@sigma-star.at>,
	David Howells <dhowells@redhat.com>,
	David Laight <david.laight.linux@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	David Woodhouse <dwmw2@infradead.org>,
	Eric Biggers <ebiggers@kernel.org>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	Ignat Korchagin <ignat@linux.win>,
	James Bottomley <James.Bottomley@hansenpartnership.com>,
	James Morris <jmorris@namei.org>,
	James Prestwood <prestwoj@gmail.com>,
	Jason Gunthorpe <jgg@ziepe.ca>, Jonathan Corbet <corbet@lwn.net>,
	Lukas Wunner <lukas@wunner.de>, Mike Snitzer <snitzer@kernel.org>,
	Mikulas Patocka <mpatocka@redhat.com>,
	Mimi Zohar <zohar@linux.ibm.com>,
	Paul Moore <paul@paul-moore.com>, Peter Huewe <peterhuewe@gmx.de>,
	Randy Dunlap <rdunlap@infradead.org>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Sumit Garg <sumit.garg@kernel.org>
Subject: Re: [PATCH v3 1/9] KEYS: Factor out opt-in KEYCTL_PKEY
Date: Wed, 25 Nov 2026 21:49:29 +0200	[thread overview]
Message-ID: <awc7yQrc4R6Y915l@kernel.org> (raw)
In-Reply-To: <awcwHuvFhr7yfbgO@kernel.org>

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

On Wed, Nov 25, 2026 at 08:59:45PM +0200, Jarkko Sakkinen wrote:
> On Wed, Nov 25, 2026 at 08:57:48PM +0200, Jarkko Sakkinen wrote:
> > On Wed, Nov 25, 2026 at 06:22:49PM +0000, sashiko-bot@kernel.org wrote:
> > > [Severity: Medium]
> > > Should TURRIS_SIGNING_KEY, TURRIS_OMNIA_MCU_KEYCTL and
> > > TURRIS_MOX_RWTM_KEYCTL be updated to depend on KEYCTL_PKEY instead of
> > > ASYMMETRIC_KEY_TYPE?
> > 
> > Yes, and it make sense to add a level of granularity to this i.e., to
> > make on/off subsystem specific choice.
> 
> In other words you want to have it "default on" for Turris while at the
> same time being "default off" for asymmetric keys.
> 
> Not particularly complicated to implement but this was pretty useful
> review comment from Sashiko to point this out.

What do you think of this?

Br, Jarkko

[-- Attachment #2: 0001-KEYS-Factor-out-KEYCTL_PKEY.patch --]
[-- Type: text/x-diff, Size: 6797 bytes --]

From 722be64c6b1eed4d6b07ee2667133db266d70921 Mon Sep 17 00:00:00 2001
From: Jarkko Sakkinen <jarkko@kernel.org>
Date: Tue, 24 Nov 2026 12:56:33 +0200
Subject: [PATCH] KEYS: Factor out KEYCTL_PKEY

Factor out CONFIG_KEYCTL_PKEY from CONFIG_ASYMMETRIC_KEY_TYPE as a hidden
helper symbol and make keyctl public-key support a per-subsystem choice:

- Add off-by-default CONFIG_ASYMMETRIC_KEY_PKEY to gate keyctl public-key
  operations on software asymmetric keys so systems that only need
  CONFIG_ASYMMETRIC_KEY_TYPE for in-kernel signature verification do not
  expose KEYCTL_PKEY_* operations.
- Switch TURRIS_SIGNING_KEY, TURRIS_OMNIA_MCU_KEYCTL, and
  TURRIS_MOX_RWTM_KEYCTL from CONFIG_ASYMMETRIC_KEY_TYPE to
  CONFIG_KEYCTL_PKEY while keeping them enabled by default.

Suggested-by: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 crypto/asymmetric_keys/Kconfig           | 11 +++++++++++
 crypto/asymmetric_keys/asymmetric_keys.h |  2 ++
 crypto/asymmetric_keys/asymmetric_type.c |  4 ++++
 drivers/firmware/Kconfig                 |  1 -
 drivers/platform/cznic/Kconfig           |  3 +--
 security/keys/Kconfig                    |  3 +++
 security/keys/Makefile                   |  2 +-
 security/keys/internal.h                 |  2 +-
 security/keys/keyctl.c                   |  2 +-
 9 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/crypto/asymmetric_keys/Kconfig b/crypto/asymmetric_keys/Kconfig
index c73979b2e98e..a1fa64a38f24 100644
--- a/crypto/asymmetric_keys/Kconfig
+++ b/crypto/asymmetric_keys/Kconfig
@@ -10,6 +10,17 @@ menuconfig ASYMMETRIC_KEY_TYPE
 
 if ASYMMETRIC_KEY_TYPE
 
+config ASYMMETRIC_KEY_PKEY
+	bool "Asymmetric key keyctl public-key operations"
+	select KEYCTL_PKEY
+	help
+	  This option exposes keyctl public-key operations (query, encrypt,
+	  decrypt, sign, and verify) on asymmetric keys to userspace.
+	  In-kernel signature verification (such as module and kexec
+	  verification) does not require this option.
+
+	  If you are unsure as to whether this is required, answer N.
+
 config ASYMMETRIC_PUBLIC_KEY_SUBTYPE
 	tristate "Asymmetric public-key crypto algorithm subtype"
 	select MPILIB
diff --git a/crypto/asymmetric_keys/asymmetric_keys.h b/crypto/asymmetric_keys/asymmetric_keys.h
index dc854cb737fb..7b669f41f297 100644
--- a/crypto/asymmetric_keys/asymmetric_keys.h
+++ b/crypto/asymmetric_keys/asymmetric_keys.h
@@ -13,5 +13,7 @@ extern int __asymmetric_key_hex_to_key_id(const char *id,
 					  struct asymmetric_key_id *match_id,
 					  size_t hexlen);
 
+#ifdef CONFIG_ASYMMETRIC_KEY_PKEY
 extern int asymmetric_key_eds_op(struct kernel_pkey_params *params,
 				 const void *in, void *out);
+#endif
diff --git a/crypto/asymmetric_keys/asymmetric_type.c b/crypto/asymmetric_keys/asymmetric_type.c
index 16a7ae16593c..8b8a75b70527 100644
--- a/crypto/asymmetric_keys/asymmetric_type.c
+++ b/crypto/asymmetric_keys/asymmetric_type.c
@@ -565,6 +565,7 @@ static struct key_restriction *asymmetric_lookup_restriction(
 	return ret;
 }
 
+#ifdef CONFIG_ASYMMETRIC_KEY_PKEY
 int asymmetric_key_eds_op(struct kernel_pkey_params *params,
 			  const void *in, void *out)
 {
@@ -603,6 +604,7 @@ static int asymmetric_key_verify_signature(struct kernel_pkey_params *params,
 
 	return verify_signature(params->key, &sig);
 }
+#endif
 
 struct key_type key_type_asymmetric = {
 	.name			= "asymmetric",
@@ -614,9 +616,11 @@ struct key_type key_type_asymmetric = {
 	.destroy		= asymmetric_key_destroy,
 	.describe		= asymmetric_key_describe,
 	.lookup_restriction	= asymmetric_lookup_restriction,
+#ifdef CONFIG_ASYMMETRIC_KEY_PKEY
 	.asym_query		= query_asymmetric_key,
 	.asym_eds_op		= asymmetric_key_eds_op,
 	.asym_verify_signature	= asymmetric_key_verify_signature,
+#endif
 };
 EXPORT_SYMBOL_GPL(key_type_asymmetric);
 
diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig
index 43e2e2a64594..9f382ba10fc9 100644
--- a/drivers/firmware/Kconfig
+++ b/drivers/firmware/Kconfig
@@ -288,7 +288,6 @@ config TURRIS_MOX_RWTM_KEYCTL
 	bool "Turris Mox rWTM ECDSA message signing"
 	default y
 	depends on KEYS
-	depends on ASYMMETRIC_KEY_TYPE
 	select CZNIC_PLATFORMS
 	select TURRIS_SIGNING_KEY
 	help
diff --git a/drivers/platform/cznic/Kconfig b/drivers/platform/cznic/Kconfig
index 61cff5f7e02e..850319fb8c67 100644
--- a/drivers/platform/cznic/Kconfig
+++ b/drivers/platform/cznic/Kconfig
@@ -80,7 +80,6 @@ config TURRIS_OMNIA_MCU_KEYCTL
 	bool "Turris Omnia MCU ECDSA message signing"
 	default y
 	depends on KEYS
-	depends on ASYMMETRIC_KEY_TYPE
 	depends on TURRIS_OMNIA_MCU_GPIO
 	select TURRIS_SIGNING_KEY
 	help
@@ -93,6 +92,6 @@ endif # TURRIS_OMNIA_MCU
 config TURRIS_SIGNING_KEY
 	tristate
 	depends on KEYS
-	depends on ASYMMETRIC_KEY_TYPE
+	select KEYCTL_PKEY
 
 endif # CZNIC_PLATFORMS
diff --git a/security/keys/Kconfig b/security/keys/Kconfig
index 3f64d60d0f8a..c0cd894d306c 100644
--- a/security/keys/Kconfig
+++ b/security/keys/Kconfig
@@ -22,6 +22,9 @@ menuconfig KEYS
 
 if KEYS
 
+config KEYCTL_PKEY
+	bool
+
 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	other threads:[~2026-11-25 19:49 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 18:06 [PATCH v3 0/9] KEYS: trusted: asymmetric keys Jarkko Sakkinen
2026-11-25 18:06 ` [PATCH v3 1/9] KEYS: Factor out opt-in KEYCTL_PKEY Jarkko Sakkinen
2026-11-25 18:22   ` sashiko-bot
2026-11-25 18:57     ` Jarkko Sakkinen
2026-11-25 18:59       ` Jarkko Sakkinen
2026-11-25 19:49         ` Jarkko Sakkinen [this message]
2026-11-25 18:06 ` [PATCH v3 2/9] KEYS: trusted: Allow ASN.1 TPM2 sealed data shorter than MIN_KEY_SIZE Jarkko Sakkinen
2026-11-25 18:06 ` [PATCH v3 3/9] lib/asn1_encoder: Add asn1_encode_integer_bytes() Jarkko Sakkinen
2026-11-25 18:06 ` [PATCH v3 4/9] tpm: Export tpm2_create_primary() Jarkko Sakkinen
2026-11-25 18:06 ` [PATCH v3 5/9] tpm: Add persistent hierarchies to tpm2_create_primary() Jarkko Sakkinen
2026-11-25 18:06 ` [PATCH v3 6/9] KEYS: trusted: Extend TPMKey support Jarkko Sakkinen
2026-11-25 18:06 ` [PATCH v3 7/9] KEYS: trusted: Reject zero-length keys in symmetric consumers Jarkko Sakkinen
2026-11-25 18:06 ` [PATCH v3 8/9] KEYS: trusted: Factor out TPM2 blob loading Jarkko Sakkinen
2026-11-25 18:16   ` sashiko-bot
2026-11-25 19:03     ` Jarkko Sakkinen
2026-11-25 20:14       ` Jarkko Sakkinen
2026-11-25 18:06 ` [PATCH v3 9/9] KEYS: trusted: Add asymmetric key support for TPM2 Jarkko Sakkinen
2026-11-25 21:17   ` Jarkko Sakkinen
2026-11-25 21:25     ` Jarkko Sakkinen
2026-11-25 18:22 ` [PATCH v3 0/9] KEYS: trusted: asymmetric keys sashiko-bot

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=awc7yQrc4R6Y915l@kernel.org \
    --to=jarkko@kernel.org \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=a.fatoum@pengutronix.de \
    --cc=agk@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=bmarzins@redhat.com \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=david.laight.linux@gmail.com \
    --cc=david@sigma-star.at \
    --cc=dhowells@redhat.com \
    --cc=dm-devel@lists.linux.dev \
    --cc=dwmw2@infradead.org \
    --cc=ebiggers@kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=ignat@linux.win \
    --cc=jgg@ziepe.ca \
    --cc=jmorris@namei.org \
    --cc=kabel@kernel.org \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=mpatocka@redhat.com \
    --cc=paul@paul-moore.com \
    --cc=peterhuewe@gmx.de \
    --cc=prestwoj@gmail.com \
    --cc=rdunlap@infradead.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=serge@hallyn.com \
    --cc=skhan@linuxfoundation.org \
    --cc=snitzer@kernel.org \
    --cc=sumit.garg@kernel.org \
    --cc=zohar@linux.ibm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox