From nobody Mon Sep 16 19:15:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+101117+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+101117+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1678727889; cv=none; d=zohomail.com; s=zohoarc; b=FvZwrNgIszbTcNDKt5in3Pm1vtCo44N0qyepwAIKRj8cK3YVFa/g2W1sj09ggyzfeFhJgiIUB33d6z0TWrZ5Csj+M3PzwCqZm3TJTibTQ6Jyot8y97epyT3Gzdp0Cf8Oa45r3Nq05AYO3iaw9kQAHHjIgk4BDvuS16DdV6MKRmU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678727889; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=qZ3lq3b48kWIMNxvCO37kJQGCJPgOwZu0f20TLfJNwU=; b=kMiMRlhIyMv/ZDnefyEOXJuvkvzHB2/R6RCYiHnfH5OOl62LBDFdkVs7vHqwvGJetrJAeVlKwLGAJR0yluuQQDXCpAWy4RVeXh11KkVC35bxa4ZK9ddtcGJKy3qakblzA+d4nLM8MpDnjPORzE3fz74yaBSfvAyU38G6gehk6UE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+101117+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1678727889500362.5834023892688; Mon, 13 Mar 2023 10:18:09 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id OOX7YY1788612xiBXuPlJ20T; Mon, 13 Mar 2023 10:18:09 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web10.25804.1678727888668004222 for ; Mon, 13 Mar 2023 10:18:08 -0700 X-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 3263A6142D; Mon, 13 Mar 2023 17:18:08 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8462C4339B; Mon, 13 Mar 2023 17:18:05 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Michael Kinney , Liming Gao , Jiewen Yao , Michael Kubacki , Sean Brogan , Rebecca Cran , Leif Lindholm , Sami Mujawar , Taylor Beebe Subject: [edk2-devel] [PATCH v5 13/38] MdeModulePkg/DxeCore: Unconditionally set memory protections Date: Mon, 13 Mar 2023 18:16:49 +0100 Message-Id: <20230313171714.3866151-14-ardb@kernel.org> In-Reply-To: <20230313171714.3866151-1-ardb@kernel.org> References: <20230313171714.3866151-1-ardb@kernel.org> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ardb@kernel.org X-Gm-Message-State: eom7gYy1PqWeknXf3wsUZ5MMx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1678727889; bh=whyqaEPznCI8mFgoN6rj2JGCjuRt/fbQVaAl/zK0+I8=; h=Cc:Date:From:Reply-To:Subject:To; b=OLO97yrVPQlcjTEi5S+DIcW/UjXuLbXYsYI0lWYZebFfSrfipo+HLgi3ZGBfWNRcOzY +ao15TR9O7iWm5LlC+W0iEpKrgZBrreA0xIHyk1g47AXPnBRdjxfhE9A/X4tajDazhcce xZkuajz8CNAI4VNEUJhS0163gz33oS0arFw= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1678727890053100014 Content-Type: text/plain; charset="utf-8" Instead of relying on a questionable heuristic that avoids calling into the SetMemoryAttributes () DXE service when the old memory type and the new one are subjected to the same NX memory protection policy, make this call unconditionally. This avoids corner cases where memory region attributes are out of sync with the policy, either due to the fact that we are in the middle of ramping up the protections, or due to explicit invocations of SetMemoryAttributes() by drivers. This requires the architecture page table code to be able to deal with this, in particular, it needs to be robust against potential recursion due to NX policies being applied to newly allocated page tables. Signed-off-by: Ard Biesheuvel --- MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c b/MdeModulePkg/C= ore/Dxe/Misc/MemoryProtection.c index b89ab046fa73..5a82eee80781 100644 --- a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c @@ -1246,7 +1246,6 @@ ApplyMemoryProtectionPolicy ( IN UINT64 Length ) { - UINT64 OldAttributes; UINT64 NewAttributes; =20 // @@ -1302,16 +1301,5 @@ ApplyMemoryProtectionPolicy ( // NewAttributes =3D GetPermissionAttributeForMemoryType (NewType); =20 - if (OldType !=3D EfiMaxMemoryType) { - OldAttributes =3D GetPermissionAttributeForMemoryType (OldType); - if (OldAttributes =3D=3D NewAttributes) { - // policy is the same between OldType and NewType - return EFI_SUCCESS; - } - } else if (NewAttributes =3D=3D 0) { - // newly added region of a type that does not require protection - return EFI_SUCCESS; - } - return gCpu->SetMemoryAttributes (gCpu, Memory, Length, NewAttributes); } --=20 2.39.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#101117): https://edk2.groups.io/g/devel/message/101117 Mute This Topic: https://groups.io/mt/97586011/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-