[edk2-devel] [PATCH] MdeModulePkg/DxeCore: Use correct type for alignment mask

Michael D Kinney michael.d.kinney at intel.com
Wed Dec 7 23:13:41 UTC 2022


Reviewed-by: Michael D Kinney <michael.d.kinney at intel.com>

Mike

> -----Original Message-----
> From: devel at edk2.groups.io <devel at edk2.groups.io> On Behalf Of Ard Biesheuvel
> Sent: Wednesday, December 7, 2022 10:01 AM
> To: devel at edk2.groups.io
> Cc: Bi, Dandan <dandan.bi at intel.com>; Gao, Liming <gaoliming at byosoft.com.cn>; Wang, Jian J <jian.j.wang at intel.com>; Ard
> Biesheuvel <ardb at kernel.org>
> Subject: [edk2-devel] [PATCH] MdeModulePkg/DxeCore: Use correct type for alignment mask
> 
> The page allocator code in CoreFindFreePagesI() uses a mask derived from
> its UINTN Alignment argument to align the descriptor end address of a
> MEMORY_MAP entry to the requested alignment, in order to check whether
> the descriptor covers enough sufficiently aligned area to satisfy the
> request.
> 
> However, on 32-bit architectures, 'Alignment' is a 32-bit type, whereas
> DescEnd is a 64-bit type, and so the resulting operation performed on
> the end address comes down to masking with 0xfffff000 instead of the
> intended 0xffffffff_fffff000. Given the -1 at the end of the expression,
> the resulting address is 0xffffffff_fffffffff for any descriptor that
> ends on a 4G aligned boundary, and this is certainly not what was
> intended.
> 
> So cast Alignment to UINT64 to ensure that the mask has the right size.
> 
> Signed-off-by: Ard Biesheuvel <ardb at kernel.org>
> ---
>  MdeModulePkg/Core/Dxe/Mem/Page.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c
> index 160289c1f9ec..5903ce7ab525 100644
> --- a/MdeModulePkg/Core/Dxe/Mem/Page.c
> +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c
> @@ -1097,7 +1097,7 @@ CoreFindFreePagesI (
>        DescEnd = MaxAddress;
> 
>      }
> 
> 
> 
> -    DescEnd = ((DescEnd + 1) & (~(Alignment - 1))) - 1;
> 
> +    DescEnd = ((DescEnd + 1) & (~((UINT64)Alignment - 1))) - 1;
> 
> 
> 
>      // Skip if DescEnd is less than DescStart after alignment clipping
> 
>      if (DescEnd < DescStart) {
> 
> --
> 2.35.1
> 
> 
> 
> -=-=-=-=-=-=
> Groups.io Links: You receive all messages sent to this group.
> View/Reply Online (#97101): https://edk2.groups.io/g/devel/message/97101
> Mute This Topic: https://groups.io/mt/95520976/1643496
> Group Owner: devel+owner at edk2.groups.io
> Unsubscribe: https://edk2.groups.io/g/devel/unsub [michael.d.kinney at intel.com]
> -=-=-=-=-=-=
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#97105): https://edk2.groups.io/g/devel/message/97105
Mute This Topic: https://groups.io/mt/95520976/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-




More information about the edk2-devel-archive mailing list