Re: [PATCH v2 1/2] KEYS: fix signature length passed to KEYCTL_PKEY_VERIFY

From: Guicai Ma

Date: Thu Nov 19 2026 - 02:50:26 EST


On Wed, Nov 18, 2026 at 11:19:28PM +0000, Florian Bauckholt wrote:
> As a result keyctl_pkey_verify() ignores the signature length passed by
> the caller and always reads max_sig_size bytes from the signature
> pointer. A shorter signature is extended with whatever follows it in
> the caller's memory, or the call fails with -EFAULT if that memory is
> not readable.

Verified the union usage in struct kernel_pkey_params and reproduced both
failure modes on arm64 with an RSA-2048 PKCS#8 key (enc=pkcs1 hash=sha256):

- A truncated 200-byte signature with the remaining 56 bytes still intact
in userspace memory was falsely accepted (0) before this patch, and is
now rejected with -EINVAL.
- A 16-byte signature placed right before a PROT_NONE guard page (as well
as a 0-byte signature at the page boundary) returned -EFAULT before this
patch, and now returns -EINVAL without faulting.

Reviewed-by: Guicai Ma <maguicai@xxxxxxxxxx>
Tested-by: Guicai Ma <maguicai@xxxxxxxxxx>