* [PATCH] crypto: rsassa-pkcs1: use constant-time comparison for digest and signature verification @ 2026-07-10 17:29 David C.C.M. Gall 2026-07-10 21:37 ` Eric Biggers 0 siblings, 1 reply; 6+ messages in thread From: David C.C.M. Gall @ 2026-07-10 17:29 UTC (permalink / raw) To: Lukas Wunner, Ignat Korchagin, Herbert Xu, David S. Miller, linux-crypto, linux-kernel Cc: gregkh Replace memcmp() with crypto_memneq() for cryptographic digest and signature comparisons to prevent timing side-channel attacks. crypto/rsassa-pkcs1.c: RSA signature digest verification used memcmp which can leak valid prefix length via timing analysis, user data could reach the leaky comparison via the digest argument to verify. Assisted-by: gregkh_clanker_t1000 Signed-off-by: David C.C.M. Gall <david.ccm.gall@googlemail.com> --- crypto/rsassa-pkcs1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto/rsassa-pkcs1.c b/crypto/rsassa-pkcs1.c index 94fa5e9600e7..a612a9eef2dd 100644 --- a/crypto/rsassa-pkcs1.c +++ b/crypto/rsassa-pkcs1.c @@ -291,7 +291,7 @@ static int rsassa_pkcs1_verify(struct crypto_sig *tfm, /* RFC 8017 sec 8.2.2 step 4 - comparison of digest with out_buf */ if (dlen != dst_len - pos) return -EKEYREJECTED; - if (memcmp(digest, out_buf + pos, dlen) != 0) + if (crypto_memneq(digest, out_buf + pos, dlen)) return -EKEYREJECTED; return 0; -- 2.43.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] crypto: rsassa-pkcs1: use constant-time comparison for digest and signature verification 2026-07-10 17:29 [PATCH] crypto: rsassa-pkcs1: use constant-time comparison for digest and signature verification David C.C.M. Gall @ 2026-07-10 21:37 ` Eric Biggers 2026-07-11 5:19 ` Greg KH 0 siblings, 1 reply; 6+ messages in thread From: Eric Biggers @ 2026-07-10 21:37 UTC (permalink / raw) To: David C.C.M. Gall Cc: Lukas Wunner, Ignat Korchagin, Herbert Xu, David S. Miller, linux-crypto, linux-kernel, gregkh On Fri, Jul 10, 2026 at 07:29:33PM +0200, David C.C.M. Gall wrote: > Replace memcmp() with crypto_memneq() for cryptographic digest and > signature comparisons to prevent timing side-channel attacks. > > crypto/rsassa-pkcs1.c: RSA signature digest verification used memcmp > which can leak valid prefix length via timing analysis, user data > could reach the leaky comparison via the digest argument to verify. > > Assisted-by: gregkh_clanker_t1000 > Signed-off-by: David C.C.M. Gall <david.ccm.gall@googlemail.com> While we should use crypto_memneq() on MACs, auth tags, and other secret data, I don't think we should let it creep into domains where it is clearly not needed, like public key signature verification. - Eric ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] crypto: rsassa-pkcs1: use constant-time comparison for digest and signature verification 2026-07-10 21:37 ` Eric Biggers @ 2026-07-11 5:19 ` Greg KH 2026-07-11 8:00 ` Ignat Korchagin 0 siblings, 1 reply; 6+ messages in thread From: Greg KH @ 2026-07-11 5:19 UTC (permalink / raw) To: Eric Biggers Cc: David C.C.M. Gall, Lukas Wunner, Ignat Korchagin, Herbert Xu, David S. Miller, linux-crypto, linux-kernel On Fri, Jul 10, 2026 at 05:37:18PM -0400, Eric Biggers wrote: > On Fri, Jul 10, 2026 at 07:29:33PM +0200, David C.C.M. Gall wrote: > > Replace memcmp() with crypto_memneq() for cryptographic digest and > > signature comparisons to prevent timing side-channel attacks. > > > > crypto/rsassa-pkcs1.c: RSA signature digest verification used memcmp > > which can leak valid prefix length via timing analysis, user data > > could reach the leaky comparison via the digest argument to verify. > > > > Assisted-by: gregkh_clanker_t1000 > > Signed-off-by: David C.C.M. Gall <david.ccm.gall@googlemail.com> > > While we should use crypto_memneq() on MACs, auth tags, and other secret > data, I don't think we should let it creep into domains where it is > clearly not needed, like public key signature verification. But isn't this user-controlled data and so a user could use it to figure out the key? thanks, greg k-h ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] crypto: rsassa-pkcs1: use constant-time comparison for digest and signature verification 2026-07-11 5:19 ` Greg KH @ 2026-07-11 8:00 ` Ignat Korchagin 2026-07-11 11:23 ` David Gall 0 siblings, 1 reply; 6+ messages in thread From: Ignat Korchagin @ 2026-07-11 8:00 UTC (permalink / raw) To: Greg KH Cc: Eric Biggers, David C.C.M. Gall, Lukas Wunner, Herbert Xu, David S. Miller, linux-crypto, linux-kernel On Sat, Jul 11, 2026 at 6:19 AM Greg KH <gregkh@linuxfoundation.org> wrote: > > On Fri, Jul 10, 2026 at 05:37:18PM -0400, Eric Biggers wrote: > > On Fri, Jul 10, 2026 at 07:29:33PM +0200, David C.C.M. Gall wrote: > > > Replace memcmp() with crypto_memneq() for cryptographic digest and > > > signature comparisons to prevent timing side-channel attacks. > > > > > > crypto/rsassa-pkcs1.c: RSA signature digest verification used memcmp > > > which can leak valid prefix length via timing analysis, user data > > > could reach the leaky comparison via the digest argument to verify. > > > > > > Assisted-by: gregkh_clanker_t1000 > > > Signed-off-by: David C.C.M. Gall <david.ccm.gall@googlemail.com> > > > > While we should use crypto_memneq() on MACs, auth tags, and other secret > > data, I don't think we should let it creep into domains where it is > > clearly not needed, like public key signature verification. > > But isn't this user-controlled data and so a user could use it to figure > out the key? This is signature verification with a public key. So the user knows the key already. > thanks, > > greg k-h > Ignat ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] crypto: rsassa-pkcs1: use constant-time comparison for digest and signature verification 2026-07-11 8:00 ` Ignat Korchagin @ 2026-07-11 11:23 ` David Gall 2026-07-11 15:17 ` Lukas Wunner 0 siblings, 1 reply; 6+ messages in thread From: David Gall @ 2026-07-11 11:23 UTC (permalink / raw) To: Ignat Korchagin Cc: Greg KH, Eric Biggers, Lukas Wunner, Herbert Xu, David S. Miller, linux-crypto, linux-kernel On Sat, Jul 11, 2026 at 09:00:23AM +0100, Ignat Korchagin wrote: > On Sat, Jul 11, 2026 at 6:19 AM Greg KH <gregkh@linuxfoundation.org> wrote: > > > > On Fri, Jul 10, 2026 at 05:37:18PM -0400, Eric Biggers wrote: > > > On Fri, Jul 10, 2026 at 07:29:33PM +0200, David C.C.M. Gall wrote: > > > > Replace memcmp() with crypto_memneq() for cryptographic digest and > > > > signature comparisons to prevent timing side-channel attacks. > > > > > > > > crypto/rsassa-pkcs1.c: RSA signature digest verification used memcmp > > > > which can leak valid prefix length via timing analysis, user data > > > > could reach the leaky comparison via the digest argument to verify. > > > > > > > > Assisted-by: gregkh_clanker_t1000 > > > > Signed-off-by: David C.C.M. Gall <david.ccm.gall@googlemail.com> > > > > > > While we should use crypto_memneq() on MACs, auth tags, and other secret > > > data, I don't think we should let it creep into domains where it is > > > clearly not needed, like public key signature verification. > > > > But isn't this user-controlled data and so a user could use it to figure > > out the key? > > This is signature verification with a public key. So the user knows > the key already. > > > thanks, > > > > greg k-h > > > > Ignat Nevermind, my reasoning on how this method is used was faulty. The crypto_memneq call does not protect against digest forgery, the public key is already available to anyone attempting verification, so an attacker can compute the padding/digest offline without needing the kernel's comparison at all, timing or otherwise. That said, this function already uses crypto_memneq for the hash-prefix check a few lines above. I'd argue for consistency it's worth using it for the digest comparison too. David ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] crypto: rsassa-pkcs1: use constant-time comparison for digest and signature verification 2026-07-11 11:23 ` David Gall @ 2026-07-11 15:17 ` Lukas Wunner 0 siblings, 0 replies; 6+ messages in thread From: Lukas Wunner @ 2026-07-11 15:17 UTC (permalink / raw) To: David Gall Cc: Ignat Korchagin, Greg KH, Eric Biggers, Herbert Xu, David S. Miller, linux-crypto, linux-kernel On Sat, Jul 11, 2026 at 01:23:36PM +0200, David Gall wrote: > That said, this function [rsassa_pkcs1_verify()] already uses > crypto_memneq() for the hash-prefix check a few lines above. > I'd argue for consistency it's worth using it for the digest > comparison too. I'd prefer the other way round, i.e. to use memcmp() for the hash_prefix comparison. Thanks, Lukas ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-07-11 15:17 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-07-10 17:29 [PATCH] crypto: rsassa-pkcs1: use constant-time comparison for digest and signature verification David C.C.M. Gall 2026-07-10 21:37 ` Eric Biggers 2026-07-11 5:19 ` Greg KH 2026-07-11 8:00 ` Ignat Korchagin 2026-07-11 11:23 ` David Gall 2026-07-11 15:17 ` Lukas Wunner
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox