From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4864:20::342; helo=mail-wm1-x342.google.com; envelope-from=leif.lindholm@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 914312117D293 for ; Tue, 6 Nov 2018 04:09:41 -0800 (PST) Received: by mail-wm1-x342.google.com with SMTP id a8-v6so11455247wmf.1 for ; Tue, 06 Nov 2018 04:09:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=m9yUPWL6HqwMzyfgTCaKuMvvsMunZMYJI6WwkBBl/ro=; b=H1L/NltuBKl2wsHv8LcyV7uONQ/8FQfoqV38Hd2OcLNhh0NrqoGjO3gsDi3BMRp7eY Hdg8YI9jifpnFqVUymnncYVireHCvutRPWXtaUIuo/ftfdysj0+c+wQ0DIbgdJvc1CFo gT+0/wTPQNAmUK/5OafseUx4ToCjcJaustGYE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=m9yUPWL6HqwMzyfgTCaKuMvvsMunZMYJI6WwkBBl/ro=; b=BT3n4Gez8nZSFePkYLdOAe4HPJ5u6NvcutC7RcBNikIZahCyjR2cBdzCszW486FIs1 Hc4o9LYcPt9MG28Y8B8szgIgk8z190L4uWA++Vt1okNEoLBh4t0EdEIc2McPzSMnOwOf JSRI+IrJZiO6G90ebiWICQ1hCCLe3D+XDKmua7PEITeFM6KZvQmADPwIDuYdgEtqGInt FA50hmwTdxqxVw8MH17VFbWSg6lJUdU9T5R0AXOGO1C/GkdOHVcHSu1IbCu2nr1xwHRu IIiWuv92eHIpSELoDkkt5wT/xFPj2nfp3BrVQoFP8t6+FMiDconD4QiovR8NzQLiGizb N7SQ== X-Gm-Message-State: AGRZ1gITvK/ZAJg1bJRZIAqGXyHMMeZSYsbUvL9HMeLG1F0GWYc3Kjm3 FsdPaVRXsxXLyoEnlpXY6Pr91A== X-Google-Smtp-Source: AJdET5dQGwkVeL16LOsyXVSgWZ3p3HVAXGC6hixUjXSUc79cKyz1cmmBnpApOC7GGbHz70zB3o87NQ== X-Received: by 2002:a1c:8c8c:: with SMTP id o134-v6mr1759780wmd.35.1541506180000; Tue, 06 Nov 2018 04:09:40 -0800 (PST) Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id 191-v6sm2375409wmk.30.2018.11.06.04.09.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Nov 2018 04:09:39 -0800 (PST) Date: Tue, 6 Nov 2018 12:09:37 +0000 From: Leif Lindholm To: Jian J Wang Cc: edk2-devel@lists.01.org, Ruiyu Ni , Jiewen Yao , Star Zeng Message-ID: <20181106120937.3k73y7l6ucsqxil6@bivouac.eciton.net> References: <20181103064221.4764-1-jian.j.wang@intel.com> <20181103064221.4764-3-jian.j.wang@intel.com> MIME-Version: 1.0 In-Reply-To: <20181103064221.4764-3-jian.j.wang@intel.com> User-Agent: NeoMutt/20170113 (1.7.2) Subject: Re: [PATCH 2/2] MdeModulePkg/Core: fix ineffective guard page issue X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Nov 2018 12:09:41 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sat, Nov 03, 2018 at 02:42:21PM +0800, Jian J Wang wrote: > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1295 > > This issue originates from following patch which allows to enable > paging if PcdImageProtectionPolicy and PcdDxeNxMemoryProtectionPolicy > (in addition to PcdSetNxForStack) are set to enable related features. > > 5267926134d17e86672b84fd57b438f05ffa68e1 > > Due to above change, PcdImageProtectionPolicy will be set to 0 by > default in many platforms, which, in turn, cause following code in > MdeModulePkg\Core\Dxe\Misc\MemoryProtection.c fail the creation of > notify event of CpuArchProtocol. > > 1138: if (mImageProtectionPolicy != 0 || > PcdGet64 (PcdDxeNxMemoryProtectionPolicy) != 0) { > 1139: Status = CoreCreateEvent ( > ... > 1142: MemoryProtectionCpuArchProtocolNotify, > ... > 1145: ); > > Then following call flow won't be done and Guard pages will not be > set as not-present in SetAllGuardPages() eventually. > > MemoryProtectionCpuArchProtocolNotify() > => HeapGuardCpuArchProtocolNotify() > => SetAllGuardPages() > > The solution is removing the if(...) statement so that the notify > event will always be created and handler be registered. This won't > cause unnecessary code execution because, in the notify event handler, > the related PCDs like > > PcdImageProtectionPolicy and > PcdDxeNxMemoryProtectionPolicy > > will be checked again to do its job. > > Cc: Star Zeng > Cc: Jiewen Yao > Cc: Ruiyu Ni > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Jian J Wang > --- > MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c | 2 -- > 1 file changed, 2 deletions(-) > > diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c > index 30e5c5153c..30798b05b9 100644 > --- a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c > +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c > @@ -1135,7 +1135,6 @@ CoreInitializeMemoryProtection ( > ASSERT (GetPermissionAttributeForMemoryType (EfiBootServicesData) == > GetPermissionAttributeForMemoryType (EfiConventionalMemory)); > > - if (mImageProtectionPolicy != 0 || PcdGet64 (PcdDxeNxMemoryProtectionPolicy) != 0) { > Status = CoreCreateEvent ( > EVT_NOTIFY_SIGNAL, > TPL_CALLBACK, > @@ -1154,7 +1153,6 @@ CoreInitializeMemoryProtection ( > &Registration > ); > ASSERT_EFI_ERROR(Status); > - } And here we see why. The indentation changes need to be part of this patch, not 1/2. / Leif > > // > // Register a callback to disable NULL pointer detection at EndOfDxe > -- > 2.16.2.windows.1 > > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel