[PATCH v2 2/2] KEYS: asymmetric: Fix PKCS#1 decryption of an empty message

Guicai Ma maguicai at kylinos.cn
Thu Nov 19 07:50:07 UTC 2026


On Wed, Nov 18, 2026 at 11:19:29PM +0000, Florian Bauckholt wrote:
>  	case kernel_pkey_encrypt:
>  		if (issig)
>  			break;
>  		ret = crypto_akcipher_sync_encrypt(tfm, in, params->in_len,
>  						   out, params->out_len);
> +		/* Returns 0 on success and always fills the whole output. */
> +		if (ret == 0)
> +			ret = crypto_akcipher_maxsize(tfm);
>  		break;

Checked both the pkcs1pad and raw RSA (mpi_write_to_sgl()) paths for
!issig, and tested with an RSA-2048 PKCS#8 key on arm64:

- KEYCTL_PKEY_DECRYPT (enc=pkcs1) on a valid ciphertext of an empty
  message returned 256 and copied the ciphertext back to userspace before
  this patch; with the patch applied it returns 0 and leaves the userspace
  output buffer untouched.
- Non-empty PKCS#1 and raw RSA (enc=raw) encrypt/decrypt roundtrips both
  continue to work as expected.

Reviewed-by: Guicai Ma <maguicai at kylinos.cn>
Tested-by: Guicai Ma <maguicai at kylinos.cn>



More information about the Linux-security-module-archive mailing list