Re: [PATCH 2/2] KEYS: Fix asym key overflow in keyctl_pkey_verify()
From: Guicai Ma
Date: Tue Nov 24 2026 - 00:25:41 EST
On Mon, Nov 23, 2026 at 11:19:59PM +0200, Jarkko Sakkinen wrote:
> While verifying a variable-length signature shorter than info.max_sig_size,
> memdup_user() reads past the end of the caller's _in2 and passes trailing
> bytes to ->asym_verify_signature().
>
> Set params->in2_len to uparams.in2_len in the KEYCTL_PKEY_VERIFY case.
[...]
> @@ -176,7 +176,7 @@ static int keyctl_pkey_params_get_2(const struct keyctl_pkey_params __user *_par
> goto out_up_key_sem;
> }
>
> - params->out_len = info.max_sig_size;
> + params->in2_len = uparams.in2_len;
> break;
> default:
> ret = -EOPNOTSUPP;
Tested this series with an RSA-2048 key (enc=pkcs1 hash=sha256) on
arm64. A truncated signature with the remaining bytes still present in
userspace memory and a short signature placed right before an unmapped
page now both fail with -EINVAL, and normal signature verification
still passes.
Reviewed-by: Guicai Ma <maguicai@xxxxxxxxxx>
Tested-by: Guicai Ma <maguicai@xxxxxxxxxx>