Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp1984443rdb; Sun, 4 Feb 2024 09:25:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IGNnfwvh/e3kOSCP84NzuKuqG1W0QO1V0tVWXcOyMSsM9VP7RNQHRv63wqkS+a21l3HmSN4 X-Received: by 2002:a17:90a:d18f:b0:296:5abe:a862 with SMTP id fu15-20020a17090ad18f00b002965abea862mr4048670pjb.9.1707067534212; Sun, 04 Feb 2024 09:25:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707067534; cv=pass; d=google.com; s=arc-20160816; b=FCgXY0QQxKMktQN71hV/V1eL3u2St96OrgPmHMT642oL9RshjAveXyXrDKVUN0+qpo 1pDriaGwxiLRUpiFW6rlTcO4JvBlz5Zw7hAa+gyL8EBR74zmHjDe0+xkHNJKy4x6jcCB 1WorvB6yW5uegfRdr8+rLGznXI9/FfeMQCvuD7GCgAFUvyeW8pyYJbp3hdKI+IFw5OSq rB3rMTmgd2oCI/UQ89K7rRclY6qh6j3g8BNKs0kvXyGmddJ36WRZUGAsG8/5O5e3qOod 5BNJIiYsPZsINYmXioj8xiK6226EVeyDpwn1fAM+UBr6WD3qu43CbJSFKKmI6c08+hLW mumg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:to:from:date; bh=oEsfkZBMuNrSQohO70oFXSFvby3G+848+xJAxSKV4ck=; fh=sfqOx+GOEtAREI2uN9DN1g6UoQ3MZTBJ5lO8itZ2i3E=; b=IIIv2gLepfFGSHPGcacmy3Hy5ZTkn0y4eOypg0NMufD///gNwqx9DoijPw+a8YI3OA vp1qvm1a8bVU7cSn5C93VDjRvf+g74Muna102hyv1CnWdJ8rViXmiq1njuhAUwbDBJ5V /4hbhDlUqF3sKGPlxrvA81BfbdH8sgUZH5HK3YFPh2HOiDTiddYZqWzNYBbLBSLCcYFq rZjNmJzdjn0DINeM3nupxXqYqK97VQUbvFv/d/5Q0YEjuoYvqbBpUx0E6e4W6zOjTqYE Jrs2IH95cuHdY1zBQcLpOeriI+1BawGbqQ9SWVCIqhgid8/7xsiKSPREG9cfruBZBk49 PeLQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-crypto+bounces-1828-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-crypto+bounces-1828-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVSLwMsUtjL3JNsDF3zRKbgRyf+OCwXY8wX0feUCioiICeQNAy9fpHf7iX+2lkGuH5ab4LGb8brsNbCJUt78e/a/SpkCiKr86P4c/JhkQ== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id p10-20020a17090a868a00b002966704cc6fsi2550337pjn.38.2024.02.04.09.25.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Feb 2024 09:25:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto+bounces-1828-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-crypto+bounces-1828-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-crypto+bounces-1828-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 0991BB20D86 for ; Sun, 4 Feb 2024 17:25:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1288D249EA; Sun, 4 Feb 2024 17:25:22 +0000 (UTC) X-Original-To: linux-crypto@vger.kernel.org Received: from bmailout2.hostsharing.net (bmailout2.hostsharing.net [83.223.78.240]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE2D824215; Sun, 4 Feb 2024 17:25:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=83.223.78.240 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707067521; cv=none; b=GM1kqxvichtTG0GoZZ4cNM7S4FUxVaBp41QrXgstMIbRoG7MbskpnEscNjV1MIHKpGkEt9rg1JHpPj2j2uRdmOOOtrCy7kmClVs2mEs7vRim/4Ol0oT7RUtri1tEoeWhKW7tw+hFo1ztumsfvgMLfHWwf4j1C1poJWXBEQ/PzcU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707067521; c=relaxed/simple; bh=o6XgZklQg99ao472cPaHWFZkdLc8gXrmjSvTwRxHuxo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TN1avc3WT/XHGYEkLHNFOWH4ajWnHA1mlu09SaaoYq3nTErMNinLTVO++B90QFMD5Hq/AoVYu1VgnV2DW1mmEXMPe97840OoD1kF3sWZ2ySKwLTJSptf57J7FWI6quGfO5rjUEOQckHsywGb/SAd0UNS3rrJquwSyaI7tcUyxOk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=wunner.de; spf=none smtp.mailfrom=h08.hostsharing.net; arc=none smtp.client-ip=83.223.78.240 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=wunner.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=h08.hostsharing.net Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "*.hostsharing.net", Issuer "RapidSSL TLS RSA CA G1" (verified OK)) by bmailout2.hostsharing.net (Postfix) with ESMTPS id 5E0872800B3C2; Sun, 4 Feb 2024 18:25:10 +0100 (CET) Received: by h08.hostsharing.net (Postfix, from userid 100393) id 463422F90E5; Sun, 4 Feb 2024 18:25:10 +0100 (CET) Date: Sun, 4 Feb 2024 18:25:10 +0100 From: Lukas Wunner To: Jonathan Cameron , Ilpo =?iso-8859-1?Q?J=E4rvinen?= Cc: Bjorn Helgaas , David Howells , David Woodhouse , Herbert Xu , "David S. Miller" , Alex Williamson , linux-pci@vger.kernel.org, linux-cxl@vger.kernel.org, linux-coco@lists.linux.dev, keyrings@vger.kernel.org, linux-crypto@vger.kernel.org, kvm@vger.kernel.org, linuxarm@huawei.com, David Box , Dan Williams , Dave Jiang , "Li, Ming" , Zhi Wang , Alistair Francis , Wilfred Mallawa , Alexey Kardashevskiy , Tom Lendacky , Sean Christopherson , Alexander Graf Subject: Re: [PATCH 07/12] spdm: Introduce library to authenticate devices Message-ID: <20240204172510.GA19805@wunner.de> References: <89a83f42ae3c411f46efd968007e9b2afd839e74.1695921657.git.lukas@wunner.de> <20231003153937.000034ca@Huawei.com> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231003153937.000034ca@Huawei.com> User-Agent: Mutt/1.10.1 (2018-07-13) On Tue, Oct 03, 2023 at 03:39:37PM +0100, Jonathan Cameron wrote: > On Thu, 28 Sep 2023 19:32:37 +0200 Lukas Wunner wrote: > > +/** > > + * spdm_challenge_rsp_sz() - Calculate CHALLENGE_AUTH response size > > + * > > + * @spdm_state: SPDM session state > > + * @rsp: CHALLENGE_AUTH response (optional) > > + * > > + * A CHALLENGE_AUTH response contains multiple variable-length fields > > + * as well as optional fields. This helper eases calculating its size. > > + * > > + * If @rsp is %NULL, assume the maximum OpaqueDataLength of 1024 bytes > > + * (SPDM 1.0.0 table 21). Otherwise read OpaqueDataLength from @rsp. > > + * OpaqueDataLength can only be > 0 for SPDM 1.0 and 1.1, as they lack > > + * the OtherParamsSupport field in the NEGOTIATE_ALGORITHMS request. > > + * For SPDM 1.2+, we do not offer any Opaque Data Formats in that field, > > + * which forces OpaqueDataLength to 0 (SPDM 1.2.0 margin no 261). > > + */ > > +static size_t spdm_challenge_rsp_sz(struct spdm_state *spdm_state, > > + struct spdm_challenge_rsp *rsp) > > +{ > > + size_t size = sizeof(*rsp) /* Header */ > > Double spaces look a bit strange... > > > + + spdm_state->h /* CertChainHash */ > > + + 32; /* Nonce */ > > + > > + if (rsp) > > + /* May be unaligned if hash algorithm has unusual length. */ > > + size += get_unaligned_le16((u8 *)rsp + size); > > + else > > + size += SPDM_MAX_OPAQUE_DATA; /* OpaqueData */ > > + > > + size += 2; /* OpaqueDataLength */ > > + > > + if (spdm_state->version >= 0x13) > > + size += 8; /* RequesterContext */ > > + > > + return size + spdm_state->s; /* Signature */ > > Double space here as well looks odd to me. This was criticized by Ilpo as well, but the double spaces are intentional to vertically align "size" on each line for neatness. How strongly do you guys feel about it? ;) > > +int spdm_authenticate(struct spdm_state *spdm_state) > > +{ > > + size_t transcript_sz; > > + void *transcript; > > + int rc = -ENOMEM; > > + u8 slot; > > + > > + mutex_lock(&spdm_state->lock); > > + spdm_reset(spdm_state); [...] > > + rc = spdm_challenge(spdm_state, slot); > > + > > +unlock: > > + if (rc) > > + spdm_reset(spdm_state); > > I'd expect reset to also clear authenticated. Seems odd to do it separately > and relies on reset only being called here. If that were the case and you > were handling locking and freeing using cleanup.h magic, then > > rc = spdm_challenge(spdm_state); > if (rc) > goto reset; > return 0; > > reset: > spdm_reset(spdm_state); Unfortunately clearing "authenticated" in spdm_reset() is not an option: Note that spdm_reset() is also called at the top of spdm_authenticate(). If the device was previously successfully authenticated and is now re-authenticated successfully, clearing "authenticated" in spdm_reset() would cause the flag to be briefly set to false, which may irritate user space inspecting the sysfs attribute at just the wrong moment. If the device was previously successfully authenticated and is re-authenticated successfully, I want the "authenticated" attribute to show "true" without any gaps. Hence it's only cleared at the end of spdm_authenticate() if there was an error. I agree with all your other review feedback and have amended the patch accordingly. Thanks a lot! Lukas