Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp685093pxb; Tue, 5 Apr 2022 18:43:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4f1fgCqJ48z2RoXABWYLUaRrRPYIcvRgsawe0wa8gWYbC3GZQCwOAYVIa+rYyU7gVLmnY X-Received: by 2002:a17:907:8693:b0:6e7:f5f4:c4d5 with SMTP id qa19-20020a170907869300b006e7f5f4c4d5mr5884545ejc.640.1649209390950; Tue, 05 Apr 2022 18:43:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649209390; cv=none; d=google.com; s=arc-20160816; b=oV7Im5tSAWJ6inhgC2kv1NSYwtRRms6/X9xgfQmonsH7kC2v6fuiizGhTYNfEo0NON /ScCimjXJN0Zr94nfaQPvUiUjxvI6VAyNEERMAIC2yWHIdhEysttRTgO1L27oV+aOH+M 1Bci5YswK21e/e66/INB1yW8edhl6SGP/ofJIuL88qiajy5li/0KXz1TSj10xEthNOOn W+28tc/HB9GvgDvsjLH8/7uJgMen//F3NCj8aPNLZnrGhUrZfBXAoI7zzf6e9NMKjRUZ FozQrc8Q0HeP+Z6+eZ9Sqgyp3leiyp6z9WP8NivL4nKU08fFukSeA46AoI+heWwbM2Oh Fwgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NXQ8kYaoWPj1mJo00s5AmGngIsqbCYaAoGdCmw48Nxc=; b=RozcwNO1LSdo3KDS0EB6CZsUua6RwzZ6V8HODYxQWWr6RmxN2e/TXZbt8165jOS3JX 3ArDmacxxSGT/dBNDKACTpzStYJIJsBNBThM34bO5597k2ZOTTwDasq1YpyP1zKb8fys z/xyBX4ykXSVSPkJiYE+Im1SLH1UBT0+TKZxcHwMF4IPSXaMcxyrnPdRRg4bHnJpF7rj 2Ko5f1XiB0EtaOdoshWNU2wyeHAVunSxVvFECdc0A+ksq4QQUR3Sn5uXOCKj41dip9s3 uyGyTTCyWdGcAWyoddW87Ep+JdXyAlO3yodXMkEUUKRFio42pJPzrNYK7d4WC2/l05AT dHxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cq2KvACs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y4-20020aa7ccc4000000b0041ba70d1386si10120782edt.532.2022.04.05.18.42.43; Tue, 05 Apr 2022 18:43:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cq2KvACs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353205AbiDEOmM (ORCPT + 99 others); Tue, 5 Apr 2022 10:42:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244183AbiDEJlJ (ORCPT ); Tue, 5 Apr 2022 05:41:09 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 741FCBB080; Tue, 5 Apr 2022 02:25:30 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 28231B81C9A; Tue, 5 Apr 2022 09:25:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8961CC385A0; Tue, 5 Apr 2022 09:25:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649150727; bh=jLJHdncUYIgkXzg4FNI//hgrXP1ygYahSZ/ZDNplSPI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cq2KvACsRiAWTPEjUJxMlOZpciRJEGml+cHSJZUZzSxNE7uDZAsOyXtCV2zJ9eZFN jQJObPOcOe0jqDZMl9aLRcjZaunTkGqu8KhLsRWPWzVW/mX9WpYcNF2tLeU4oc0pPS AYNks00TekPJhrZvZf9hzfrhk9VT95IYgPddq6Iw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vitaly Chikunov , Eric Biggers , Herbert Xu Subject: [PATCH 5.15 158/913] crypto: rsa-pkcs1pad - correctly get hash from source scatterlist Date: Tue, 5 Apr 2022 09:20:20 +0200 Message-Id: <20220405070344.576892112@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Biggers commit e316f7179be22912281ce6331d96d7c121fb2b17 upstream. Commit c7381b012872 ("crypto: akcipher - new verify API for public key algorithms") changed akcipher_alg::verify to take in both the signature and the actual hash and do the signature verification, rather than just return the hash expected by the signature as was the case before. To do this, it implemented a hack where the signature and hash are concatenated with each other in one scatterlist. Obviously, for this to work correctly, akcipher_alg::verify needs to correctly extract the two items from the scatterlist it is given. Unfortunately, it doesn't correctly extract the hash in the case where the signature is longer than the RSA key size, as it assumes that the signature's length is equal to the RSA key size. This causes a prefix of the hash, or even the entire hash, to be taken from the *signature*. (Note, the case of a signature longer than the RSA key size should not be allowed in the first place; a separate patch will fix that.) It is unclear whether the resulting scheme has any useful security properties. Fix this by correctly extracting the hash from the scatterlist. Fixes: c7381b012872 ("crypto: akcipher - new verify API for public key algorithms") Cc: # v5.2+ Reviewed-by: Vitaly Chikunov Signed-off-by: Eric Biggers Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- crypto/rsa-pkcs1pad.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/crypto/rsa-pkcs1pad.c +++ b/crypto/rsa-pkcs1pad.c @@ -495,7 +495,7 @@ static int pkcs1pad_verify_complete(stru sg_nents_for_len(req->src, req->src_len + req->dst_len), req_ctx->out_buf + ctx->key_size, - req->dst_len, ctx->key_size); + req->dst_len, req->src_len); /* Do the actual verification step. */ if (memcmp(req_ctx->out_buf + ctx->key_size, out_buf + pos, req->dst_len) != 0)