* Re: [PATCH 1/2] KEYS: fix signature length passed to KEYCTL_PKEY_VERIFY
2026-11-11 15:56 ` [PATCH 1/2] KEYS: fix signature length passed to KEYCTL_PKEY_VERIFY Florian Bauckholt via B4 Relay
@ 2026-11-11 16:40 ` sashiko-bot
2026-11-11 22:56 ` Jarkko Sakkinen
` (2 subsequent siblings)
3 siblings, 0 replies; 10+ messages in thread
From: sashiko-bot @ 2026-11-11 16:40 UTC (permalink / raw)
Cc: linux-security-module
> From: Florian Bauckholt <florian.bauckholt@cispa.de>
>
> 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. It copies max_sig_size bytes from the signature pointer and
> passes max_sig_size as the signature size to the verification.
>
> This makes no difference for signatures that are always max_sig_size
> bytes long, such as RSA. A shorter signature, e.g. a DER-encoded ECDSA
> signature, is followed by whatever is behind 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 the signature,
> which hides the problem.
>
> 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@vger.kernel.org
> Link: https://lore.kernel.org/all/20260919221742.3709658-1-benquike@gmail.com/
> Signed-off-by: Florian Bauckholt <florian.bauckholt@cispa.de>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261111-keyctl-pkey-fixes-v1-0-934ebaa267a7@cispa.de?part=1
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH 1/2] KEYS: fix signature length passed to KEYCTL_PKEY_VERIFY
2026-11-11 15:56 ` [PATCH 1/2] KEYS: fix signature length passed to KEYCTL_PKEY_VERIFY Florian Bauckholt via B4 Relay
2026-11-11 16:40 ` sashiko-bot
@ 2026-11-11 22:56 ` Jarkko Sakkinen
2026-11-17 13:21 ` Rodolfo Giometti
2026-11-18 20:08 ` Stefan Berger
3 siblings, 0 replies; 10+ messages in thread
From: Jarkko Sakkinen @ 2026-11-11 22:56 UTC (permalink / raw)
To: florian.bauckholt
Cc: David Howells, Lukas Wunner, Ignat Korchagin, Herbert Xu,
David S. Miller, Paul Moore, James Morris, Serge E. Hallyn,
Hui Peng, keyrings, linux-crypto, linux-security-module,
linux-kernel, stable
On Wed, Nov 11, 2026 at 04:56:07PM +0100, Florian Bauckholt via B4 Relay wrote:
> From: Florian Bauckholt <florian.bauckholt@cispa.de>
>
> 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. It copies max_sig_size bytes from the signature pointer and
> passes max_sig_size as the signature size to the verification.
>
> This makes no difference for signatures that are always max_sig_size
> bytes long, such as RSA. A shorter signature, e.g. a DER-encoded ECDSA
> signature, is followed by whatever is behind 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 the signature,
> which hides the problem.
>
> 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@vger.kernel.org
> Link: https://lore.kernel.org/all/20260919221742.3709658-1-benquike@gmail.com/
> Signed-off-by: Florian Bauckholt <florian.bauckholt@cispa.de>
> ---
> 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 15b6bf6399b5..794fa3d01911 100644
> --- a/security/keys/keyctl_pkey.c
> +++ b/security/keys/keyctl_pkey.c
> @@ -160,7 +160,7 @@ static int keyctl_pkey_params_get_2(const struct keyctl_pkey_params __user *_par
> uparams.in2_len > info.max_sig_size)
> return -EINVAL;
>
> - params->out_len = info.max_sig_size;
> + params->in2_len = uparams.in2_len;
> break;
> default:
> return -EOPNOTSUPP;
>
> --
> 2.56.0
>
>
Thanks, good catch, and apologies for causing this bug.
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Br, Jarkko
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH 1/2] KEYS: fix signature length passed to KEYCTL_PKEY_VERIFY
2026-11-11 15:56 ` [PATCH 1/2] KEYS: fix signature length passed to KEYCTL_PKEY_VERIFY Florian Bauckholt via B4 Relay
2026-11-11 16:40 ` sashiko-bot
2026-11-11 22:56 ` Jarkko Sakkinen
@ 2026-11-17 13:21 ` Rodolfo Giometti
2026-11-18 20:08 ` Stefan Berger
3 siblings, 0 replies; 10+ messages in thread
From: Rodolfo Giometti @ 2026-11-17 13:21 UTC (permalink / raw)
To: Florian Bauckholt, David Howells, Jarkko Sakkinen, Lukas Wunner,
Ignat Korchagin, Herbert Xu, David S. Miller
Cc: Paul Moore, James Morris, Serge E. Hallyn, Hui Peng,
Stefan Berger, keyrings, linux-crypto, linux-security-module,
linux-kernel, stable
On 11/11/2026 16:56, Florian Bauckholt wrote:
> 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. It copies max_sig_size bytes from the signature pointer and
> passes max_sig_size as the signature size to the verification.
>
> This makes no difference for signatures that are always max_sig_size
> bytes long, such as RSA. A shorter signature, e.g. a DER-encoded ECDSA
> signature, is followed by whatever is behind 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 the signature,
> which hides the problem.
The test suite of craf (https://github.com/giometti/crypto-afalg,
test3008) hits this with RSA too: it cuts a genuine 256-byte RSA-2048
PKCS#1 signature to 255 bytes and expects the verify to fail. On
Ubuntu's 6.8.0-147 kernel, which carries the stable backport of
cb481e59ea6c, the cut signature verifies about once in 256 runs. Over
2000 runs per build:
plain: ok=1991 ko=9
asan: ok=1997 ko=3
and a failing run prints (line wrapped here):
libkcrypto [pkey-cert]: kc-check pkey-verify cert:test3008.cert
enc=pkcs1 hash=sha256 test3008.d256 test3008.bad: exit 0, not 1:
KO!
To reproduce it (the count printed is the number of failures; here it
gave 3 out of 1000 runs):
git clone https://github.com/giometti/crypto-afalg
cd crypto-afalg/tests
export TESTS_TMPDIR=$(mktemp -d)
for i in $(seq 1000); do ./do_test.sh 3008; done | grep -c 'KO!'
I also replayed the inputs of one failing run on a UML kernel of
current mainline (666539eecdf4, after v7.4-rc3): the 255-byte signature
verifies 20 times out of 20, and with your patch applied it is refused
20 times out of 20.
Maybe it is worth saying so in the commit message, since this is going
to stable?
I'll send my Tested-by once test3008 has run 2000 times on a kernel
with your patch applied.
>
> 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@vger.kernel.org
> Link: https://lore.kernel.org/all/20260919221742.3709658-1-benquike@gmail.com/
> Signed-off-by: Florian Bauckholt <florian.bauckholt@cispa.de>
> ---
> 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 15b6bf6399b5..794fa3d01911 100644
> --- a/security/keys/keyctl_pkey.c
> +++ b/security/keys/keyctl_pkey.c
> @@ -160,7 +160,7 @@ static int keyctl_pkey_params_get_2(const struct keyctl_pkey_params __user *_par
> uparams.in2_len > info.max_sig_size)
> return -EINVAL;
>
> - params->out_len = info.max_sig_size;
> + params->in2_len = uparams.in2_len;
> break;
> default:
> return -EOPNOTSUPP;
>
Ciao,
Rodolfo
--
GNU/Linux Solutions e-mail: giometti@enneenne.com
Linux Device Driver giometti@linux.it
Embedded Systems phone: +39 349 2432127
UNIX programming
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH 1/2] KEYS: fix signature length passed to KEYCTL_PKEY_VERIFY
2026-11-11 15:56 ` [PATCH 1/2] KEYS: fix signature length passed to KEYCTL_PKEY_VERIFY Florian Bauckholt via B4 Relay
` (2 preceding siblings ...)
2026-11-17 13:21 ` Rodolfo Giometti
@ 2026-11-18 20:08 ` Stefan Berger
2026-11-18 20:28 ` Jarkko Sakkinen
3 siblings, 1 reply; 10+ messages in thread
From: Stefan Berger @ 2026-11-18 20:08 UTC (permalink / raw)
To: florian.bauckholt, David Howells, Jarkko Sakkinen, Lukas Wunner,
Ignat Korchagin, Herbert Xu, David S. Miller
Cc: Paul Moore, James Morris, Serge E. Hallyn, Hui Peng, keyrings,
linux-crypto, linux-security-module, linux-kernel, stable
On 11/11/26 10:56 AM, Florian Bauckholt via B4 Relay wrote:
> From: Florian Bauckholt <florian.bauckholt@cispa.de>
>
> 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. It copies max_sig_size bytes from the signature pointer and
> passes max_sig_size as the signature size to the verification.
>
> This makes no difference for signatures that are always max_sig_size
> bytes long, such as RSA. A shorter signature, e.g. a DER-encoded ECDSA
> signature, is followed by whatever is behind 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 the signature,
> which hides the problem.
>
> 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@vger.kernel.org
> Link: https://lore.kernel.org/all/20260919221742.3709658-1-benquike@gmail.com/
> Signed-off-by: Florian Bauckholt <florian.bauckholt@cispa.de>
Tested-by: Stefan Berger <stefanb@linux.ibm.com>
> ---
> 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 15b6bf6399b5..794fa3d01911 100644
> --- a/security/keys/keyctl_pkey.c
> +++ b/security/keys/keyctl_pkey.c
> @@ -160,7 +160,7 @@ static int keyctl_pkey_params_get_2(const struct keyctl_pkey_params __user *_par
> uparams.in2_len > info.max_sig_size)
> return -EINVAL;
>
> - params->out_len = info.max_sig_size;
> + params->in2_len = uparams.in2_len;
> break;
> default:
> return -EOPNOTSUPP;
>
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH 1/2] KEYS: fix signature length passed to KEYCTL_PKEY_VERIFY
2026-11-18 20:08 ` Stefan Berger
@ 2026-11-18 20:28 ` Jarkko Sakkinen
0 siblings, 0 replies; 10+ messages in thread
From: Jarkko Sakkinen @ 2026-11-18 20:28 UTC (permalink / raw)
To: Stefan Berger
Cc: florian.bauckholt, David Howells, Lukas Wunner, Ignat Korchagin,
Herbert Xu, David S. Miller, Paul Moore, James Morris,
Serge E. Hallyn, Hui Peng, keyrings, linux-crypto,
linux-security-module, linux-kernel, stable
On Wed, Nov 18, 2026 at 03:08:19PM -0500, Stefan Berger wrote:
>
>
> On 11/11/26 10:56 AM, Florian Bauckholt via B4 Relay wrote:
> > From: Florian Bauckholt <florian.bauckholt@cispa.de>
> >
> > 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. It copies max_sig_size bytes from the signature pointer and
> > passes max_sig_size as the signature size to the verification.
> >
> > This makes no difference for signatures that are always max_sig_size
> > bytes long, such as RSA. A shorter signature, e.g. a DER-encoded ECDSA
> > signature, is followed by whatever is behind 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 the signature,
> > which hides the problem.
> >
> > 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@vger.kernel.org
> > Link: https://lore.kernel.org/all/20260919221742.3709658-1-benquike@gmail.com/
> > Signed-off-by: Florian Bauckholt <florian.bauckholt@cispa.de>
>
> Tested-by: Stefan Berger <stefanb@linux.ibm.com>
Can these patches be rebased? They don't apply.
I've probably missed b4 shazam issue last time.
Was just wondering why I don't have these yet.
Br, Jarkko
^ permalink raw reply [flat|nested] 10+ messages in thread