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 6B670AC0983 for ; Fri, 10 Nov 2023 06:11:34 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=B5fyzYL7WD3vbPuPfLuBR0FU2pEGAFnhqMuHN7vZOmE=; 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=1699596692; v=1; b=T7gH0UJ6RtWaMubVA3TCz0d2wU9x3HtX/6wXYHL/2UKsl2x/OBk7l8jknZifvz6o5xs2CCrP 8ublzULOWXK7nofyYeSgIeiFkPwNiJToMHZ5fo1bmUzk5Rp6/7MbNXAcZcY8l0xIgpfS9Qieomi aQ3F1qn7B5tptuVXTYWqLAGg= X-Received: by 127.0.0.2 with SMTP id BwV9YY7687511xJ0LF3EgQJ0; Thu, 09 Nov 2023 22:11:32 -0800 X-Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by mx.groups.io with SMTP id smtpd.web10.22303.1699596692086808369 for ; Thu, 09 Nov 2023 22:11:32 -0800 X-Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-5be264b0184so196903a12.3 for ; Thu, 09 Nov 2023 22:11:32 -0800 (PST) X-Gm-Message-State: 1kNh1rc5q4la1GRjV01wUhNsx7686176AA= X-Google-Smtp-Source: AGHT+IFDMcQw+jIu7XhTGxbjv12mCCca87zOgSj0H5xKiTdTnvNzMXirXFPo06aVbfDg1zsjWyVyttmbv7Tycrltxs4= X-Received: by 2002:a05:6a20:6a1d:b0:13a:e955:d958 with SMTP id p29-20020a056a206a1d00b0013ae955d958mr7832419pzk.7.1699596691076; Thu, 09 Nov 2023 22:11:31 -0800 (PST) MIME-Version: 1.0 References: <20231107061959.113213-1-rsingh@ventanamicro.com> <20231107061959.113213-5-rsingh@ventanamicro.com> In-Reply-To: From: "Ranbir Singh" Date: Fri, 10 Nov 2023 11:41:20 +0530 Message-ID: Subject: Re: [edk2-devel] [PATCH v2 4/5] MdeModulePkg/Bus/Pci/PciBusDxe: Fix NULL_RETURNS Coverity issue To: Laszlo Ersek Cc: devel@edk2.groups.io, Ray Ni , Veeresh Sangolli 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,rsingh@ventanamicro.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Type: multipart/alternative; boundary="000000000000088bd10609c6310c" X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=T7gH0UJ6; dmarc=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 --000000000000088bd10609c6310c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable EFI_NOT_READY was listed as one of the error return values in the function header of StartPciDevices(). So, I considered it here. Maybe we can go by a dual approach, including CpuDeadLoop() in StartPciDevices() as well as add return value check at the call site in PciBusDriverBindingStart(). On Tue, Nov 7, 2023 at 10:18=E2=80=AFPM Laszlo Ersek wr= ote: > On 11/7/23 07:19, Ranbir Singh wrote: > > From: Ranbir Singh > > > > The function StartPciDevices has a check > > > > ASSERT (RootBridge !=3D NULL); > > > > 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. > > > > 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. > > > > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4239 > > > > 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(-) > > > > diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c > b/MdeModulePkg/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; > > > > RootBridge =3D GetRootBridgeByHandle (Controller); > > - ASSERT (RootBridge !=3D NULL); > > + if (RootBridge =3D=3D NULL) { > > + return EFI_NOT_READY; > > + } > > + > > ThisHostBridge =3D RootBridge->PciRootBridgeIo->ParentHandle; > > > > 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 (#111017): https://edk2.groups.io/g/devel/message/111017 Mute This Topic: https://groups.io/mt/102438320/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- --000000000000088bd10609c6310c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
EFI_NOT_READY was listed as one of the error return values= in the function header of StartPciDevices(). So, I considered it here.
=

Maybe we can go by a dual approach, including CpuDeadLo= op() in StartPciDevices() as well as add return value check at the call sit= e in PciBusDriverBindingStart().

=
On Tue, Nov 7, 2023 at 10:18=E2=80=AF= PM Laszlo Ersek <lersek@redhat.com<= /a>> wrote:
O= n 11/7/23 07:19, Ranbir Singh wrote:
> From: Ranbir Singh <Ranbir.Singh3@Dell.com>
>
> The function StartPciDevices has a check
>
>=C2=A0 =C2=A0 =C2=A0ASSERT (RootBridge !=3D NULL);
>
> 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.
>
> 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.
>
> REF:
https://bugzilla.tianocore.org/show_b= ug.cgi?id=3D4239
>
> Cc: Ray Ni <r= ay.ni@intel.com>
> Co-authored-by: Veeresh Sangolli <veeresh.sangolli@dellteam.com>
> Signed-off-by: Ranbir Singh <Ranbir.Singh3@Dell.com>
> Signed-off-by: Ranbir Singh <rsingh@ventanamicro.com>
> ---
>=C2=A0 MdeModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c | 5 ++++-
>=C2=A0 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c b/MdeMo= dulePkg/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 (
>=C2=A0 =C2=A0 LIST_ENTRY=C2=A0 =C2=A0 =C2=A0*CurrentLink;
>=C2=A0
>=C2=A0 =C2=A0 RootBridge =3D GetRootBridgeByHandle (Controller);
> -=C2=A0 ASSERT (RootBridge !=3D NULL);
> +=C2=A0 if (RootBridge =3D=3D NULL) {
> +=C2=A0 =C2=A0 return EFI_NOT_READY;
> +=C2=A0 }
> +
>=C2=A0 =C2=A0 ThisHostBridge =3D RootBridge->PciRootBridgeIo->Par= entHandle;
>=C2=A0
>=C2=A0 =C2=A0 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 pa= tch is
acceptable, but then the StartPciDevices() call site in
PciBusDriverBindingStart() must check the error properly: we must not
install "gEfiPciEnumerationCompleteProtocolGuid", and the functio= n must
propagate the error outwards.

Laszlo

_._,_._,_

Groups.io Links:

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

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

_._,_._,_
--000000000000088bd10609c6310c--