From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (EUR04-VI1-obe.outbound.protection.outlook.com [40.107.8.89]) by mx.groups.io with SMTP id smtpd.web09.3590.1582194050818616307 for ; Thu, 20 Feb 2020 02:20:51 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@nxp.com header.s=selector2 header.b=ej0IYjuv; spf=pass (domain: nxp.com, ip: 40.107.8.89, mailfrom: gaurav.jain@nxp.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KMhZjJhb48YrcNXH3FQeJrINLTpgjKiuGGKvnW/i4X19QSXI/Lh8U0hdW8gA1h6bWzmLI2usRHHXHyW4IC0ddkDrt/S76IudGMHfVbSSYX/Vw58BSQYqEH3nWEdZxfE8sKkUTBlYPhv6ZehhpJSYXozvea5t6bnPcJBpLyXSxsxt9MUmIwrVLrHspzsD2vlN3EDtq/ll0LTDRxd/8XkFwNkqZdtkwmWesK6WO+Lj45bVoqHMWyi2LAR9PF6KOgzhPSABZU0vWaWrcw7mmlan0UH3idZZ1OXLNoNSHA3E9xPjVm709vtdq5XitCYmdhQUPQzMTZ/qvLE19m7Dz0I20g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2+7RuBIHqaFPaLVQuc0P9AuRtuMmNvpqOVUpToHvVyM=; b=id3sFMqXdH4eUpMisuGeJRVWbXvrVDnnojenckjyuIx5ypDjy71zCRmgJ70hxMUMlbBaHz+AKM80Ufu2AqnC1AW3cfFxLpK82s+PftivY6QoQTZlkGTxZGBhoJlsiZzUdDLe4o1WNm017WdEWZR5BvlNC/rX7q3O8ssckpF630Nf4+B64+d9aMb42AAnOyqdvsTL8XahDcb00YnHfPZLamGnyL35oI7nd7JQv0JEbfV/bFbxr1KJRNWAeeBEs7v9woGKLFl2oyAWBhyfmRcy4a4NWS6XFLGS9gdxp5DcDGPuTKJY3wQKQtpVj46i4LpsiY1iHYhWwzQyumHZQZrqWA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2+7RuBIHqaFPaLVQuc0P9AuRtuMmNvpqOVUpToHvVyM=; b=ej0IYjuvzbzm+HpRjwTXVf7/JvByv/QIKCt4gcnlFg3aGL7GdfPlJWCqGyrwCNiRoG+6Oyq0QkUruCn167GYjOHxH/fqQYRIdpp5X/nqcIZCfZ8Q1iObGX4q9QHcV1jKqf0bt6SgPx+UhIQ43GgrFUBdWLOZPjec6ZpiwnjTo1k= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=gaurav.jain@nxp.com; Received: from DB7PR04MB4091.eurprd04.prod.outlook.com (52.134.110.144) by DB7PR04MB4363.eurprd04.prod.outlook.com (52.135.131.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2729.22; Thu, 20 Feb 2020 10:20:48 +0000 Received: from DB7PR04MB4091.eurprd04.prod.outlook.com ([fe80::183:969:2508:3c92]) by DB7PR04MB4091.eurprd04.prod.outlook.com ([fe80::183:969:2508:3c92%6]) with mapi id 15.20.2729.033; Thu, 20 Feb 2020 10:20:48 +0000 From: "Gaurav Jain" To: devel@edk2.groups.io CC: Jian J Wang , Hao A Wu , Ray Ni , Ard Biesheuvel , Pankaj Bansal , Gaurav Jain Subject: [PATCH v2 1/1] MdeModulePkg/Pci: Fixed Asserts in SCT PCIIO Protocol Test. Date: Thu, 20 Feb 2020 21:10:30 +0530 Message-ID: <20200220154030.5068-1-gaurav.jain@nxp.com> X-Mailer: git-send-email 2.17.1 X-ClientProxiedBy: SG2PR01CA0153.apcprd01.prod.exchangelabs.com (2603:1096:4:8f::33) To DB7PR04MB4091.eurprd04.prod.outlook.com (2603:10a6:5:1e::16) Return-Path: gaurav.jain@nxp.com MIME-Version: 1.0 Received: from uefi-workstation.ap.freescale.net (92.120.1.69) by SG2PR01CA0153.apcprd01.prod.exchangelabs.com (2603:1096:4:8f::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2750.18 via Frontend Transport; Thu, 20 Feb 2020 10:20:45 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [92.120.1.69] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 0c37344c-4365-498a-868b-08d7b5ee8dc5 X-MS-TrafficTypeDiagnostic: DB7PR04MB4363:|DB7PR04MB4363: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2276; X-Forefront-PRVS: 031996B7EF X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4636009)(136003)(396003)(366004)(39860400002)(376002)(346002)(189003)(199004)(8936002)(1076003)(2906002)(6506007)(66556008)(6916009)(478600001)(52116002)(66476007)(54906003)(8676002)(81156014)(81166006)(4326008)(26005)(6666004)(16526019)(36756003)(6512007)(186003)(5660300002)(956004)(44832011)(2616005)(86362001)(6486002)(66946007)(316002);DIR:OUT;SFP:1101;SCL:1;SRVR:DB7PR04MB4363;H:DB7PR04MB4091.eurprd04.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; Received-SPF: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mOP3skSIR6iKvvFAO/hqONWbiEd775XRry4xej61WQc24unNFIZ3JxhzsWu6+N7PeB8AECy9YLG+jjcteytO0M1A65Nszezei+f7xY0xfXwp2po6Fs+/GAzJBSFOKcObWjJLK0fe7un1rSlpXWSceV9BSQMtdayXsOcfJONQ1GcBTuCmv1wwVWiXejJKpFAg3sjsl/IVWc7iuDhDBsggJO6admEdFmcycht6WF75n0mEPR/bhXD5Np9nmekNMCMDCbGeK+7gXX5gMk+K9ALcNVUXiZ55nZ97m5kLrIqVFBC2pczlB4YlXphd7cgkJ1oTIDe/34TE3mh/vG4AWJcjIJChZqZom/Q8tWGv6+tS2PZ4ifYoCN3gvEjYR7MNN73hFy66Vi8N6T4ikFyRY4Qw4dddSCJnIbXc5zcJLVbsYeZaeQ3V22Bl1DSMqchm7Xwq X-MS-Exchange-AntiSpam-MessageData: HoGVa3i60REsui3S31l0KrAtIRzpBM9/cVccAmNriuVYjg903oBxMrB0YyF0SYP7uxIuqSHAXUE5EBDaKr3r7CWlvUyT3sDIXOAjfS9Euprjop6iTpfTOoh7bkzw1ZRFK3yuTvuPSFXemcEDkolmlA== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0c37344c-4365-498a-868b-08d7b5ee8dc5 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Feb 2020 10:20:48.3969 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: dSUY8H9j55zqJCreS4zYo/AG0WckLnk/mNFku4RItrlZjBR2HVk9fvD9egFaiIOgmkSHguBnhpvthfcIH3wRrg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR04MB4363 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain ASSERT in PollMem_Conf, CopyMem_Conf, SetBarAttributes_Conf Conformance Test. SCT Test expect return as Invalid Parameter or Unsupported. Added Checks for Function Parameters. return Invalid or Unsupported if Check fails. Added Checks in PciIoPollIo(), PciIoIoRead() PciIoIoWrite() Signed-off-by: Gaurav Jain --- Notes: v2 - Reverted ASSERT(FALSE) code. - Added Checks for Width, BarIndex, Buffer, Address range in PciIoIoRead, PciIoIoWrite. - Added Checks for Width, BarIndex, Result, Address range in PciIoPollIo, PciIoPollMem, PciIoCopyMem. - Added Checks for Attributes, BarIndex, Address range in PciIoSetBarAttributes. .../NonDiscoverablePciDeviceIo.c | 180 ++++++++++++++++++ 1 file changed, 180 insertions(+) diff --git a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverab= lePciDeviceIo.c b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDisco= verablePciDeviceIo.c index 2d55c9699322..4dd804356021 100644 --- a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDe= viceIo.c +++ b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDe= viceIo.c @@ -93,6 +93,35 @@ PciIoPollMem ( OUT UINT64 *Result ) { + NON_DISCOVERABLE_PCI_DEVICE *Dev; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Desc; + UINTN Count; + EFI_STATUS Status; + + if ((UINT32)Width > EfiPciIoWidthUint64) { + return EFI_INVALID_PARAMETER; + } + + if (BarIndex >=3D PCI_MAX_BAR) { + return EFI_UNSUPPORTED; + } + + if (Result =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + Dev =3D NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); + Count =3D 1; + + Status =3D GetBarResource (Dev, BarIndex, &Desc); + if (EFI_ERROR (Status)) { + return Status; + } + + if (Offset + (Count << (Width & 0x3)) > Desc->AddrLen) { + return EFI_UNSUPPORTED; + } + ASSERT (FALSE); return EFI_UNSUPPORTED; } @@ -126,6 +155,35 @@ PciIoPollIo ( OUT UINT64 *Result ) { + NON_DISCOVERABLE_PCI_DEVICE *Dev; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Desc; + UINTN Count; + EFI_STATUS Status; + + if ((UINT32)Width > EfiPciIoWidthUint64) { + return EFI_INVALID_PARAMETER; + } + + if (BarIndex >=3D PCI_MAX_BAR) { + return EFI_UNSUPPORTED; + } + + if (Result =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + Dev =3D NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); + Count =3D 1; + + Status =3D GetBarResource (Dev, BarIndex, &Desc); + if (EFI_ERROR (Status)) { + return Status; + } + + if (Offset + (Count << (Width & 0x3)) > Desc->AddrLen) { + return EFI_UNSUPPORTED; + } + ASSERT (FALSE); return EFI_UNSUPPORTED; } @@ -396,6 +454,33 @@ PciIoIoRead ( IN OUT VOID *Buffer ) { + NON_DISCOVERABLE_PCI_DEVICE *Dev; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Desc; + EFI_STATUS Status; + + if ((UINT32)Width > EfiPciIoWidthUint64) { + return EFI_INVALID_PARAMETER; + } + + if (BarIndex >=3D PCI_MAX_BAR) { + return EFI_UNSUPPORTED; + } + + if (Buffer =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + Dev =3D NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); + + Status =3D GetBarResource (Dev, BarIndex, &Desc); + if (EFI_ERROR (Status)) { + return Status; + } + + if (Offset + (Count << (Width & 0x3)) > Desc->AddrLen) { + return EFI_UNSUPPORTED; + } + ASSERT (FALSE); return EFI_UNSUPPORTED; } @@ -425,6 +510,33 @@ PciIoIoWrite ( IN OUT VOID *Buffer ) { + NON_DISCOVERABLE_PCI_DEVICE *Dev; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Desc; + EFI_STATUS Status; + + if ((UINT32)Width > EfiPciIoWidthUint64) { + return EFI_INVALID_PARAMETER; + } + + if (BarIndex >=3D PCI_MAX_BAR) { + return EFI_UNSUPPORTED; + } + + if (Buffer =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + Dev =3D NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); + + Status =3D GetBarResource (Dev, BarIndex, &Desc); + if (EFI_ERROR (Status)) { + return Status; + } + + if (Offset + (Count << (Width & 0x3)) > Desc->AddrLen) { + return EFI_UNSUPPORTED; + } + ASSERT (FALSE); return EFI_UNSUPPORTED; } @@ -556,6 +668,40 @@ PciIoCopyMem ( IN UINTN Count ) { + NON_DISCOVERABLE_PCI_DEVICE *Dev; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *DestDesc; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *SrcDesc; + EFI_STATUS Status; + + if ((UINT32)Width > EfiPciIoWidthUint64) { + return EFI_INVALID_PARAMETER; + } + + if (DestBarIndex >=3D PCI_MAX_BAR || + SrcBarIndex >=3D PCI_MAX_BAR) { + return EFI_UNSUPPORTED; + } + + Dev =3D NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); + + Status =3D GetBarResource (Dev, DestBarIndex, &DestDesc); + if (EFI_ERROR (Status)) { + return Status; + } + + if (DestOffset + (Count << (Width & 0x3)) > DestDesc->AddrLen) { + return EFI_UNSUPPORTED; + } + + Status =3D GetBarResource (Dev, SrcBarIndex, &SrcDesc); + if (EFI_ERROR (Status)) { + return Status; + } + + if (SrcOffset + (Count << (Width & 0x3)) > SrcDesc->AddrLen) { + return EFI_UNSUPPORTED; + } + ASSERT (FALSE); return EFI_UNSUPPORTED; } @@ -1414,6 +1560,40 @@ PciIoSetBarAttributes ( IN OUT UINT64 *Length ) { + NON_DISCOVERABLE_PCI_DEVICE *Dev; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Desc; + EFI_PCI_IO_PROTOCOL_WIDTH Width; + UINTN Count; + EFI_STATUS Status; + + #define DEV_SUPPORTED_ATTRIBUTES \ + (EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE) + + if ((Attributes & (~DEV_SUPPORTED_ATTRIBUTES)) !=3D 0) { + return EFI_UNSUPPORTED; + } + + if (BarIndex >=3D PCI_MAX_BAR) { + return EFI_UNSUPPORTED; + } + + if (Offset =3D=3D NULL || Length =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + Dev =3D NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); + Width =3D EfiPciIoWidthUint8; + Count =3D (UINT32) *Length; + + Status =3D GetBarResource(Dev, BarIndex, &Desc); + if (EFI_ERROR (Status)) { + return Status; + } + + if (*Offset + (Count << (Width & 0x3)) > Desc->AddrLen) { + return EFI_UNSUPPORTED; + } + ASSERT (FALSE); return EFI_UNSUPPORTED; } --=20 2.17.1