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=CsDaM3nA; spf=pass (domain: arm.com, ip: 40.107.8.75, mailfrom: krzysztof.koch@arm.com) Received: from EUR04-VI1-obe.outbound.protection.outlook.com (EUR04-VI1-obe.outbound.protection.outlook.com [40.107.8.75]) by groups.io with SMTP; Thu, 18 Jul 2019 05:31:58 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QUnYQM6VdCImeMkqo4JlrEsDxvTe4Dxiu8KLVQNTgGNosqT85xIacOsXAXNHW9pMjRrh4TJ125f0K+SHaf0CkadQAt1sYQaFPulvhKuZK+RcXJKXOU2GiO7VXPx4C0nyicpgHvjBgZ/y97MmrTA2054MIuhorbj4AM6AirAqkTheQ70JXEHv6zR9FYzbuNDdk41d5pX/Wnmk7q2jO9PjwD7J4B2NcV7oAdc/anE7ks62JwXvZetVcNILf2MvWUZ7WjuCg/PfOhpLbKWcy41ban6vM3jRwYcFVj5lJdQZmSV+vQRp5Ct4RaEZNUVcJl012N84X7LnashyqgyVESimUQ== 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=MN82JiK8kS2UmaxB3vvOBaq8Gz52s8/x5p0fbAbJlLY=; b=FNC21NdULyDv2isCxg7zg5Y+M6iFzhKV3r/gTMsQIYyjBONI9eeWsDtlnEuRz7Vr/A3cpcw0Y8NPEUmhZOv20Vm7VmPfAhjizZ4OaXSRFd55JtM2oR9em0dmnr1GdWM4r5J5SJyZZJCPz2Lo17pks9Ahwz30/DMxp9lkSJxwyLafu8y7lfGXy6W1szB3OYyKMXpRaQ6T5ddS52Gc473NvVN0LGeWt6VNFI5O84+gK/4nW2IJIwKEpy700WpYHFmJEmAXf9KxcpdWkggxpNbJ8GsTBxqtFOgAlE0yZgjumYxYstrkAUmPMAhuauYRHxdsPMcuuOL9droif93a800xkg== 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=MN82JiK8kS2UmaxB3vvOBaq8Gz52s8/x5p0fbAbJlLY=; b=CsDaM3nAl92UWDvcxSHD/tHe2UMGBbY9GMDklx3SVpCVY1/FX+zze7F0MJ4PYT0ZfevC5yfvyIVfAV4TNz3gvN1yr1tRN80BG4QrgI2OQrzgP6GKAJ9IjWqzf10w1qsM4P+66FR8piGWcBPLlK1z9sr/wDRAN1x4OUXCfGtWtFg= Received: from VE1PR08CA0005.eurprd08.prod.outlook.com (2603:10a6:803:104::18) by DB6PR0802MB2600.eurprd08.prod.outlook.com (2603:10a6:4:a1::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2073.14; Thu, 18 Jul 2019 12:31:54 +0000 Received: from AM5EUR03FT020.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e08::201) by VE1PR08CA0005.outlook.office365.com (2603:10a6:803:104::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2094.12 via Frontend Transport; Thu, 18 Jul 2019 12:31:53 +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 AM5EUR03FT020.mail.protection.outlook.com (10.152.16.116) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.2052.18 via Frontend Transport; Thu, 18 Jul 2019 12:31:52 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1415.2; Thu, 18 Jul 2019 12:31:50 +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; Thu, 18 Jul 2019 12:31:50 +0000 From: "Krzysztof Koch" To: CC: , , , , , Subject: [PATCH v1 1/6] ShellPkg: acpiview: Allow passing buffer length to DumpGasStruct() Date: Thu, 18 Jul 2019 13:31:37 +0100 Message-ID: <20190718123142.5696-2-krzysztof.koch@arm.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: <20190718123142.5696-1-krzysztof.koch@arm.com> References: <20190718123142.5696-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)(376002)(136003)(346002)(396003)(39860400002)(2980300002)(199004)(189003)(47776003)(2906002)(356004)(6666004)(5660300002)(76176011)(186003)(4326008)(1076003)(7696005)(53416004)(6916009)(26005)(54906003)(486006)(51416003)(16586007)(48376002)(86362001)(476003)(2351001)(8676002)(44832011)(336012)(8936002)(50226002)(68736007)(14444005)(426003)(63370400001)(53936002)(81166006)(63350400001)(446003)(81156014)(70586007)(316002)(2616005)(478600001)(70206006)(126002)(305945005)(11346002)(36756003)(50466002);DIR:OUT;SFP:1101;SCL:1;SRVR:DB6PR0802MB2600;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: 8e43cf64-ccc1-4d5a-ad65-08d70b7be99a X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(2017052603328);SRVR:DB6PR0802MB2600; X-MS-TrafficTypeDiagnostic: DB6PR0802MB2600: X-Microsoft-Antispam-PRVS: NoDisclaimer: True X-MS-Oob-TLC-OOBClassifiers: OLM:5236; X-Forefront-PRVS: 01026E1310 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: G7lVJBlTYD8b91fAKT/cMfUoReiqeGNEEz0E8y24r3uJdSIf1PJ2IzDnqX5lTtt/shGBubEsLgFfB4YEmkkYorwbvpEr+4K5sZoo+p8iLKnWYO4DblU4kQBqi0aACYgFZgO+sIzXo6hmDxvQHbD6OsVDfiuIQW4gVAL4kcoSjfVyQu2q2J8ISI8F/WojrqSfPy16oOz5sHlQQqjCzKyVA4BEnuPOs+otKgNM1CRApjKh1ZRiKK0rrHOgoK5xADe9Fd0Hei9Xu/0sQvx4J3ih63zwXWulSTVjUP+1EMSz/rHJcF1MyLHc7ZeNbmVoA5icCVoqEbvQ2reg0FfLB9e5qVmAmQo6mHbo/OYFhMf3FdJ4k8IiHmRiUwI1UpyV4Pwtg33i84A8mlJfXFduSGoy1rf5wkC2TC1rotWXQ0xox8c= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jul 2019 12:31:52.3004 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8e43cf64-ccc1-4d5a-ad65-08d70b7be99a 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: DB6PR0802MB2600 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: 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 8de5ebf74775bab8e765849cba6ef4eb6f659a5a..2c47a3f848aa2dd512c53343ecf1c3c285173dd6 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c @@ -164,7 +164,7 @@ DumpDbgDeviceInfo ( AddrSize = (UINT32*)(Ptr + (*AddrSizeOffset)); while (Index < (*GasCount)) { PrintFieldName (4, L"BaseAddressRegister"); - DumpGasStruct (DataPtr, 4); + DumpGasStruct (DataPtr, 4, *DbgDevInfoLen); PrintFieldName (4, L"Address Size"); Print (L"0x%x\n", AddrSize[Index]); DataPtr += GAS_LENGTH; -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'