Linux Security Modules development
 help / color / mirror / Atom feed
From: Florian Bauckholt via B4 Relay <devnull+florian.bauckholt.cispa.de@kernel.org>
To: David Howells <dhowells@redhat.com>,
	 Jarkko Sakkinen <jarkko@kernel.org>,
	Lukas Wunner <lukas@wunner.de>,
	 Ignat Korchagin <ignat@linux.win>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	 "David S. Miller" <davem@davemloft.net>
Cc: Paul Moore <paul@paul-moore.com>,
	James Morris <jmorris@namei.org>,
	 "Serge E. Hallyn" <serge@hallyn.com>,
	Hui Peng <benquike@gmail.com>,
	 Stefan Berger <stefanb@linux.ibm.com>,
	 Rodolfo Giometti <giometti@enneenne.com>,
	keyrings@vger.kernel.org,  linux-crypto@vger.kernel.org,
	linux-security-module@vger.kernel.org,
	 linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	 Florian Bauckholt <florian.bauckholt@cispa.de>
Subject: [PATCH v2 1/2] KEYS: fix signature length passed to KEYCTL_PKEY_VERIFY
Date: Thu, 19 Nov 2026 00:19:28 +0100	[thread overview]
Message-ID: <20261119-keyctl-pkey-fixes-v2-1-9e2d1c7db7ec@cispa.de> (raw)
In-Reply-To: <20261119-keyctl-pkey-fixes-v2-0-9e2d1c7db7ec@cispa.de>

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 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@vger.kernel.org
Link: https://lore.kernel.org/all/20260919221742.3709658-1-benquike@gmail.com/
Link: https://lore.kernel.org/all/0e20f799-e389-40d2-aaee-2f174748faae@enneenne.com/ [1]
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Tested-by: Stefan Berger <stefanb@linux.ibm.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 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;

-- 
2.56.0



  reply	other threads:[~2026-11-18 23:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 23:19 [PATCH v2 0/2] KEYS: two fixes for the asymmetric keyctl operations Florian Bauckholt via B4 Relay
2026-11-18 23:19 ` Florian Bauckholt via B4 Relay [this message]
2026-11-18 23:24   ` [PATCH v2 1/2] KEYS: fix signature length passed to KEYCTL_PKEY_VERIFY sashiko-bot
2026-11-18 23:19 ` [PATCH v2 2/2] KEYS: asymmetric: Fix PKCS#1 decryption of an empty message Florian Bauckholt via B4 Relay
2026-11-18 23:25   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261119-keyctl-pkey-fixes-v2-1-9e2d1c7db7ec@cispa.de \
    --to=devnull+florian.bauckholt.cispa.de@kernel.org \
    --cc=benquike@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dhowells@redhat.com \
    --cc=florian.bauckholt@cispa.de \
    --cc=giometti@enneenne.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=ignat@linux.win \
    --cc=jarkko@kernel.org \
    --cc=jmorris@namei.org \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=paul@paul-moore.com \
    --cc=serge@hallyn.com \
    --cc=stable@vger.kernel.org \
    --cc=stefanb@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox