Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp3585715pxb; Mon, 21 Feb 2022 01:04:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJyREYioSu+SylDOciQCLu50dZnyVDR8rSAt8uI/W33z861+dv0BSWGqGUAPaAn4UFoLIOTD X-Received: by 2002:a17:902:f649:b0:14d:846f:e7da with SMTP id m9-20020a170902f64900b0014d846fe7damr18407738plg.133.1645434276013; Mon, 21 Feb 2022 01:04:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645434276; cv=none; d=google.com; s=arc-20160816; b=e4Dh1foJHIhSXNTGKVgBFXVQcIZ62kSC832bAUYz8PRDzsTKGurW9sVp7fWMNBNFdD Pn+LF1u8WAM6VfQchDLWvCFJ98+5+kDIciENCoVtK6TqzGqQeuZdcOBoOU824xGy3xFE 9KrYTCL15gZtilSw7ceBi1kzINjqSF3pyOsimZ43COdCJG64ieCOl3C8Zo1DWLDE8WOf ZdhMdqT/1FNA3LOyKfTQ1h5F0uEhojvm6QwXduh506ekFTIivcwdDzPW9knMKalBWZOJ ZgvZwISKnGYmo1GrNxQ6cCGFnZXuMoBkIdTe7ZJjZkctaP0/4tyVtP/9UpXYlPjCtu1g yZOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=U/98q1q8+EsUksC5rrw6Te7fwBJym+iVAlDIEpmp9j0=; b=bTqWtSkpZKVxSf51q4y45sNLRNAXys59Q/Zpff3hBmEuUjN/D2VAkC7yK4X1sSRtu1 9aqK/s/nEcjs/uC0YAogbqXIcU8uXTXyptQuTLteEyRdL4F6beSMQw9jrK5DS18+11Wq UxgQRAOJBfNSwp11zhq9ya/BYZbSlqEL9jVEsBEB+PU6kTolBIRrlNHudjK7ZcEzyRs9 gYC/W6tJoWXothPWNBVSIMb5DBR+mHHrPJIA2PR/hLMkHiBtLf7U45dHRkWxlXsmVg82 /PfISiCqrzHuil/P8nXUPMdR7qVfZMSwHtzr+gqGr0evN0Ixxhfk8UaP10kczKPqwlmC gsLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Qkme+nn2; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o16si20736968pgu.129.2022.02.21.01.04.22; Mon, 21 Feb 2022 01:04:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-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=@kernel.org header.s=k20201202 header.b=Qkme+nn2; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343543AbiBUCWD (ORCPT + 99 others); Sun, 20 Feb 2022 21:22:03 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:40780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343540AbiBUCWC (ORCPT ); Sun, 20 Feb 2022 21:22:02 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A14B7658B; Sun, 20 Feb 2022 18:21:39 -0800 (PST) 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 28B2561055; Mon, 21 Feb 2022 02:21:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 357A5C340E8; Mon, 21 Feb 2022 02:21:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645410098; bh=kGIeWEaq/5UzKoe9nNUsyzDA3N0lfQIYAcHCE2Et33Y=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Qkme+nn2X2Y4RINHEWEoRSLt9y7wLpMTzVJejfvOaJsNfUcZy6SNfwy+gVGdLvM3C k0Tv6KaOkEJhYoNHIqHJAar6Otdb+52kzKIp5Brx55DVYYbuT2bQgl/wF6ZQU7ByHW DEJUAYQnrzoKofyw6fZcU6K0tGQDOaiEv2/DB5xMvZjV0pD2s2Yi5ih8SlLP56dug6 mH/yWxyaFALXHOxOEr5z/EkZdoB2vFa4nRcaEkPTMJXyqKzaI9I1a3Rzybv0KejXC5 tTSAe7GUpzZT4q1y8BgjNl9T4AZ7U+3+jvA/mEIBBFfojlVS9z6CgWbjUj04SBwsMR gZTmVTuv7YUuw== Date: Sun, 20 Feb 2022 18:21:36 -0800 From: Eric Biggers To: Jarkko Sakkinen Cc: keyrings@vger.kernel.org, David Howells , linux-crypto@vger.kernel.org, linux-integrity@vger.kernel.org, Stefan Berger , Gilad Ben-Yossef , Tianjia Zhang , Vitaly Chikunov , Mimi Zohar , stable@vger.kernel.org Subject: Re: [PATCH 2/2] KEYS: asymmetric: properly validate hash_algo and encoding Message-ID: References: <20220201003414.55380-1-ebiggers@kernel.org> <20220201003414.55380-3-ebiggers@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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-crypto@vger.kernel.org On Mon, Feb 21, 2022 at 02:46:26AM +0100, Jarkko Sakkinen wrote: > On Mon, Jan 31, 2022 at 04:34:14PM -0800, Eric Biggers wrote: > > From: Eric Biggers > > > > It is insecure to allow arbitrary hash algorithms and signature > > encodings to be used with arbitrary signature algorithms. Notably, > > ECDSA, ECRDSA, and SM2 all sign/verify raw hash values and don't > > disambiguate between different hash algorithms like RSA PKCS#1 v1.5 > > padding does. Therefore, they need to be restricted to certain sets of > > hash algorithms (ideally just one, but in practice small sets are used). > > Additionally, the encoding is an integral part of modern signature > > algorithms, and is not supposed to vary. > > > > Therefore, tighten the checks of hash_algo and encoding done by > > software_key_determine_akcipher(). > > > > Also rearrange the parameters to software_key_determine_akcipher() to > > put the public_key first, as this is the most important parameter and it > > often determines everything else. > > > > Fixes: 299f561a6693 ("x509: Add support for parsing x509 certs with ECDSA keys") > > Fixes: 215525639631 ("X.509: support OSCCA SM2-with-SM3 certificate verification") > > Fixes: 0d7a78643f69 ("crypto: ecrdsa - add EC-RDSA (GOST 34.10) algorithm") > > Cc: stable@vger.kernel.org > > Signed-off-by: Eric Biggers > > --- > > crypto/asymmetric_keys/public_key.c | 111 +++++++++++++++++++--------- > > 1 file changed, 76 insertions(+), 35 deletions(-) > > > > diff --git a/crypto/asymmetric_keys/public_key.c b/crypto/asymmetric_keys/public_key.c > > index aba7113d86c76..a603ee8afdb8d 100644 > > --- a/crypto/asymmetric_keys/public_key.c > > +++ b/crypto/asymmetric_keys/public_key.c > > @@ -60,39 +60,83 @@ static void public_key_destroy(void *payload0, void *payload3) > > } > > > > /* > > - * Determine the crypto algorithm name. > > + * Given a public_key, and an encoding and hash_algo to be used for signing > > + * and/or verification with that key, determine the name of the corresponding > > + * akcipher algorithm. Also check that encoding and hash_algo are allowed. > > */ > > -static > > -int software_key_determine_akcipher(const char *encoding, > > - const char *hash_algo, > > - const struct public_key *pkey, > > - char alg_name[CRYPTO_MAX_ALG_NAME]) > > +static int > > +software_key_determine_akcipher(const struct public_key *pkey, > > + const char *encoding, const char *hash_algo, > > + char alg_name[CRYPTO_MAX_ALG_NAME]) > > Why is changing parameter order necessary? > It's mentioned in the commit message. It's obviously not necessary but this way makes much more sense IMO. - Eric