From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=CYH+EpRc; spf=pass (domain: arm.com, ip: 40.107.0.76, mailfrom: krzysztof.koch@arm.com) Received: from EUR02-AM5-obe.outbound.protection.outlook.com (EUR02-AM5-obe.outbound.protection.outlook.com [40.107.0.76]) by groups.io with SMTP; Mon, 22 Jul 2019 00:50:51 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Lu4Yivr5dPEG6yPOHu7r7Z8Yt91TE4F2hQHTnMZM/0UeTFBx/KP42FA0VtEsDelQIydEkMBLTM31IOR4mcunDwwB2IYoIS8hGuKCie1bJtVF0P/dclgHKNgrgAM59IbzNUc2YJX1H6tSqGpzi+ejBgXhiKkotpzBnywALA4jQhGzr5SYA7HSi8RdhHvEaQ6zaOcOH9MN8qKvL1quh5JeSgdBvKsnRZ8R7SrNIKWjB2JdzaB+yF4frRMP6z6y1DQ4ETHMxWzk1/YIuMT4Ga0COp0wDvGV4pOcM0gCT+BvtRoRQ/NUJLBck/8/lkX9aiGf/O3dKyde9RONjl/XF7a53w== 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=nGRRsdv3tyjUUpm3jLQJVAcXEyzdZS4eT9eMia9X8U8=; b=RDeqNzMNFY6UmYzHQE4RUxg+OGCcYRVb6E7TM19TbtJlNdSjZsob9z5+dw9HaJUaDgjc2bBhDmfObUjER8V0kG0hZvOjT1+oogk67owcKkYZsexZ62H8QHXL6IvAlCHEYLo3s2wMHs7vfY/ScxjB7X0zf+HyudfOyW74NXZe7C75Uy62s9mQfooqJxjQSU2ET3+HIaNn3b+efScmbAg2TB7KgiZu99tWZtCUj/uYnHuPsWpR59+f7PdzebIBjCwE8X36imdVwhTKWG+AsB/rFghoXywNtCnb24H9uqcUA5xSzoTkvXi5KNfjSZc/uJC4sU1w0AgyJXvrkmJnik3VEQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1;spf=temperror (sender ip is 40.67.248.234) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=arm.com;dmarc=temperror action=none header.from=arm.com;dkim=none (message not signed);arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nGRRsdv3tyjUUpm3jLQJVAcXEyzdZS4eT9eMia9X8U8=; b=CYH+EpRcf1YM1g3JI7cw6D4aEuAfHGn8nNQQRmxGSTkw7X/E9o1UT8fSFYYkmFw4ugmALmFr1KqoqpVmBUXc4cJjQxr2l2SMILCFy5Wpds9PDxT0eiEpHj259eYKvXFzYnzFcF1LXAB05WKPY3dfknItznuKakfq2bgdl1RzsGs= Received: from HE1PR0802CA0021.eurprd08.prod.outlook.com (2603:10a6:3:bd::31) by AM0PR08MB4948.eurprd08.prod.outlook.com (2603:10a6:208:163::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2094.16; Mon, 22 Jul 2019 07:50:47 +0000 Received: from DB5EUR03FT021.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e0a::205) by HE1PR0802CA0021.outlook.office365.com (2603:10a6:3:bd::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2094.14 via Frontend Transport; Mon, 22 Jul 2019 07:50:47 +0000 Authentication-Results: spf=temperror (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=temperror action=none header.from=arm.com; Received-SPF: TempError (protection.outlook.com: error in processing during lookup of arm.com: DNS Timeout) Received: from nebula.arm.com (40.67.248.234) by DB5EUR03FT021.mail.protection.outlook.com (10.152.20.238) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.2052.18 via Frontend Transport; Mon, 22 Jul 2019 07:50:45 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1415.2; Mon, 22 Jul 2019 07:50:35 +0000 Received: from E119924.Arm.com (10.1.199.124) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Mon, 22 Jul 2019 07:50:35 +0000 From: "Krzysztof Koch" To: CC: , , , , , Subject: [PATCH v2 1/6] ShellPkg: acpiview: Allow passing buffer length to DumpGasStruct() Date: Mon, 22 Jul 2019 08:50:21 +0100 Message-ID: <20190722075026.20244-2-krzysztof.koch@arm.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: <20190722075026.20244-1-krzysztof.koch@arm.com> References: <20190722075026.20244-1-krzysztof.koch@arm.com> Return-Path: Krzysztof.Koch@arm.com MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:40.67.248.234;IPV:NLI;CTRY:IE;EFV:NLI;SFV:NSPM;SFS:(10009020)(4636009)(39850400004)(396003)(376002)(346002)(136003)(2980300002)(199004)(189003)(8936002)(51416003)(2616005)(50226002)(53416004)(86362001)(7696005)(11346002)(478600001)(8676002)(426003)(5660300002)(63350400001)(70206006)(316002)(53936002)(186003)(26005)(446003)(76176011)(476003)(81156014)(336012)(81166006)(70586007)(63370400001)(126002)(50466002)(356004)(2906002)(6666004)(54906003)(47776003)(48376002)(14444005)(16586007)(2351001)(36756003)(44832011)(486006)(1076003)(68736007)(4326008)(305945005)(6916009);DIR:OUT;SFP:1101;SCL:1;SRVR:AM0PR08MB4948;H:nebula.arm.com;FPR:;SPF:TempError;LANG:en;PTR:InfoDomainNonexistent;A:1;MX:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c898fd1e-1735-48e7-9227-08d70e794def X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(2017052603328);SRVR:AM0PR08MB4948; X-MS-TrafficTypeDiagnostic: AM0PR08MB4948: X-Microsoft-Antispam-PRVS: NoDisclaimer: True X-MS-Oob-TLC-OOBClassifiers: OLM:5236; X-Forefront-PRVS: 01068D0A20 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: J/oT7+99kCYRlhK/DbSQk29BEE43Puf3seZgBpsTAkTH0RMLPpKgZI+M8NuXObD8yXF8iDc9+rDLtaVp5uROuiLNL/fmtFDo0zovcZG3So3+JMEIUUAm70cnNRTBhprzR0O6f529A3tSyIHZzZeKh8QsoGtkVlNnL97zViVJ4Btiw/ZLMGbktM0PB72abA+PpB3J8Gj0HsGs4wC05SCux8K/xRgiZDpLGVQ957nHNnJt1aslQNkO7T9mk8Uavm/470iAmKRyIO/S4L3kW8mvi8QeiGalh1Jnr2V3bYgpTQWTvSzrprFbZUgoSz1AzVaa5lBhxH8ML3YwDsnPcNvHIW2z3Gv8WMncD5uU2+X0pXc8fuxV/SaZSRXkQ3RL3fhsd0qPIMAlwpqqBVTXVPnNWzb+XyxCsbNkiGU+kPndqiI= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2019 07:50:45.7472 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c898fd1e-1735-48e7-9227-08d70e794def X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[40.67.248.234];Helo=[nebula.arm.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB4948 Content-Type: text/plain Modify the signature of the DumpGasStruct() function to include the buffer length parameter and to return the number of bytes parsed by the function. This way it becomes possible to prevent buffer overruns when dumping Generic Address Structure's (GAS) fields in the acpiview table parsers. Update all existing DumpGasStruct() calls in acpiview to add the length argument. Signed-off-by: Krzysztof Koch --- Notes: v2: - Pass GAS_LENGTH to DumpGasStruct() in DBG2 parser [Zhichao] v1: - Modify DumpGasStruct() signature [Krzysztof] ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c | 26 +++++++++++--------- ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h | 8 ++++-- ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c | 2 +- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c index 8b3153516d2b7d9b920ab2de0344c17798ac572c..2d6ff80e299eebe7853061d3db89332197c0dc0e 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c @@ -589,23 +589,27 @@ STATIC CONST ACPI_PARSER GasParser[] = { @param [in] Ptr Pointer to the start of the buffer. @param [in] Indent Number of spaces to indent the output. + @param [in] Length Length of the GAS structure buffer. + + @retval Number of bytes parsed. **/ -VOID +UINT32 EFIAPI DumpGasStruct ( IN UINT8* Ptr, - IN UINT32 Indent + IN UINT32 Indent, + IN UINT32 Length ) { Print (L"\n"); - ParseAcpi ( - TRUE, - Indent, - NULL, - Ptr, - GAS_LENGTH, - PARSER_PARAMS (GasParser) - ); + return ParseAcpi ( + TRUE, + Indent, + NULL, + Ptr, + Length, + PARSER_PARAMS (GasParser) + ); } /** @@ -621,7 +625,7 @@ DumpGas ( IN UINT8* Ptr ) { - DumpGasStruct (Ptr, 2); + DumpGasStruct (Ptr, 2, GAS_LENGTH); } /** diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h index 7657892d9fd2e2e14c6578611ff0cf1b6f6cd750..20ca358bddfa5953bfb1d1bebaebbf3079eaba01 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h @@ -405,12 +405,16 @@ ParseAcpi ( @param [in] Ptr Pointer to the start of the buffer. @param [in] Indent Number of spaces to indent the output. + @param [in] Length Length of the GAS structure buffer. + + @retval Number of bytes parsed. **/ -VOID +UINT32 EFIAPI DumpGasStruct ( IN UINT8* Ptr, - IN UINT32 Indent + IN UINT32 Indent, + IN UINT32 Length ); /** diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c index 1efcbd40f86efdabed2152540a415db8a950fb71..c6929695a1032c57761ef85002d6c51b7800ce23 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c @@ -134,7 +134,7 @@ DumpDbgDeviceInfo ( AddrSize = (UINT32*)(Ptr + (*AddrSizeOffset)); while (Index < (*GasCount)) { PrintFieldName (4, L"BaseAddressRegister"); - DumpGasStruct (DataPtr, 4); + DumpGasStruct (DataPtr, 4, GAS_LENGTH); PrintFieldName (4, L"Address Size"); Print (L"0x%x\n", AddrSize[Index]); DataPtr += GAS_LENGTH; -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'