Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4408345pxb; Mon, 21 Feb 2022 20:37:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJwAimVGwdaamrDLtc+8V/4Fb+dZgFG0mAlieq+QWdU4gtnui+T61hCaXhIf8WrEa2e4YBE+ X-Received: by 2002:a17:90a:550e:b0:1bc:6b9d:f325 with SMTP id b14-20020a17090a550e00b001bc6b9df325mr2190962pji.242.1645504646389; Mon, 21 Feb 2022 20:37:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645504646; cv=none; d=google.com; s=arc-20160816; b=qzlDh9At2lCvJFF7MEHH1gkExUYKIV5lBFJ//wSjsrhoE1QmP09oMY0MR9VsPegxIe y9kh5fiPEaf6OX6Zz59oJ6IMyL23nTS+TBmBNNAc7C+ZkhRJGB+v7SFmaCNQQej8YUbw axV137Vh1l3kaiVu1M8xYEF8kng0OXXSQ1+2ILLTisxNXNqHKyyppt2i3GZDC9gzteT2 3U1iyeu9VGx9/iAA1Xiarzj2LZbhDp4OPjKoU2yVkYBWzCHmVXxj0qit4O1maF4xDUnD 0uK3+w8g1Hdq+0+USnl2PMRTTitgzpcOUTM+8oixj9NQeXZtc+fsUtg7ECryl7+b0Wqs 8gjg== 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=19Rc7R9raB0o0b+tgCxPTcC9dlBruFc5buEUhXWOF9I=; b=DI/bN5HTCxsZrTiThwpBzydYwrze+A/uGLJTXco1yU9wsoBu/acXZBE5iEwHsCAJCu y7Yl83OKIQtgJpwZG4KshJB3paI3d1+zeDMWb5WYQaK3GXR4saCYtuTIosgNK3ryNX5F +tJK6It8V7K5nHBaA2q6oxfokjgNtLAzupkD4GxGDlROHpaCGhzyzXYuveVzi5YYmJd3 S7g6sPseWBl7gx+V87iGSDT+X6BINvZtgG+u5Q6rd0pbXtP7KTGtXMuJZSxKBIY1P1Ct AwsFw6LDYkNkqiLqZlF1DZ/rfv1oakrIcGU3C9fB7CbPWqceT7T6141OYjJSRdt2M1Nk t4zA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HTJwlypT; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id gt14si1140204pjb.119.2022.02.21.20.37.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 20:37:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-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=@kernel.org header.s=k20201202 header.b=HTJwlypT; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D2F87939EB; Mon, 21 Feb 2022 20:25:35 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233539AbiBUUQj (ORCPT + 99 others); Mon, 21 Feb 2022 15:16:39 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:37536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229893AbiBUUQh (ORCPT ); Mon, 21 Feb 2022 15:16:37 -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 AD91812ABE; Mon, 21 Feb 2022 12:16:13 -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 50F9B60FF6; Mon, 21 Feb 2022 20:16:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F458C340E9; Mon, 21 Feb 2022 20:16:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645474572; bh=46m+hKe2FxMP2Hp56rRFNSZ0rdlWQD3u26aizbEBFaI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HTJwlypT7i1Uc8kYuY+QrrRXqaA/kO64DCOFx2BqCOgnDB6YrqCbINz0sVK6oNPX6 tSVaWduDmvROXW+gyLo5srJ0TofAdqK4HjOuuwqT6MxaLyybV07Z5fDuW9tuKt1JrJ ytfDU8DeGEd/vtIR2UITwzYtoIK6S5/Fhz72FsR3Iuoz1T45lDNNv+TmTduIhunJcE hz4/4NNmNcH2kSJfs4Gon2erKAvR7ULfM+7Zfk/RB4Zhspn2AYOYQR44iqkJzlO27z bilHDbxd4tX3e58/sKbmSYFaMQYHenJkAYhFCaRGC3XOPhl5SWlpPZeQYyOqaEN4GO mdBnEum1+oJHQ== Date: Mon, 21 Feb 2022 21:16:47 +0100 From: Jarkko Sakkinen To: Eric Biggers 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=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Sun, Feb 20, 2022 at 06:21:36PM -0800, Eric Biggers wrote: > 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. Ah, so it is. Reviewed-by: Jarkko Sakkinen BR, Jarkko