From nobody Sat May 4 04:06:06 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+97101+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+97101+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1670436060; cv=none; d=zohomail.com; s=zohoarc; b=HhssV1mAuRcV7iwQ517jH5vgRDs3Fdm6be9aIfU6fc40X4b156MDoo0BDDOoV1iNsU3k4AR61WFH+2BdoKs5FdjxDm7TCts0pfmJzXQyCprkmLJK6ihwp09Us6EJp/sjcSvz9OMzfo4VE6p9WpKpWlPnTUwdsuxCWbX2n5lc5ow= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670436060; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=8kNLvGxIh7kf9TyB2iTac+q8GqTxJ1g5kz886lpI2t8=; b=bnpoNqUma2gG3GFib3yVd/ByNjzNAYYytcYeUB0gSo4nnabglfUqG2jBd7r5i7hUZU2vgMmSkq+VAhWJbEugPX5MlRjdybcHF4NVWLlNCNzcZlw19YbyXjTVfWnVQoZSdv2U1htHn+meP7BkZwtfGFnXRIlv0+ei04y9mRjRFSA= 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+97101+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 167043605999576.63359094951602; Wed, 7 Dec 2022 10:00:59 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id DxiSYY1788612x08t5FzCKo6; Wed, 07 Dec 2022 10:00:59 -0800 X-Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by mx.groups.io with SMTP id smtpd.web10.22946.1670436058757865938 for ; Wed, 07 Dec 2022 10:00:59 -0800 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 ams.source.kernel.org (Postfix) with ESMTPS id 42162B81F1F; Wed, 7 Dec 2022 18:00:56 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0358EC433C1; Wed, 7 Dec 2022 18:00:52 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: dandan.bi@intel.com, gaoliming@byosoft.com.cn, jian.j.wang@intel.com, Ard Biesheuvel Subject: [edk2-devel] [PATCH] MdeModulePkg/DxeCore: Use correct type for alignment mask Date: Wed, 7 Dec 2022 19:00:44 +0100 Message-Id: <20221207180044.2863126-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: C1IWxgA19A8QjfYdWZHjocAUx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1670436059; bh=QwhL8EkQYJ+sVcSD6o0hIGf3VBO70XVl5ygDotkvKUI=; h=Cc:Date:From:Reply-To:Subject:To; b=a/K17O6gyZZ69PbUVIZOP9nFlKwWqmB9dPz21pEDR1za6/KKDYZ2LoQ1FsvAJ0WAtNb L3pFMwUC4azG+yYfGvzZNdFnQP/aRp9aettFQCumHXB1UFykmLdwXwR6iXJqBet/asAc5 iQV4Dk/pTBGMJc2fzf7H5CO+1W5fyBDNhq8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1670436062396100003 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Michael D Kinney --- 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/P= age.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 =3D MaxAddress; } =20 - DescEnd =3D ((DescEnd + 1) & (~(Alignment - 1))) - 1; + DescEnd =3D ((DescEnd + 1) & (~((UINT64)Alignment - 1))) - 1; =20 // Skip if DescEnd is less than DescStart after alignment clipping if (DescEnd < DescStart) { --=20 2.35.1 -=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 (#97101): https://edk2.groups.io/g/devel/message/97101 Mute This Topic: https://groups.io/mt/95520976/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-