From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web10.145.1609794343178713233 for ; Mon, 04 Jan 2021 13:05:43 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UFNqh/7E; spf=pass (domain: redhat.com, ip: 216.205.24.124, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609794341; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dDTWcJF5WJeOOzj9Bia32A+VBlo7Zy08nm72H9p5YMY=; b=UFNqh/7EGQ7p50kNtrLsLt1ARYD4Fkbmo/5w1dIGFtGi5ifFc0TAjsoLY8YA+qxT+HIGvP /I579qePFwJyLwvFAUo0u/ICE+/SDGXMmqt+AIEBNJNy8goxD5BY60x38YXZaNZcF+jqyt fkK943Eb65oHPHYy8UORgkdYLtgCJgg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-381-F72fAdkcP669jm7Lf7MHaw-1; Mon, 04 Jan 2021 16:05:38 -0500 X-MC-Unique: F72fAdkcP669jm7Lf7MHaw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C78411005D4C; Mon, 4 Jan 2021 21:05:36 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-113-80.ams2.redhat.com [10.36.113.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F53D6F43C; Mon, 4 Jan 2021 21:05:35 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH 07/12] OvmfPkg/VmgExitLib: Check for an explicit DR7 cached value To: devel@edk2.groups.io, thomas.lendacky@amd.com Cc: Brijesh Singh , James Bottomley , Jordan Justen , Ard Biesheuvel References: <69448e7f1e1ad25b2ff4890dd64e96ae14bb54e5.1608065471.git.thomas.lendacky@amd.com> From: "Laszlo Ersek" Message-ID: <331d0fe6-a83f-b3b3-c8e4-e2f1546eb518@redhat.com> Date: Mon, 4 Jan 2021 22:05:34 +0100 MIME-Version: 1.0 In-Reply-To: <69448e7f1e1ad25b2ff4890dd64e96ae14bb54e5.1608065471.git.thomas.lendacky@amd.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lersek@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 12/15/20 21:51, Lendacky, Thomas wrote: > From: Tom Lendacky > > BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3108 > > Check the DR7 cached indicator against a specific value. This makes it > harder for a hypervisor to just write random data into that field in an > attempt to use an invalid DR7 value. > > Cc: Jordan Justen > Cc: Laszlo Ersek > Cc: Ard Biesheuvel > Cc: Brijesh Singh > Signed-off-by: Tom Lendacky > --- > OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 11 +++++++---- > 1 file changed, 7 insertions(+), 4 deletions(-) > > diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c > index 1671db3a01b1..5149ab2bc989 100644 > --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c > +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c > @@ -128,10 +128,13 @@ UINT64 > > // > // Per-CPU data mapping structure > +// Use UINT32 for cached indicators and compare to a specific value > +// so that the hypervisor can't indicate a value is cached by just > +// writing random data to that area. > // > typedef struct { > - BOOLEAN Dr7Cached; > - UINT64 Dr7; > + UINT32 Dr7Cached; > + UINT64 Dr7; > } SEV_ES_PER_CPU_DATA; > > > @@ -1489,7 +1492,7 @@ Dr7WriteExit ( > } > > SevEsData->Dr7 = *Register; > - SevEsData->Dr7Cached = TRUE; > + SevEsData->Dr7Cached = 1; > > return 0; > } > @@ -1533,7 +1536,7 @@ Dr7ReadExit ( > // If there is a cached valued for DR7, return that. Otherwise return the > // DR7 standard reset value of 0x400 (no debug breakpoints set). > // > - *Register = (SevEsData->Dr7Cached) ? SevEsData->Dr7 : 0x400; > + *Register = (SevEsData->Dr7Cached == 1) ? SevEsData->Dr7 : 0x400; > > return 0; > } > Reviewed-by: Laszlo Ersek