diff mbox series

[v2,4/5] crypto: rsa-pkcs1pad - fix buffer overread in pkcs1pad_verify_complete()

Message ID 20220119001306.85355-5-ebiggers@kernel.org (mailing list archive)
State New
Headers show
Series crypto: rsa-pkcs1pad fixes | expand

Commit Message

Eric Biggers Jan. 19, 2022, 12:13 a.m. UTC
From: Eric Biggers <ebiggers@google.com>

Before checking whether the expected digest_info is present, we need to
check that there are enough bytes remaining.

Fixes: a49de377e051 ("crypto: Add hash param to pkcs1pad")
Cc: <stable@vger.kernel.org> # v4.6+
Cc: Tadeusz Struk <tadeusz.struk@linaro.org>
Signed-off-by: Eric Biggers <ebiggers@google.com>
 crypto/rsa-pkcs1pad.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox series


diff --git a/crypto/rsa-pkcs1pad.c b/crypto/rsa-pkcs1pad.c
index 6b556ddeb3a00..9d804831c8b3f 100644
--- a/crypto/rsa-pkcs1pad.c
+++ b/crypto/rsa-pkcs1pad.c
@@ -476,6 +476,8 @@  static int pkcs1pad_verify_complete(struct akcipher_request *req, int err)
 	if (digest_info) {
+		if (digest_info->size > dst_len - pos)
+			goto done;
 		if (crypto_memneq(out_buf + pos, digest_info->data,
 			goto done;