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 2DF01D80D4E for ; Mon, 13 Nov 2023 16:57:17 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=GIAAVBc7vbsX4Xd+tS99VoFoDHfTswCASt0+Wv3zXaA=; 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=1699894635; v=1; b=DrnDH5XAjxyEUcd8V/k75hBXuYxfPO40RnlIdBchcVoPYTR1x/9ZV40fAZO7vhknLKu7aOTm vqJf+ZSpy14v2QmjQvE2qNxslrhm6I9AWbxELib3bvDYYM2ADkSChV1moM/qRKY6/hFg0QffbzK BaM6/LKKszwBqzxUXwLcBTSo= X-Received: by 127.0.0.2 with SMTP id wSZzYY7687511xarkfmNJUdW; Mon, 13 Nov 2023 08:57:15 -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.420.1699894635241000813 for ; Mon, 13 Nov 2023 08:57:15 -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-338-qPIRSxwjNdGWaeCc6IPC8w-1; Mon, 13 Nov 2023 11:57:12 -0500 X-MC-Unique: qPIRSxwjNdGWaeCc6IPC8w-1 X-Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 2C820811E94; Mon, 13 Nov 2023 16:57:12 +0000 (UTC) X-Received: from [10.39.192.220] (unknown [10.39.192.220]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6D229370; Mon, 13 Nov 2023 16:57:11 +0000 (UTC) Message-ID: <11bcc934-8230-e98e-9e15-58e991c9314a@redhat.com> Date: Mon, 13 Nov 2023 17:57:10 +0100 MIME-Version: 1.0 Subject: Re: [edk2-devel] [PATCH v3 1/2] MdeModulePkg/Bus/Pci/XhciDxe: Fix FORWARD_NULL Coverity issues To: devel@edk2.groups.io, rsingh@ventanamicro.com Cc: Ray Ni , Veeresh Sangolli References: <20231110052231.447797-1-rsingh@ventanamicro.com> <20231110052231.447797-2-rsingh@ventanamicro.com> From: "Laszlo Ersek" In-Reply-To: <20231110052231.447797-2-rsingh@ventanamicro.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 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: rP2GWD4p5JIBfTfwiZ3OzGOqx7686176AA= 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=DrnDH5XA; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=redhat.com (policy=none) On 11/10/23 06:22, Ranbir Singh wrote: > From: Ranbir Singh >=20 > The functions UsbHcGetHostAddrForPciAddr, UsbHcGetPciAddrForHostAddr > and UsbHcFreeMem do have >=20 > ASSERT ((Block !=3D NULL)); >=20 > statements after for loop, but these are applicable only in DEBUG mode. > In RELEASE mode, if for whatever reasons there is no match inside for > loop and the loop exits because of Block !=3D NULL; condition, then there > is no "Block" NULL pointer check afterwards and the code proceeds to do > dereferencing "Block" which will lead to CRASH. >=20 > Hence, for safety add NULL pointer checks always. >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4221 >=20 > Cc: Ray Ni > Co-authored-by: Veeresh Sangolli > Signed-off-by: Ranbir Singh > Signed-off-by: Ranbir Singh > --- > MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.c | 29 ++++++++++++++++++++ > 1 file changed, 29 insertions(+) >=20 > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.c b/MdeModulePkg/Bus/P= ci/XhciDxe/UsbHcMem.c > index b54187ec228e..597cbe4646e8 100644 > --- a/MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.c > +++ b/MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.c > @@ -267,6 +267,16 @@ UsbHcGetPciAddrForHostAddr ( > } > =20 > ASSERT ((Block !=3D NULL)); > + > + if (Block =3D=3D NULL) { > + // > + // Should never be here > + // > + DEBUG ((DEBUG_ERROR, "UsbHcGetPciAddrForHostAddr: Invalid host memor= y pointer passed\n")); > + CpuDeadLoop (); > + return 0; > + } > + > // > // calculate the pci memory address for host memory address. > // > @@ -322,6 +332,16 @@ UsbHcGetHostAddrForPciAddr ( > } > =20 > ASSERT ((Block !=3D NULL)); > + > + if (Block =3D=3D NULL) { > + // > + // Should never be here > + // > + DEBUG ((DEBUG_ERROR, "UsbHcGetHostAddrForPciAddr: Invalid pci memory= pointer passed\n")); > + CpuDeadLoop (); > + return 0; > + } > + > // > // calculate the pci memory address for host memory address. > // > @@ -603,6 +623,15 @@ UsbHcFreeMem ( > // > ASSERT (Block !=3D NULL); > =20 > + if (Block =3D=3D NULL) { > + // > + // Should never be here > + // > + DEBUG ((DEBUG_ERROR, "UsbHcFreeMem: Invalid memory pointer passed\n"= )); > + CpuDeadLoop (); > + return; > + } > + > // > // Release the current memory block if it is empty and not the head > // Reviewed-by: Laszlo Ersek -=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 (#111166): https://edk2.groups.io/g/devel/message/111166 Mute This Topic: https://groups.io/mt/102502055/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-