From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 889499417C4 for ; Fri, 12 Jan 2024 11:33:40 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=VWB5MR8qtL9H0Y4UXGlXsN4/nRIY/IzqLpNukWIHo5E=; c=relaxed/simple; d=groups.io; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject:To:Cc:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type; s=20140610; t=1705059219; v=1; b=kUNUna1KHh/Evh3aIJSlmY9ngjYCsi0l8j0adepGoVj7H9wFFXP6HX4xzz1pn6YYp+6ch1GU zMuo1wuOhbTkDdJmIucxFvOcWUW0LfmQ9CsJPsT/gciE1juCciwoWi5rz2l4dJ7iO6cEy5yxxAK 9Kv1UK8ML0E6GJe3NW3xSwko= X-Received: by 127.0.0.2 with SMTP id hh6lYY7687511xXzKGfm3LVz; Fri, 12 Jan 2024 03:33:39 -0800 X-Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) by mx.groups.io with SMTP id smtpd.web11.5141.1705059218147187171 for ; Fri, 12 Jan 2024 03:33:38 -0800 X-Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-a28e31563ebso672092266b.2 for ; Fri, 12 Jan 2024 03:33:37 -0800 (PST) X-Gm-Message-State: ypuiMQUv8uXo7g4ex1hRaU61x7686176AA= X-Google-Smtp-Source: AGHT+IFCf9h63G3ytMvucRP5Pmix9xKTlsKZQhZxpMQWK4L4GXW0CsOM5D/7+sANVe/95l/mSNm8/X8EamcK8MRvYOs= X-Received: by 2002:a17:906:29ce:b0:a28:b085:5a86 with SMTP id y14-20020a17090629ce00b00a28b0855a86mr540227eje.133.1705059216366; Fri, 12 Jan 2024 03:33:36 -0800 (PST) MIME-Version: 1.0 References: <48d2fc1437b07b1e815f3ca8cabc9c1a2fc05a87.1704696950.git.patrick.rudolph@9elements.com> In-Reply-To: <48d2fc1437b07b1e815f3ca8cabc9c1a2fc05a87.1704696950.git.patrick.rudolph@9elements.com> From: "Sheng Lean Tan" Date: Fri, 12 Jan 2024 12:33:00 +0100 Message-ID: Subject: Re: [edk2-devel] [PATCH] UefiPayloadPkg: CbParseLib: Fix integer overflow To: Patrick Rudolph Cc: devel@edk2.groups.io, sean@starlabs.systems, gua.guo@intel.com, james.lu@intel.com, ray.ni@intel.com, guo.dong@intel.com Precedence: Bulk 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,sheng.tan@9elements.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Type: multipart/alternative; boundary="000000000000e9af0e060ebe0876" X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=kUNUna1K; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=9elements.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io --000000000000e9af0e060ebe0876 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Gua or Sean, Would you mind to help review this? Thanks! Best Regards, *Lean Sheng Tan* 9elements GmbH, Kortumstra=C3=9Fe 19-21, 44787 Bochum, Germany Email: sheng.tan@9elements.com Phone: *+49 234 68 94 188 <+492346894188>* Mobile: *+49 176 76 113842 <+4917676113842>* Registered office: Bochum Commercial register: Amtsgericht Bochum, HRB 17519 Management: Sebastian German, Eray Bazaar Data protection information according to Art. 13 GDPR On Mon, 8 Jan 2024 at 08:00, Patrick Rudolph wrote: > The IMD entry uses the 32bit start field as relative offset > to root. On Ia32X64 this works fine as UINTN is also 32 bit and > negative relative offsets are properly calculated due to an > integer overflow. > > On X64 this doesn't work as UINTN is 64 bit and the offset > is no longer subtracted, but it's added to the root. Fix that > by sign extending the start field to 64 bit. > > Test: Booting UefiPayloadPkg still works on Ia32X64 and now also > works on X64. > > Signed-off-by: Patrick Rudolph > --- > UefiPayloadPkg/Library/CbParseLib/CbParseLib.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/UefiPayloadPkg/Library/CbParseLib/CbParseLib.c > b/UefiPayloadPkg/Library/CbParseLib/CbParseLib.c > index 8a353f77f6..9e149532a7 100644 > --- a/UefiPayloadPkg/Library/CbParseLib/CbParseLib.c > +++ b/UefiPayloadPkg/Library/CbParseLib/CbParseLib.c > @@ -282,7 +282,7 @@ FindCbMemTable ( > for (Idx =3D 0; Idx < Root->num_entries; Idx++) { > if (Entries[Idx].id =3D=3D TableId) { > if (IsImdEntry) { > - *MemTable =3D (VOID *)((UINTN)Entries[Idx].start + (UINTN)Root); > + *MemTable =3D (VOID *)((INTN)(INT32)Entries[Idx].start + > (UINTN)Root); > } else { > *MemTable =3D (VOID *)(UINTN)Entries[Idx].start; > } > -- > 2.43.0 > > -=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 (#113713): https://edk2.groups.io/g/devel/message/113713 Mute This Topic: https://groups.io/mt/103593206/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- --000000000000e9af0e060ebe0876 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Gua or Sean,
Would you mind to help review this?
Thanks!

<= div>Best Regards,
Lea= n Sheng Tan



9elements GmbH, Kortumstra=C3=9Fe 19-21, 44787 Bochum, = Germany
Email= :=C2=A0sheng.tan@9elements.com
<= font>Phone:=C2=A0+49 234 68 94 188<= /div>
Mobile:=C2=A0+49 176 76 113842
=

Registered office: Bochum
Commercial register: Amtsgericht Bochum, HRB 17519
Management: Sebastian German, Er= ay Bazaar

<= /div>

On Mon, 8 Jan 2024 at 08:00, Patrick Rudolph <patrick.rudolph@9elements.com> wrote:
The IMD entry uses= the 32bit start field as relative offset
to root. On Ia32X64 this works fine as UINTN is also 32 bit and
negative relative offsets are properly calculated due to an
integer overflow.

On X64 this doesn't work as UINTN is 64 bit and the offset
is no longer subtracted, but it's added to the root. Fix that
by sign extending the start field to 64 bit.

Test: Booting UefiPayloadPkg still works on Ia32X64 and now also
=C2=A0 =C2=A0 =C2=A0 works on X64.

Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
---
=C2=A0UefiPayloadPkg/Library/CbParseLib/CbParseLib.c | 2 +-
=C2=A01 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/UefiPayloadPkg/Library/CbParseLib/CbParseLib.c b/UefiPayloadPk= g/Library/CbParseLib/CbParseLib.c
index 8a353f77f6..9e149532a7 100644
--- a/UefiPayloadPkg/Library/CbParseLib/CbParseLib.c
+++ b/UefiPayloadPkg/Library/CbParseLib/CbParseLib.c
@@ -282,7 +282,7 @@ FindCbMemTable (
=C2=A0 =C2=A0for (Idx =3D 0; Idx < Root->num_entries; Idx++) {
=C2=A0 =C2=A0 =C2=A0if (Entries[Idx].id =3D=3D TableId) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0if (IsImdEntry) {
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 *MemTable =3D (VOID *)((UINTN)Entries[Idx].sta= rt + (UINTN)Root);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 *MemTable =3D (VOID *)((INTN)(INT32)Entries[Id= x].start + (UINTN)Root);
=C2=A0 =C2=A0 =C2=A0 =C2=A0} else {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0*MemTable =3D (VOID *)(UINTN)Entries[Idx]= .start;
=C2=A0 =C2=A0 =C2=A0 =C2=A0}
--
2.43.0

_._,_._,_

Groups.io Links:

=20 You receive all messages sent to this group. =20 =20

View/Reply Online (#113713) | =20 | Mute= This Topic | New Topic
Your Subscriptio= n | Contact Group Owner | Unsubscribe [rebecca@openfw.io]

_._,_._,_
--000000000000e9af0e060ebe0876--