提交 ae0913fa 编写于 作者: E Eric Biggers 提交者: Zheng Zengkai

crypto: rsa-pkcs1pad - restore signature length check

stable inclusion
from stable-v5.10.110
commit b89fb8b8824222c0568ad03e02c612df0746959e
bugzilla: https://gitee.com/openeuler/kernel/issues/I574AL

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=b89fb8b8824222c0568ad03e02c612df0746959e

--------------------------------

commit d3481acc upstream.

RSA PKCS#1 v1.5 signatures are required to be the same length as the RSA
key size.  RFC8017 specifically requires the verifier to check this
(https://datatracker.ietf.org/doc/html/rfc8017#section-8.2.2).

Commit a49de377 ("crypto: Add hash param to pkcs1pad") changed the
kernel to allow longer signatures, but didn't explain this part of the
change; it seems to be unrelated to the rest of the commit.

Revert this change, since it doesn't appear to be correct.

We can be pretty sure that no one is relying on overly-long signatures
(which would have to be front-padded with zeroes) being supported, given
that they would have been broken since commit c7381b01
("crypto: akcipher - new verify API for public key algorithms").

Fixes: a49de377 ("crypto: Add hash param to pkcs1pad")
Cc: <stable@vger.kernel.org> # v4.6+
Cc: Tadeusz Struk <tadeusz.struk@linaro.org>
Suggested-by: NVitaly Chikunov <vt@altlinux.org>
Signed-off-by: NEric Biggers <ebiggers@google.com>
Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NYu Liao <liaoyu15@huawei.com>
Reviewed-by: NWei Li <liwei391@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 8e066e4d
...@@ -538,7 +538,7 @@ static int pkcs1pad_verify(struct akcipher_request *req) ...@@ -538,7 +538,7 @@ static int pkcs1pad_verify(struct akcipher_request *req)
if (WARN_ON(req->dst) || if (WARN_ON(req->dst) ||
WARN_ON(!req->dst_len) || WARN_ON(!req->dst_len) ||
!ctx->key_size || req->src_len < ctx->key_size) !ctx->key_size || req->src_len != ctx->key_size)
return -EINVAL; return -EINVAL;
req_ctx->out_buf = kmalloc(ctx->key_size + req->dst_len, GFP_KERNEL); req_ctx->out_buf = kmalloc(ctx->key_size + req->dst_len, GFP_KERNEL);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册