[PATCH 2/2] KEYS: asymmetric: Fix PKCS#1 decryption of an empty message
Herbert Xu
herbert at gondor.apana.org.au
Fri Nov 20 09:52:55 UTC 2026
On Wed, Nov 11, 2026 at 04:56:08PM +0100, Florian Bauckholt via B4 Relay wrote:
> From: Florian Bauckholt <florian.bauckholt at cispa.de>
>
> KEYCTL_PKEY_DECRYPT with enc=pkcs1 on a valid ciphertext of an empty
> message returns the key size instead of 0, and the output buffer is
> filled with the ciphertext.
>
> crypto_akcipher_sync_encrypt() returns 0 on success, so
> software_key_eds_op() maps a result of 0 to crypto_akcipher_maxsize().
> The mapping is applied to decryption as well, but
> crypto_akcipher_sync_decrypt() returns the length of the plaintext,
> which is 0 for an empty message. By then crypto_akcipher_sync_post()
> has copied its scratch buffer to the output. pkcs1pad copied nothing
> into that buffer, so it still holds the ciphertext.
>
> Only the caller's own input is returned, so nothing is disclosed, and
> messages that are not empty are decrypted correctly. An empty message
> is valid, though: RFC 8017 section 7.2 only limits the message length
> to k - 11 octets.
>
> Apply the mapping to encryption only.
>
> Fixes: 63ba4d67594a ("KEYS: asymmetric: Use new crypto interface without scatterlists")
> Cc: stable at vger.kernel.org # v6.5+
> Link: https://lore.kernel.org/all/20260919221742.3709658-1-benquike@gmail.com/
> Signed-off-by: Florian Bauckholt <florian.bauckholt at cispa.de>
> ---
> crypto/asymmetric_keys/public_key.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
Patch applied. Thanks.
--
Email: Herbert Xu <herbert at gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
More information about the Linux-security-module-archive
mailing list