Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp637305pxb; Tue, 5 Apr 2022 16:50:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRB3jpzXQNccEwKdDXrqBGoUg6INheNIcNsQM/ouppa+mpPEWDQHv8cIOVyrbEHLpfQhTA X-Received: by 2002:a17:902:ef50:b0:156:486f:b593 with SMTP id e16-20020a170902ef5000b00156486fb593mr5798259plx.104.1649202631063; Tue, 05 Apr 2022 16:50:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649202631; cv=none; d=google.com; s=arc-20160816; b=mViRdeT647V92oaS5yvU9PO5YAccctaIOvKhpVmlRRuIqRpedQiBauqPk/NqBUcO1R ZSZtU0J18YoKFVGPiaYJiVSR8lQSvYQrE8rbKL/VyIv39cXRO/d8rOAcjFuahu42249f I8QqurwFv/40mg2r67tZeBrLkBqr3ZZpJpRenn1zTkQWuzE4LRTppS6QLDeDT1Ve9vT9 3lFLzoqCqbo3/Is2huOPJFFfCOojLKcl/M++g77hDUN1Dl5pRCnI4Z1e9x7xQH7P7qWl vQ9CKXua/VfYjuQ/PtKDfGo4NZuwPoZ3TgotO7IDztf3qwaMF8csfRdEypmanw8h0mdC ag8A== 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=Uly24Jg6aYHAF+0dVc2bvye/3gb4d4KxhCTj/MEKDp0=; b=M2PvvzCTEkJBQZQarNFcdknDpSaAQvu8Ph8GZHGyKRM1XsHrxwdkx22UxXyYbAgW/v vyO2hX68JecLU0aYbce+91GA4zqm1QWTi+NCBwVjdXLVfRq+kRgN8WUEv2HRdr7U9RL+ s1Rjq7Tl5diEylyMBcwP98eUglgpc+X3RJHmbKthr2wT8jaOCcA6eLu8Fn4StN+TWqYm R41CWdFJIc+2zHBnPr7hWstjdYVsifjGxmQ2krbZbvvVi3SuW8t9p5QdeNphSyXPI36Q Q12dpmtxLSxjOMFQPKjUlyy5WeTNEwCng8UN+eCUHIDLnB6fxP8AHyvbJoQGI+9lMz1j EuGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=asGlX5E3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id k184-20020a636fc1000000b003816043f10asi14684019pgc.767.2022.04.05.16.50.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 16:50:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=asGlX5E3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B9682133DB8; Tue, 5 Apr 2022 16:34:52 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377159AbiDEL2B (ORCPT + 99 others); Tue, 5 Apr 2022 07:28:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243285AbiDEIuT (ORCPT ); Tue, 5 Apr 2022 04:50:19 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C90C12AF2; Tue, 5 Apr 2022 01:38:38 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 267C061500; Tue, 5 Apr 2022 08:38:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F80CC385A1; Tue, 5 Apr 2022 08:38:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649147911; bh=wxo5Qgm4ML6MQghSIyIPjrQXgvNxgJgLaqb67pNgPhk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=asGlX5E3gcurU0uTdjDN+GMNKXlfzFTkyDvvmhGdYlr3dmi725HpCmUCrtRv8+sER vxQ9j7FrjBuYjiwU5hVjb8ffzSWK8gvi3gB/4yh9FvyDbPtc6E5LrU2aiYlwWptJVr eQgn2o0L37EigUYBLkxUv29BRwdTeV21biqpsKBQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tadeusz Struk , Vitaly Chikunov , Eric Biggers , Herbert Xu Subject: [PATCH 5.16 0167/1017] crypto: rsa-pkcs1pad - restore signature length check Date: Tue, 5 Apr 2022 09:18:00 +0200 Message-Id: <20220405070359.181100856@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 d3481accd974541e6a5d6a1fb588924a3519c36e 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 a49de377e051 ("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 c7381b012872 ("crypto: akcipher - new verify API for public key algorithms"). Fixes: a49de377e051 ("crypto: Add hash param to pkcs1pad") Cc: # v4.6+ Cc: Tadeusz Struk Suggested-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 @@ -538,7 +538,7 @@ static int pkcs1pad_verify(struct akciph if (WARN_ON(req->dst) || 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; req_ctx->out_buf = kmalloc(ctx->key_size + req->dst_len, GFP_KERNEL);