Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3183C433EF for ; Tue, 11 Jan 2022 04:48:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347923AbiAKEsL (ORCPT ); Mon, 10 Jan 2022 23:48:11 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:60386 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346578AbiAKEsJ (ORCPT ); Mon, 10 Jan 2022 23:48:09 -0500 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 39D0161464; Tue, 11 Jan 2022 04:48:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65C1EC36AEB; Tue, 11 Jan 2022 04:48:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1641876488; bh=9k7gOl/NHLklU+ZV4oa3MqfoDU/Ae8pDZuPPq4e+vuY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=TKjMXLohTL3KBqdbMa/XT/78E7lOCg80MzUcrVl+POwdOzlNXTT/v0XkpQwMvO1Hu ZnU6/oVx7vDiq94PluRGsnKlzMmqBIMIgxjE/oB+jK/xKxjxcggUAQjuHl+pUw8QvM KHQDp5jvSf5OOouYoM8ZvLrTEMrN7ErmtAXPGV0KdQD0qODl1bozuIzexS+6I2UtvY jcF49TsTNXgig1bnFP57SOskccPCfVnn6iAlCy9GjW0xGoCvhHoM2kKH82Os4Qbt7t pAg3Usuc/CKwk8R3hP9ExITRl7oSO3LfDWxRe1bVlzVLsyvtH4qxPz30hWlJWutPOi L72N3+S77MUfw== Date: Mon, 10 Jan 2022 20:48:06 -0800 From: Eric Biggers To: Stefan Berger Cc: Mimi Zohar , linux-integrity@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 5/6] ima: support fs-verity file digest based signatures Message-ID: References: <20220109185517.312280-1-zohar@linux.ibm.com> <20220109185517.312280-6-zohar@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 10, 2022 at 10:26:23PM -0500, Stefan Berger wrote: > > On 1/10/22 17:45, Eric Biggers wrote: > > On Sun, Jan 09, 2022 at 01:55:16PM -0500, Mimi Zohar wrote: > > > + case IMA_VERITY_DIGSIG: > > > + set_bit(IMA_DIGSIG, &iint->atomic_flags); > > > + > > > + algo = iint->ima_hash->algo; > > > + hash = kzalloc(sizeof(*hash) + hash_digest_size[algo], > > > + GFP_KERNEL); > > > + if (!hash) { > > > + *cause = "verity-hashing-error"; > > > + *status = INTEGRITY_FAIL; > > > + break; > > > + } > > > + > > > + rc = calc_tbs_hash(IMA_VERITY_DIGSIG, iint->ima_hash->algo, > > > + iint->ima_hash->digest, hash); > > > + if (rc) { > > > + *cause = "verity-hashing-error"; > > > + *status = INTEGRITY_FAIL; > > > + break; > > > + } > > > + > > > + rc = integrity_digsig_verify(INTEGRITY_KEYRING_IMA, > > > + (const char *)xattr_value, > > > + xattr_len, hash->digest, > > > + hash->length); > > This is still verifying a raw hash value, which is wrong as I've explained > > several times. Yes, you are now hashing the hash algorithm ID together with the > > original hash value, but at the end the thing being signed/verified is still a > > raw hash value, which is ambigious. > > > > I think I see where the confusion is. If rsa-pkcs1pad is used, then the > > asymmetric algorithm is parameterized by a hash algorithm, and this hash > > algorithm's identifier is automatically built-in to the data which is > > signed/verified. And the data being signed/verified is assumed to be a hash > > value of the same type. So in this case, the caller doesn't need to handle > > disambiguating raw hashes. > > > > However, asymmetric_verify() also supports ecdsa and ecrdsa signatures. As far > > as I can tell, those do *not* have the hash algorithm identifier built-in to the > > data which is signed/verified; they just sign/verify the data given. That > > > The signatures are generated by evmctl by this code here, which works for > RSA and ECDSA and likely also ECRDSA: > > https://sourceforge.net/p/linux-ima/ima-evm-utils/ci/master/tree/src/libimaevm.c#l1036 > > ?? if (!EVP_PKEY_sign_init(ctx)) > ??????? goto err; > ??? st = "EVP_get_digestbyname"; > ??? if (!(md = EVP_get_digestbyname(algo))) > ??????? goto err; > ??? st = "EVP_PKEY_CTX_set_signature_md"; > ??? if (!EVP_PKEY_CTX_set_signature_md(ctx, md)) > ??????? goto err; > ??? st = "EVP_PKEY_sign"; > ??? sigsize = MAX_SIGNATURE_SIZE - sizeof(struct signature_v2_hdr) - 1; > ??? if (!EVP_PKEY_sign(ctx, hdr->sig, &sigsize, hash, size)) > ??????? goto err; > ??? len = (int)sigsize; > > As far as I know, these are not raw signatures but generate the OIDs for RSA > + shaXYZ or ECDSA + shaXYZ (1.2.840.10045.4.1 et al) and prepend them to the > hash and then sign that. As I said, this appears to be true for RSA but not for ECDSA or ECRDSA. - Eric