All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] KEYS: Double max_size to make keyctl pkey_verify work
@ 2022-02-02  6:59 Vitaly Chikunov
  2022-02-02 12:55 ` Stefan Berger
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Vitaly Chikunov @ 2022-02-02  6:59 UTC (permalink / raw)
  To: keyrings, Jarkko Sakkinen, David Howells
  Cc: linux-crypto, linux-integrity, Stefan Berger, Eric Biggers

Rarely used `keyctl pkey_verify' can verify raw signatures, but was
failing, because ECDSA/EC-RDSA signature sizes are twice key sizes which
does not pass in/out sizes check in keyctl_pkey_params_get_2.
This in turn because these values cannot be distinguished by a single
`max_size' callback return value.
Also, `keyctl pkey_query` displays incorrect `max_sig_size' about these
algorithms.

Signed-off-by: Vitaly Chikunov <vt@altlinux.org>
---
 crypto/asymmetric_keys/public_key.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/crypto/asymmetric_keys/public_key.c b/crypto/asymmetric_keys/public_key.c
index 4fefb219bfdc..3ffbab07ed2a 100644
--- a/crypto/asymmetric_keys/public_key.c
+++ b/crypto/asymmetric_keys/public_key.c
@@ -143,8 +143,19 @@ static int software_key_query(const struct kernel_pkey_params *params,
 
 	len = crypto_akcipher_maxsize(tfm);
 	info->key_size = len * 8;
-	info->max_data_size = len;
-	info->max_sig_size = len;
+	if (strcmp(alg_name, "ecrdsa") == 0 ||
+	    strncmp(alg_name, "ecdsa-", 6) == 0) {
+		/*
+		 * For these algos sig size is twice key size.
+		 * keyctl uses max_sig_size as minimum input size, and
+		 * max_data_size as minimum output size for a signature.
+		 */
+		info->max_data_size = len * 2;
+		info->max_sig_size = len * 2;
+	} else {
+		info->max_data_size = len;
+		info->max_sig_size = len;
+	}
 	info->max_enc_size = len;
 	info->max_dec_size = len;
 	info->supported_ops = (KEYCTL_SUPPORTS_ENCRYPT |
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-02-25 19:47 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-02  6:59 [RFC PATCH] KEYS: Double max_size to make keyctl pkey_verify work Vitaly Chikunov
2022-02-02 12:55 ` Stefan Berger
2022-02-02 21:24   ` Vitaly Chikunov
2022-02-02 22:38     ` Vitaly Chikunov
2022-02-03  3:42       ` Stefan Berger
2022-02-03  0:07     ` Vitaly Chikunov
2022-02-20 23:31   ` Jarkko Sakkinen
2022-02-03  3:15 ` Stefan Berger
2022-02-03  3:34   ` Vitaly Chikunov
2022-02-20 23:29   ` Jarkko Sakkinen
2022-02-21  2:43     ` Vitaly Chikunov
2022-02-25 19:47       ` Stefan Berger
2022-02-20 23:25 ` Jarkko Sakkinen

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.