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

From: Jarkko Sakkinen

Date: Thu Nov 19 2026 - 07:56:18 EST


On Thu, Nov 19, 2026 at 11:25:07AM +0100, Rodolfo Giometti wrote:
> On 19/11/2026 00:19, Florian Bauckholt via B4 Relay wrote:
> > From: Florian Bauckholt <florian.bauckholt@xxxxxxxx>
> >
> > Commit cb481e59ea6c ("KEYS: fix overflow in keyctl_pkey_params_get_2()")
> > made keyctl_pkey_params_get_2() set params->out_len to the maximum
> > output size of the operation instead of the size provided by the caller.
> > It does so for KEYCTL_PKEY_VERIFY as well, but verify has no output
> > buffer: out_len shares a union with in2_len, the length of the
> > signature.
> >
> > 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.
> >
> > The x962 ECDSA template currently ignores data following a DER-encoded
> > signature, which hides the problem there. A truncated RSA signature,
> > however, is accepted if the bytes following it happen to match the ones
> > that were cut off, as reported by Rodolfo Giometti [1].
> >
> > Use the length provided by the caller, which has already been checked
> > against max_sig_size.
> >
> > Fixes: cb481e59ea6c ("KEYS: fix overflow in keyctl_pkey_params_get_2()")
> > Cc: stable@xxxxxxxxxxxxxxx
> > Link: https://lore.kernel.org/all/20260919221742.3709658-1-benquike@xxxxxxxxx/
> > Link: https://lore.kernel.org/all/0e20f799-e389-40d2-aaee-2f174748faae@xxxxxxxxxxxx/ [1]
> > Reviewed-by: Jarkko Sakkinen <jarkko@xxxxxxxxxx>
> > Tested-by: Stefan Berger <stefanb@xxxxxxxxxxxxx>
> > Signed-off-by: Florian Bauckholt <florian.bauckholt@xxxxxxxx>
> > ---
> > security/keys/keyctl_pkey.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/security/keys/keyctl_pkey.c b/security/keys/keyctl_pkey.c
> > index e7121523b9c9..722521a014ab 100644
> > --- a/security/keys/keyctl_pkey.c
> > +++ b/security/keys/keyctl_pkey.c
> > @@ -175,7 +175,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;
> >
>
> I ran test3008 of craf 2000 times on a UML kernel of current mainline
> (666539eecdf4) with this change applied: no failures, against 4 out of
> 2000 without it.
>
> Tested-by: Rodolfo Giometti <giometti@xxxxxxxxxxxx>

Thanks.

Reviewed-by: Jarkko Sakkinen <jarkko@xxxxxxxxxx>


>
> Ciao,
>
> Rodolfo
>
> --
> GNU/Linux Solutions e-mail: giometti@xxxxxxxxxxxx
> Linux Device Driver giometti@xxxxxxxx
> Embedded Systems phone: +39 349 2432127
> UNIX programming

Br, Jarkko