From nobody Mon Feb 9 21:37:04 2026 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+67705+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+67705+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1605783257; cv=none; d=zohomail.com; s=zohoarc; b=MZnTj0ZlFiWr2dAftVvDUfMJ4J1S/FXoCbB84EL+QggjsWnvO9rHdGVR/Zz9kkjkx0mUrsMCgLj8A+C97jpNVxUy3t2FtjurYaGZvjdhMIw7lAvjG23MObCMsJcQ/gCPqEhdAzgssE+1+96ifA4vYf1vFEvNlCuTDphiEgHLpy8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605783257; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=4iyPaDS3rfsX6uhi1fLSNTD8FIwlyxvz682EinpcTR4=; b=fRcTGQUvGkwGcb6Bdi5Cm1E6LNjboFYSldiCmWAzEBg9vabUVUUx/Oi1L3qaGNJH7Lt/MG7YJJ3gxMFyxRrFIa6NVe4w5EH4AEwy5d2NUp51kGvEjZ92moyYtNVTrdCyiCN4dV97jWUuKO1pljGj8+o+mJYRIrSESxf4xp7RQU0= 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+67705+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1605783257518214.5149268713634; Thu, 19 Nov 2020 02:54:17 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id B77CYY1788612xFNt4Gf5ppO; Thu, 19 Nov 2020 02:54:17 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web12.7408.1605783256575953154 for ; Thu, 19 Nov 2020 02:54:16 -0800 X-Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-229-VqiBesbeOqKGMt4FlttCcg-1; Thu, 19 Nov 2020 05:54:11 -0500 X-MC-Unique: VqiBesbeOqKGMt4FlttCcg-1 X-Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 48E4D100739B; Thu, 19 Nov 2020 10:53:45 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-112-236.ams2.redhat.com [10.36.112.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB4B160636; Thu, 19 Nov 2020 10:53:43 +0000 (UTC) From: "Laszlo Ersek" To: edk2-devel-groups-io Cc: Dandan Bi , Hao A Wu , Jian J Wang , Liming Gao , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [PATCH v2 RESEND 1/2] MdeModulePkg/Core/Dxe: assert SectionInstance invariant in FindChildNode() Date: Thu, 19 Nov 2020 11:53:39 +0100 Message-Id: <20201119105340.16225-2-lersek@redhat.com> In-Reply-To: <20201119105340.16225-1-lersek@redhat.com> References: <20201119105340.16225-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: 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,lersek@redhat.com X-Gm-Message-State: wqemko6TgvZIXGB55Ig8rGz5x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1605783257; bh=4iyPaDS3rfsX6uhi1fLSNTD8FIwlyxvz682EinpcTR4=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=xMCvRBQwj/u9m2VenUObG/XtCWuTnS8v9xCzNjzbiGOgqc7tk9Kmj7HmNgH+v5JZGVB saQwFxRvESzzOZFD2TegUj377s+AZP36fqtVz5ILfor9yUMq0+zFvhnnliGh3TBSwRvRu FeOteItFewyrZxe1iuyKe1DhfLxs0p+67T4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" FindChildNode() has two callers: GetSection(), and FindChildNode() itself. - At the GetSection() call site, a positive (i.e., nonzero) SectionInstance is passed. This is because GetSection() takes a zero-based (UINTN) SectionInstance, and then passes Instance=3D(SectionInstance+1) to FindChildNode(). - For reaching the recursive FindChildNode() call site, a section type mismatch, or a section instance mismatch, is necessary. This means, respectively, that SectionInstance will either not have been decreased, or not to zero anyway, at the recursive FindChildNode() call site. Add two ASSERT()s to FindChildNode(), for expressing the (SectionSize>0) invariant. In turn, the invariant provides the explanation why, after the recursive call, a zero SectionInstance implies success. Capture it in a comment. Cc: Dandan Bi Cc: Hao A Wu Cc: Jian J Wang Cc: Liming Gao Cc: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Laszlo Ersek Reviewed-by: Liming Gao Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c | 23 +++++= ++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.= c b/MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c index d678166db475..d7f7ef427422 100644 --- a/MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c +++ b/MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c @@ -952,8 +952,8 @@ CreateChildNode ( search. @param SearchType Indicates the type of section to search f= or. @param SectionInstance Indicates which instance of section to fi= nd. - This is an in/out parameter to deal with - recursions. + This is an in/out parameter and it is 1-b= ased, + to deal with recursions. @param SectionDefinitionGuid Guid of section definition @param FoundChild Output indicating the child node that is = found. @param FoundStream Output indicating which section stream th= e child @@ -988,6 +988,8 @@ FindChildNode ( EFI_STATUS ErrorStatus; EFI_STATUS Status; =20 + ASSERT (*SectionInstance > 0); + CurrentChildNode =3D NULL; ErrorStatus =3D EFI_NOT_FOUND; =20 @@ -1037,6 +1039,11 @@ FindChildNode ( } } =20 + // + // Type mismatch, or we haven't found the desired instance yet. + // + ASSERT (*SectionInstance > 0); + if (CurrentChildNode->EncapsulatedStreamHandle !=3D NULL_STREAM_HANDLE= ) { // // If the current node is an encapsulating node, recurse into it... @@ -1050,16 +1057,20 @@ FindChildNode ( &RecursedFoundStream, AuthenticationStatus ); - // - // If the status is not EFI_SUCCESS, just save the error code and co= ntinue - // to find the request child node in the rest stream. - // if (*SectionInstance =3D=3D 0) { + // + // The recursive FindChildNode() call decreased (*SectionInstance)= to + // zero. + // ASSERT_EFI_ERROR (Status); *FoundChild =3D RecursedChildNode; *FoundStream =3D RecursedFoundStream; return EFI_SUCCESS; } else { + // + // If the status is not EFI_SUCCESS, just save the error code and + // continue to find the request child node in the rest stream. + // ErrorStatus =3D Status; } } else if ((CurrentChildNode->Type =3D=3D EFI_SECTION_GUID_DEFINED) &&= (SearchType !=3D EFI_SECTION_GUID_DEFINED)) { --=20 2.19.1.3.g30247aa5d201 -=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 (#67705): https://edk2.groups.io/g/devel/message/67705 Mute This Topic: https://groups.io/mt/78362187/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-