mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dan Carpenter <dan@pereq.eu>
To: Andrew Morton <akpm@linux-foundation.org>,
	 Herbert Xu <herbert@gondor.apana.org.au>,
	 Nicolai Stange <nicstange@gmail.com>,
	Mimi Zohar <zohar@us.ibm.com>,
	 Dmitry Kasatkin <dmitry.kasatkin@intel.com>
Cc: "Karthik Bhargavan" <karthik@pereq.eu>,
	"Clément Blaudeau" <clement@cryspen.com>,
	linux-kernel@vger.kernel.org, "Dan Carpenter" <dan@pereq.eu>
Subject: [PATCH 2/3] lib/digsig: Reject a signature larger than the modulus
Date: Wed, 02 Dec 2026 15:20:29 +0300	[thread overview]
Message-ID: <20261202-digsig_send-v1-2-2797f094dac3@pereq.eu> (raw)
In-Reply-To: <20261202-digsig_send-v1-0-2797f094dac3@pereq.eu>

This is a correctness fix based on the RFC.  Currently,
digsig_verify_rsa() accepts a legacy IMA or EVM signature even if the
RSA modulus has been added to it.  That's a bug: it means one signature
could have several different encodings that verify.

RSA verification (RSAVP1 in RFC 8017 section 5.2.2) starts by checking
that the signature s is less than the modulus n.  digsig_verify_rsa()
skips that check and computes s^e mod n directly, so s, s + n, s + 2n
and so on all give the same result.  No signature is forged, but a
different value is accepted for the same file.  The kernel's other RSA
code rejects s >= n in rsa_check_payload().

Reject a signature that is greater than or equal to the modulus.

In real life signatures made by evmctl are always less than n because
RSA_private_encrypt() returns m^d mod n.  So it means no one is affected
by this bug in practice but also fixing it has no risk of breaking
anything.

Fixes: 051dbb918c7f ("crypto: digital signature verification support")
Signed-off-by: Dan Carpenter <dan@pereq.eu>
---
 lib/digsig.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lib/digsig.c b/lib/digsig.c
index 8ca6af0a8fd4..4940ce755750 100644
--- a/lib/digsig.c
+++ b/lib/digsig.c
@@ -135,6 +135,11 @@ static int digsig_verify_rsa(struct key *key,
 		goto err;
 	}
 
+	if (mpi_cmp(in, pkey[0]) >= 0) {
+		err = -EINVAL;
+		goto err;
+	}
+
 	res = mpi_alloc(mpi_get_nlimbs(in) * 2);
 	if (!res)
 		goto err;

-- 
2.53.0


  parent reply	other threads:[~2026-12-02 12:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 12:20 [PATCH 0/3] lib/digsig: fix some bugs in digsig Dan Carpenter
2026-12-02 12:20 ` [PATCH 1/3] lib/digsig: Fix error pointer dereference in digsig_verify_rsa() Dan Carpenter
2026-12-02 12:20 ` Dan Carpenter [this message]
2026-12-02 12:20 ` [PATCH 3/3] lib/digsig: Reject garbage bytes after the signature Dan Carpenter

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=20261202-digsig_send-v1-2-2797f094dac3@pereq.eu \
    --to=dan@pereq.eu \
    --cc=akpm@linux-foundation.org \
    --cc=clement@cryspen.com \
    --cc=dmitry.kasatkin@intel.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=karthik@pereq.eu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nicstange@gmail.com \
    --cc=zohar@us.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

all inboxes | Powered by JetHome®