Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp87681rbb; Fri, 23 Feb 2024 12:44:47 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWzTvQdzkiWsSrezDweeaZx8crIAFMOO9Fu4oWlrNM9m1PJfb355KD/xyGmpYlZRPGAjm0g2i+put7EOdBRN4tTT0CrvIRjdaxXIJJm1Q== X-Google-Smtp-Source: AGHT+IFrCgOQ5x53hxAcqqN6hIAQriS4aNQNIOGk3zhvf4gWbmBs1RKDvzx0hxfPaUN1kKS7T25o X-Received: by 2002:a05:620a:1124:b0:787:2dfe:2a2e with SMTP id p4-20020a05620a112400b007872dfe2a2emr938571qkk.56.1708721087487; Fri, 23 Feb 2024 12:44:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708721087; cv=pass; d=google.com; s=arc-20160816; b=bxzo7J8mWTbr/efv67e+JGVXch5/CaYX6k6ueq7z2L7qkPGHYrVsKV3/Tt9sqzxR/e YszBuSka6Q7ZuEAL4axGAFYnh8yCNJWyRQeCCVWD2u+sX4DeulifJD298NYV6LvtBv2D V/ysyU7vWAXBY+VpU8ZBHA8aJjL/hDqnqFPg+tCH99iqj31u+mLiZ234WzlUUFNcPUH3 YnIQH8gad/XmcB5roPChxqjvsUeKfUWeKnus1sWEC4g0Da/STW4lmhFjxsdNRXlor2Wd NBiWfsp6x3nFht01Qv3eSdKkT4o/JbNOVJ83zcVdEfEo+fqGjJjje5vf+YSGrmHdtWfB WOcQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:dkim-signature; bh=w2bVTDZxro+3yv7HkcnJMf2U/GSC3dVBquYKZWSi2og=; fh=g+K6cttPAsSxOj3rr3s++ibR9e628yQf0OCygVn+Rmc=; b=aCt0gVY0ar4edfpi4Vtfpnu22fJ0dVmj3zKmD6eidtkL+WBItgitseX88U3fJZ8IDd RVRHX5ymcAdfYG+a5t+W4yEbKKAOVAY9GACSwQ/tq4+AebTaGsgqx6p9srqIXoAPHYY/ Ld+1Fpnm8cvim5kVcHqC5HxrxAzJVNmwKcX9AXvLjp8IfpV1RfDXCld581+bEJp/1kqK BjlzlqwH4SMuI1N1j+IAzMDb7w2vZIgvQrgKCFrUzbcz0Jr4U17IX+NI4rMZuTz/Jcdv ZSJRhOEKzQU8rr1dIfIu/ZTSlGG4t6wAy3nVy068ZZg9maI0TmwgNcRcK/HgRnTUJXP2 FDHw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=I5J+TKJX; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-79126-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79126-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id f6-20020a05620a15a600b00783fb4f6fbcsi15547067qkk.529.2024.02.23.12.44.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 12:44:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79126-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=I5J+TKJX; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-79126-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79126-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 2ACDD1C23737 for ; Fri, 23 Feb 2024 20:44:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8067D1487E6; Fri, 23 Feb 2024 20:42:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="I5J+TKJX" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 A4540146E76; Fri, 23 Feb 2024 20:42:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708720948; cv=none; b=Z6xeEwJQfHL6tIFH5C5RTc6w1Glq+cAC3lV7KaYzUvO5yh9ispGiFYfTttzLJTBXLIQqJGc5Z0//7FG0wVT1kEORDMR4ZyTmQzz4A97n1K5Bv5dFQXwb5z5ZF6IAPguCZm8l8zbR6oiJNv7Fw8FLmPiCYwgwAEAY1QnQ/Di+6IE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708720948; c=relaxed/simple; bh=pHoXDnwutfbyjqrkBCrccDqh2gu3zSNO5OYOn7Rd5Dg=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=l2HYpP9aY81yGHPQ9mSpf4BbukrzKl1zeck9HKHUiEOieT+VagQV0Y1qECyPD/tL+R37HD1uyLCykvSIdqbzZz489xwMOvAJC/lY7DIcFoSxPdvJY8E27TINr/Ugrn9mNRum14OacFWpJy1Lz5lWaCjpyf+GpY9BCrn7jn+jskk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=I5J+TKJX; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C95CFC433F1; Fri, 23 Feb 2024 20:42:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708720948; bh=pHoXDnwutfbyjqrkBCrccDqh2gu3zSNO5OYOn7Rd5Dg=; h=Date:Cc:Subject:From:To:References:In-Reply-To:From; b=I5J+TKJXSsh/1Pd/kcCSDm5W0Zo/GXHSvaEAGbwlJyh7hyFMYwS8sSeMfDyFEyfbp omK/t9h3JjNiNcFWT2M48tbNCbfWYwf/ap10zB986ogizIRRfxB2zsni3Hs+j8D1MV wdG9R5XASvCB5cwH1fcAYaG+zC+dBsnM06UOI3UGoK0Ohu632/6eiA2lx9M6K2I27Y Q2PgnrRDdwu2/0KzPuGdMP3ByC4H+1sQRjiByvWlagGVqXCvB7DV/yWIK2nTPMxXPr Qg6utD1NfgGXYKOy0jayxr26lN0r3YHN3HNeO1m1EUFf0l3K1pranyPPOuQqgCkgnv JUo32pR6bc8RA== Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Fri, 23 Feb 2024 22:42:23 +0200 Message-Id: Cc: "Ross Philipson" , "Kanth Ghatraju" , "Peter Huewe" Subject: Re: [PATCH 1/3] tpm: protect against locality counter underflow From: "Jarkko Sakkinen" To: "Jarkko Sakkinen" , "Daniel P. Smith" , "James Bottomley" , "Lino Sanfilippo" , "Alexander Steffen" , "Jason Gunthorpe" , "Sasha Levin" , , X-Mailer: aerc 0.15.2 References: <20240131170824.6183-1-dpsmith@apertussolutions.com> <20240131170824.6183-2-dpsmith@apertussolutions.com> <2ba9a96e-f93b-48e2-9ca0-48318af7f9b1@kunbus.com> <91f600ef-867b-4523-89be-1c0ba34f8a4c@kunbus.com> <7a7f8f0c1b9d124bfc01b66082abf2d8445564ce.camel@HansenPartnership.com> In-Reply-To: On Fri Feb 23, 2024 at 10:40 PM EET, Jarkko Sakkinen wrote: > On Fri Feb 23, 2024 at 3:57 AM EET, Daniel P. Smith wrote: > > On 2/21/24 14:43, Jarkko Sakkinen wrote: > > > On Wed Feb 21, 2024 at 12:37 PM UTC, James Bottomley wrote: > > >> On Tue, 2024-02-20 at 22:31 +0000, Jarkko Sakkinen wrote: > > >>> > > >>> 2. Because localities are not too useful these days given TPM2's > > >>> =C2=A0=C2=A0 policy mechanism > > >> > > >> Localitites are useful to the TPM2 policy mechanism. When we get ke= y > > >> policy in the kernel it will give us a way to create TPM wrapped key= s > > >> that can only be unwrapped in the kernel if we run the kernel in a > > >> different locality from userspace (I already have demo patches doing > > >> this). > > >=20 > > > Let's keep this discussion in scope, please. > > >=20 > > > Removing useless code using registers that you might have some actual= ly > > > useful use is not wrong thing to do. It is better to look at things f= rom > > > clean slate when the time comes. > > >=20 > > >>> I cannot recall out of top of my head can > > >>> =C2=A0=C2=A0 you have two localities open at same time. > > >> > > >> I think there's a misunderstanding about what localities are: they'r= e > > >> effectively an additional platform supplied tag to a command. Each > > >> command can therefore have one and only one locality. The TPM doesn= 't > > >=20 > > > Actually this was not unclear at all. I even read the chapters from > > > Ariel Segall's yesterday as a refresher. > > >=20 > > > I was merely asking that if TPM_ACCESS_X is not properly cleared and = you > > > se TPM_ACCESS_Y where Y < X how does the hardware react as the bug > > > report is pretty open ended and not very clear of the steps leading t= o > > > unwanted results. > > >=20 > > > With a quick check from [1] could not spot the conflict reaction but > > > it is probably there. > > > > The expected behavior is explained in the Informative Comment of sectio= n=20 > > 6.5.2.4 of the Client PTP spec[1]: > > > > "The purpose of this register is to allow the processes operating at th= e=20 > > various localities to share the TPM. The basic notion is that any=20 > > locality can request access to the TPM by setting the=20 > > TPM_ACCESS_x.requestUse field using its assigned TPM_ACCESS_x register= =20 > > address. If there is no currently set locality, the TPM sets current=20 > > locality to the requesting one and allows operations only from that=20 > > locality. If the TPM is currently at another locality, the TPM keeps th= e=20 > > request pending until the currently executing locality frees the TPM.= =20 > > Right. > > I'd think it would make sense to document the basic dance like this as > part of kdoc for request_locality: > > * Setting TPM_ACCESS_x.requestUse: > * 1. No locality reserved =3D> set locality. > * 2. Locality reserved =3D> set pending. > > I.e. easy reminder with enough granularity. Also for any non-TPM kernel developer this should be enough to get the basic gist of the mechanism without spending too much time reading. BR, Jarkko