* [PATCH 0/3] lib/digsig: fix some bugs in digsig
@ 2026-12-02 12:20 Dan Carpenter
2026-12-02 12:20 ` [PATCH 1/3] lib/digsig: Fix error pointer dereference in digsig_verify_rsa() Dan Carpenter
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Dan Carpenter @ 2026-12-02 12:20 UTC (permalink / raw)
To: Andrew Morton, Herbert Xu, Nicolai Stange, Mimi Zohar, Dmitry Kasatkin
Cc: Karthik Bhargavan, Clément Blaudeau, linux-kernel,
Dan Carpenter, stable
Pereq is doing formal verification work. These are some bugs we found.
* Dereferencing an error pointer on the error path
* Not implementing the RFC correctly
* Allowing garbage bytes after a signature
Fixing the last two bugs is just about correctness and they don't
actually affect real life.
Signed-off-by: Dan Carpenter <dan@pereq.eu>
---
Dan Carpenter (3):
lib/digsig: Fix error pointer dereference in digsig_verify_rsa()
lib/digsig: Reject a signature larger than the modulus
lib/digsig: Reject garbage bytes after the signature
lib/digsig.c | 11 +++++++++++
1 file changed, 11 insertions(+)
---
base-commit: a9c48428cbd8d96b26f92631d0db6f8519c5fcc5
change-id: 20261202-digsig_send-1d579b20c1d2
Best regards,
--
Dan Carpenter <dan@pereq.eu>
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH 1/3] lib/digsig: Fix error pointer dereference in digsig_verify_rsa()
2026-12-02 12:20 [PATCH 0/3] lib/digsig: fix some bugs in digsig Dan Carpenter
@ 2026-12-02 12:20 ` Dan Carpenter
2026-12-02 12:20 ` [PATCH 2/3] lib/digsig: Reject a signature larger than the modulus Dan Carpenter
2026-12-02 12:20 ` [PATCH 3/3] lib/digsig: Reject garbage bytes after the signature Dan Carpenter
2 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2026-12-02 12:20 UTC (permalink / raw)
To: Andrew Morton, Herbert Xu, Nicolai Stange, Mimi Zohar, Dmitry Kasatkin
Cc: Karthik Bhargavan, Clément Blaudeau, linux-kernel,
Dan Carpenter, stable
This error path calls mpi_free() with an error pointer which will
crash. Set the "in" pointer to a NULL instead.
Fixes: 03cdfaad491e ("lib/mpi: mpi_read_from_buffer(): return error code")
Cc: stable@vger.kernel.org
Signed-off-by: Dan Carpenter <dan@pereq.eu>
---
lib/digsig.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/lib/digsig.c b/lib/digsig.c
index 9dd319c12c7d..8ca6af0a8fd4 100644
--- a/lib/digsig.c
+++ b/lib/digsig.c
@@ -131,6 +131,7 @@ static int digsig_verify_rsa(struct key *key,
in = mpi_read_from_buffer(sig, &nret);
if (IS_ERR(in)) {
err = PTR_ERR(in);
+ in = NULL;
goto err;
}
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH 2/3] lib/digsig: Reject a signature larger than the modulus
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
2026-12-02 12:20 ` [PATCH 3/3] lib/digsig: Reject garbage bytes after the signature Dan Carpenter
2 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2026-12-02 12:20 UTC (permalink / raw)
To: Andrew Morton, Herbert Xu, Nicolai Stange, Mimi Zohar, Dmitry Kasatkin
Cc: Karthik Bhargavan, Clément Blaudeau, linux-kernel, Dan Carpenter
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
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH 3/3] lib/digsig: Reject garbage bytes after the signature
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 ` [PATCH 2/3] lib/digsig: Reject a signature larger than the modulus Dan Carpenter
@ 2026-12-02 12:20 ` Dan Carpenter
2 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2026-12-02 12:20 UTC (permalink / raw)
To: Andrew Morton, Herbert Xu, Nicolai Stange, Mimi Zohar, Dmitry Kasatkin
Cc: Karthik Bhargavan, Clément Blaudeau, linux-kernel, Dan Carpenter
The digsig_verify_rsa() function accepts signatures with garbage after
the end. Reject signatures that aren't the correct length.
evmctl writes the header, the bit count and the RSA output and
nothing else, so no one is affected by this in real life. It's just a
correctness issue.
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 4940ce755750..18683e774bbd 100644
--- a/lib/digsig.c
+++ b/lib/digsig.c
@@ -135,6 +135,11 @@ static int digsig_verify_rsa(struct key *key,
goto err;
}
+ if (nret != siglen) {
+ err = -EINVAL;
+ goto err;
+ }
+
if (mpi_cmp(in, pkey[0]) >= 0) {
err = -EINVAL;
goto err;
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-02 12:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 2/3] lib/digsig: Reject a signature larger than the modulus Dan Carpenter
2026-12-02 12:20 ` [PATCH 3/3] lib/digsig: Reject garbage bytes after the signature Dan Carpenter
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®