Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2013286rdb; Tue, 20 Feb 2024 14:23:24 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXAiIUkSt892Hwd5LLbaUeg2tXNgFqhSot74b1/UqedFsUBd7u11B5zlcpvHYCo/9FFouJhBBeKYEIZD8B8dVNkk2Wbg16MnG30mn0leQ== X-Google-Smtp-Source: AGHT+IF6TbTiejhs2KjRRy+272xJPaWcSbMvKi8SAtUJoTjsHDVWUZXn/6S1a7PulFMv3rcXQ0sx X-Received: by 2002:a05:6358:706:b0:178:92dc:8a32 with SMTP id e6-20020a056358070600b0017892dc8a32mr17136509rwj.20.1708467804554; Tue, 20 Feb 2024 14:23:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708467804; cv=pass; d=google.com; s=arc-20160816; b=WNm6R9xGMjPL6B8GZ1YPZUXGmW5GzKo7nyvFbRukymQPWXFVKBmAnt6ZChJWuvNgHb eoUxAeFex3darZwRqa/HJctXlIxK8hwCHveaIf6IWllXxvTHqTJNCwDQg0IpaXBb8Tt/ 7GJYFkqsJzMTdMjvFziNnHDJdi2oPOe8zQv+yC5sGyk2EAQgLHPysfbyI8h6qdwU9Qby +071Bhr4VIq9+tkOMp9Vl47gvrIeTXkDOzDjj5PxdNQDBFgCI9iMPub42AkBDYVH/vnf bbYqGATHZskaxU/vMoXuovJJ+7p7AJwsVvi7UbAX6cd+f4LhWD6x0i1bv7nlpQjTFQdC 5nuQ== 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=OKS6Udcp6igVrG987pzqq3GCkNomRfNehWlRDWLPYoM=; fh=qgRitiGmfKto+KksLpraWTy3Jfsqw7ZkR35I16jgweg=; b=AvI6DwPftRosMBYgzFhj83QfdhrNM7JLxPhFyLSy/Y7a1QLLA3Zi5gg9OehcGtcbCF nEcJHGq+GN4fsuV8ZbPJQzRCLUvtoJogr716Z+WaSpQ5/kMUOKjd4YOHUMmwxPdYc6sA fDOQf8Rd5StL4a/a1X18zmEu54Ig2SE3v0YeR8n7Xp/nMIDnQgp4Ez+SIe373F+XjV9Y 7KiDJCic1n0wijRuSUrLX6OwqCeYk2bod9HU6elPFinF9NC0q+6PpMKzgIJg/ET8whQY WbfucuwdKqGPBAM47KLfW4IwJv1h3a3WSYoEVmG9lrFJsYbyL4oPlfzAbYSFe9FQgQZ7 KpOQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="UIS1TAq/"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-73758-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73758-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id x186-20020a6386c3000000b005dc431481absi6772216pgd.672.2024.02.20.14.23.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 14:23:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-73758-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="UIS1TAq/"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-73758-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73758-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id E6D67283F9C for ; Tue, 20 Feb 2024 22:23:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 995B11534E5; Tue, 20 Feb 2024 22:23:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UIS1TAq/" 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 BD83B14A4D2; Tue, 20 Feb 2024 22:23:18 +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=1708467798; cv=none; b=XDRLfWaU4Z5Jbf5SppILwUPn+C4M2gaQoWE1guxWYrppVs8cnv8U38ungJTKYyqkoHOsvwGhdJCJBenMe4hBq6dJDSySz5npiVRsYVc5uOLsE5m7D3ylIQfVx7gbnNFHpF5+CQjTNw090pJjIdokY3cDn7f3i9j4Yk073qTZP+o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708467798; c=relaxed/simple; bh=OKS6Udcp6igVrG987pzqq3GCkNomRfNehWlRDWLPYoM=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=MCsP2kvUVJel57QnlgEfGK6LlN2Kx28ZkeMetDGeLg7BFi1kU6Cl3pUG+mLLZ2TLXOHazSwI8yMxP0SKml4cQN2cFdwASRtFFnvhZos7PY6Nz5f3ADTY7ZjKql4eXDrXy/lBZgiBdUGYNwrZy816s6FxYypTDHitvPsmRp2umF4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UIS1TAq/; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0703FC433F1; Tue, 20 Feb 2024 22:23:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708467798; bh=OKS6Udcp6igVrG987pzqq3GCkNomRfNehWlRDWLPYoM=; h=Date:Cc:Subject:From:To:References:In-Reply-To:From; b=UIS1TAq/SIc7z+kKMQv5U7evPlAFezVV/5KXY51Bp3Et8Gj86uAE0arOUP4bTNbVt j5ZVQ5Wqm92Z2b8QeXU4qR+JOL/7Af0wzR7fDbyNCdAJ9KGRpxNWHNqF1EeEPkBd2e LXrPuJEcwefDbsmsY7iqPk1ikvPFnoNL4Ry03OCrlqph8GEPNbKqKb55nmbzXiXp+0 UOvuFVoJwJARlhHtJ4RSRV7ODNjA26/S5UfSAY/E9W+cBW2eMcAg28wL035BWG31k1 QPSKxQxTyVdMqmVqCzLoW/CveW1nicG437KO1zO3PNuDkqE2gwtug1TbKIRiaYnUkU WtGgVYBM/hYlA== 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: Tue, 20 Feb 2024 22:23:13 +0000 Message-Id: Cc: "Ross Philipson" , "Kanth Ghatraju" , "Peter Huewe" Subject: Re: [PATCH 1/3] tpm: protect against locality counter underflow From: "Jarkko Sakkinen" To: "Lino Sanfilippo" , "Alexander Steffen" , "Daniel P. Smith" , "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> In-Reply-To: <91f600ef-867b-4523-89be-1c0ba34f8a4c@kunbus.com> On Tue Feb 20, 2024 at 8:54 PM UTC, Lino Sanfilippo wrote: > Hi, > > On 20.02.24 19:42, Alexander Steffen wrote: > > ATTENTION: This e-mail is from an external sender. Please check attachm= ents and links before opening e.g. with mouseover. > >=20 > >=20 > > On 02.02.2024 04:08, Lino Sanfilippo wrote: > >> On 01.02.24 23:21, Jarkko Sakkinen wrote: > >> > >>> > >>> On Wed Jan 31, 2024 at 7:08 PM EET, Daniel P. Smith wrote: > >>>> Commit 933bfc5ad213 introduced the use of a locality counter to cont= rol when a > >>>> locality request is allowed to be sent to the TPM. In the commit, th= e counter > >>>> is indiscriminately decremented. Thus creating a situation for an in= teger > >>>> underflow of the counter. > >>> > >>> What is the sequence of events that leads to this triggering the > >>> underflow? This information should be represent in the commit message= . > >>> > >> > >> AFAIU this is: > >> > >> 1. We start with a locality_counter of 0 and then we call tpm_tis_requ= est_locality() > >> for the first time, but since a locality is (unexpectedly) already act= ive > >> check_locality() and consequently __tpm_tis_request_locality() return = "true". > >=20 > > check_locality() returns true, but __tpm_tis_request_locality() returns > > the requested locality. Currently, this is always 0, so the check for > > !ret will always correctly indicate success and increment the > > locality_count. > >=20 > > Will the TPM TIS CORE ever (have to) request another locality than 0? May= be the best would > be to hardcode TPM_ACCESS(0) and get rid of all the locality parameters t= hat are > passed from one function to another. Usually, or at least use cases I'm aware of, localities are per component. E.g. Intel TXT has one and Linux has another. There's been some proposals in the past here for hypervisor specific locality here at LKML they didn't lead to anything. If you are suggesting of removing "int l" parameter altogether, I do support that idea. > But this is rather code optimization and not really required to fix > the reported bug. Just adding here that I wish we also had a log transcript of bug, which is right now missing. The explanation believable enough to move forward but I still wish to see a log transcript. A/B testing of the bug and fix is something I'm lacking here. If anyone has ideas how to use QEMU to simulate what Intel TXT does with localities that would help. Most of us do not carry Intel TXT setup anywhere (home or office). Also even tho 0/3 has an explanation bug 1/3 does not have anything at all to make it to be counted as a bug fix. Pretty difficult to compare any possible proposals for a fix on this playground tbh. BR, Jarkko