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 54613941888 for ; Tue, 7 Nov 2023 16:48:45 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=ORzhJXwbKZWHCmY1iC69dZj087g5YIkQ+QnVBKdfITg=; c=relaxed/simple; d=groups.io; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From:In-Reply-To:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1699375723; v=1; b=h+CF2Kf0UZGpSX0lOn5TYq9Us+Vv9m1Wp0wk/Z9W3VCTx5FGWRAI4+w6oPCPz8EM6/+RQt9Y Oj9/NAuillSmKl+QpSPVaAUmwelDNsT//FE0GM/c/+oaZn7Bz4xJ3B1BR+E8YLidpOJpNjv2uFA lDUoIUnZmTILcja15y6+6OCQ= X-Received: by 127.0.0.2 with SMTP id gi8JYY7687511xSJDDjJqHEv; Tue, 07 Nov 2023 08:48:43 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web10.16007.1699375723212201600 for ; Tue, 07 Nov 2023 08:48:43 -0800 X-Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-220--Rk97i17P5-NtfVpgTcYbQ-1; Tue, 07 Nov 2023 11:48:39 -0500 X-MC-Unique: -Rk97i17P5-NtfVpgTcYbQ-1 X-Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B3E9F88D4E8; Tue, 7 Nov 2023 16:48:38 +0000 (UTC) X-Received: from [10.39.193.64] (unknown [10.39.193.64]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 065A2492BE7; Tue, 7 Nov 2023 16:48:37 +0000 (UTC) Message-ID: Date: Tue, 7 Nov 2023 17:48:36 +0100 MIME-Version: 1.0 Subject: Re: [edk2-devel] [PATCH v2 4/5] MdeModulePkg/Bus/Pci/PciBusDxe: Fix NULL_RETURNS Coverity issue To: devel@edk2.groups.io, rsingh@ventanamicro.com Cc: Ray Ni , Veeresh Sangolli References: <20231107061959.113213-1-rsingh@ventanamicro.com> <20231107061959.113213-5-rsingh@ventanamicro.com> From: "Laszlo Ersek" In-Reply-To: <20231107061959.113213-5-rsingh@ventanamicro.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.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,lersek@redhat.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: craFMPZHSbzzO5fbrLItdQc4x7686176AA= Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=h+CF2Kf0; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=redhat.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 On 11/7/23 07:19, Ranbir Singh wrote: > From: Ranbir Singh >=20 > The function StartPciDevices has a check >=20 > ASSERT (RootBridge !=3D NULL); >=20 > but this comes into play only in DEBUG mode. In Release mode, there > is no handling if the RootBridge value is NULL and the code proceeds > to unconditionally dereference "RootBridge" which will lead to CRASH. >=20 > Hence, for safety add NULL pointer checks always and return > EFI_NOT_READY if RootBridge value is NULL which is one of the return > values as mentioned in the function description header. >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4239 >=20 > Cc: Ray Ni > Co-authored-by: Veeresh Sangolli > Signed-off-by: Ranbir Singh > Signed-off-by: Ranbir Singh > --- > MdeModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) >=20 > diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c b/MdeModul= ePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c > index 581e9075ad41..3de80d98370e 100644 > --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c > +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c > @@ -772,7 +772,10 @@ StartPciDevices ( > LIST_ENTRY *CurrentLink; > =20 > RootBridge =3D GetRootBridgeByHandle (Controller); > - ASSERT (RootBridge !=3D NULL); > + if (RootBridge =3D=3D NULL) { > + return EFI_NOT_READY; > + } > + > ThisHostBridge =3D RootBridge->PciRootBridgeIo->ParentHandle; > =20 > CurrentLink =3D mPciDevicePool.ForwardLink; I don't think this is a good fix. There is one call site, namely in PciBusDriverBindingStart(). That call site does not check the return value. (Of course /s) I think that this ASSERT() can indeed never fail. Therefore I suggest CpuDeadLoop() instead. If you insist that CpuDeadLoop() is "too risky" here, then the patch is acceptable, but then the StartPciDevices() call site in PciBusDriverBindingStart() must check the error properly: we must not install "gEfiPciEnumerationCompleteProtocolGuid", and the function must propagate the error outwards. Laszlo -=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 (#110865): https://edk2.groups.io/g/devel/message/110865 Mute This Topic: https://groups.io/mt/102438320/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/19134562= 12/xyzzy [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-