From: Jiangshan Yi <yijiangshan@kylinos.cn>
To: dhowells@redhat.com, lukas@wunner.de, ignat@linux.win,
herbert@gondor.apana.org.au, davem@davemloft.net
Cc: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org,
keyrings@vger.kernel.org, 13667453960@163.com,
Jiangshan Yi <yijiangshan@kylinos.cn>
Subject: [PATCH] crypto: verify_pefile - Use constant-time digest comparison
Date: Mon, 20 Jul 2026 11:18:15 +0800 [thread overview]
Message-ID: <20260720031815.204237-1-yijiangshan@kylinos.cn> (raw)
The PE file digest comparison in verify_pefile_signature() uses
memcmp(), whose execution time depends on the position of the first
mismatched byte. This creates a timing side-channel that could allow
an attacker to forge PE file signatures byte by byte.
Replace memcmp() with crypto_memneq() to perform a constant-time
comparison, consistent with the rest of the crypto subsystem
(gcm, ccm, chacha20poly1305, rsassa-pkcs1, krb5, etc.). Add an
explicit <crypto/utils.h> include since this file did not previously
pull in the crypto_memneq() declaration.
Signed-off-by: Jiangshan Yi <yijiangshan@kylinos.cn>
---
crypto/asymmetric_keys/verify_pefile.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/crypto/asymmetric_keys/verify_pefile.c b/crypto/asymmetric_keys/verify_pefile.c
index cec99db14129..dce40a2a3fac 100644
--- a/crypto/asymmetric_keys/verify_pefile.c
+++ b/crypto/asymmetric_keys/verify_pefile.c
@@ -14,6 +14,7 @@
#include <linux/asn1.h>
#include <linux/verification.h>
#include <crypto/hash.h>
+#include <crypto/utils.h>
#include "verify_pefile.h"
/*
@@ -374,7 +375,7 @@ static int pefile_digest_pe(const void *pebuf, unsigned int pelen,
/* Check that the PE file digest matches that in the MSCODE part of the
* PKCS#7 certificate.
*/
- if (memcmp(digest, ctx->digest, ctx->digest_len) != 0) {
+ if (crypto_memneq(digest, ctx->digest, ctx->digest_len)) {
pr_warn("Digest mismatch\n");
ret = -EKEYREJECTED;
} else {
--
2.25.1
reply other threads:[~2026-07-20 3:19 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260720031815.204237-1-yijiangshan@kylinos.cn \
--to=yijiangshan@kylinos.cn \
--cc=13667453960@163.com \
--cc=davem@davemloft.net \
--cc=dhowells@redhat.com \
--cc=herbert@gondor.apana.org.au \
--cc=ignat@linux.win \
--cc=keyrings@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lukas@wunner.de \
/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