From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (NAM12-BN8-obe.outbound.protection.outlook.com [40.92.21.68]) by mx.groups.io with SMTP id smtpd.web10.345.1586551812665132627 for ; Fri, 10 Apr 2020 13:50:12 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@outlook.com header.s=selector1 header.b=QkuQUEXd; spf=pass (domain: outlook.com, ip: 40.92.21.68, mailfrom: michael.kubacki@outlook.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JvGztfQ+Tvu0dHwSP8HWkjfWvpV+xGUkHwIRoN3BsfXo20pFoF2sGPM/Cw6IKD+hzUxtnPDcEssKUbMer+sQR8VQCEc5m37dGk34zeibV/CIJbGjebpqnAOpvtDDv+DjI/HlYLWBoHckVIxD6QtmRwgJXTaBksHtBIH9PuizwAnbHKdArSbvZpCtJeErzxmrtZlw7tpDssrGKUS3oaNdmNwKIfZPjqpsRI8cgANuewOUq1lLzjDtUYwqEVOYmwP09hs5nb2KQN/JD2Tsu7Q/bFxbFpqQGOkyKgigzDYPBssyyEQQ6yHEtwsT3cXeHj+k+bK/piGl6OYpyOgANTky8A== 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=OJ0Oaw6qeqVBP4z7BaWvqHeExMKi0ezauP2A7yDq1AI=; b=Nlm3OwZeYeQYTTwNrxB3SqsI/cVK3c3CYnNEZ10kdye9KITM3KwWHUPRchnGV3xUFphdZyboMnGNGmrMtXvZhNoXG0lPVhadhBngNAe6n8ZreDITGWc9xrDigi9BSkZlhm+gnbG7ha3wWsY/VJzy8QSE6p2u+kmwMG7dXB6wRbi7oRuqir+TRuqunHtVJRcxlFvDJGfCd/zglRL0rirr/9PIdnRJj3Usduj6BC5CjQTjxuvwZdJd662eCyTZrYqowSUIzM/RIuj1cVbmxe+w8YaceMjDGeM/bzPag0GACh7MV8DOIhszy0RD6KthrPFAh5E7Rg7HFMbrBID/9tkbkQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=outlook.com; dmarc=pass action=none header.from=outlook.com; dkim=pass header.d=outlook.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OJ0Oaw6qeqVBP4z7BaWvqHeExMKi0ezauP2A7yDq1AI=; b=QkuQUEXdouBcVEHKjikq1uz2Z0dwcNubitt7PQvF77ns/wBAqhgGLo6IdAiD5I8WgYucDI/aL13uF5VllSjaIsImgVfLmVXvJZnr+Ncu6xja42cgIZtB58kfdIfIlNp30PaAT+uZxiceifyPoy3iINcGjvxTydj/0aU7Nzel0Riab99AGOLQPOFtRsvcCzRoH+kGaheCF5v87siV3iPmS8FiLbof+3QjKOneGkaTRsxKfOjRfeU2ewhy574LQDyldt/D+VcZOee30eLZJbKkhUDXjcPgj3hYhQWszyK6aAjQ1iM+TGtOVqKgNgo95Y1s0lneTyRl/6PdIs19KZMLKw== Received: from BN8NAM12FT047.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc66::47) by BN8NAM12HT100.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc66::183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2921.12; Fri, 10 Apr 2020 20:50:11 +0000 Received: from MWHPR07MB3440.namprd07.prod.outlook.com (2a01:111:e400:fc66::53) by BN8NAM12FT047.mail.protection.outlook.com (2a01:111:e400:fc66::318) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2921.12 via Frontend Transport; Fri, 10 Apr 2020 20:50:11 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:18136B4EB130DF84144C3DACEF8D7EFD542718080A8CDD94974D3819AD953B12;UpperCasedChecksum:1900D7C829918658DE0667BB07736BAB8DB33D370822B0E1629065E690883E0C;SizeAsReceived:7727;Count:47 Received: from MWHPR07MB3440.namprd07.prod.outlook.com ([fe80::bcc9:271b:20db:52e3]) by MWHPR07MB3440.namprd07.prod.outlook.com ([fe80::bcc9:271b:20db:52e3%6]) with mapi id 15.20.2900.015; Fri, 10 Apr 2020 20:50:11 +0000 From: "Michael Kubacki" To: devel@edk2.groups.io Cc: Dandan Bi , Hao A Wu , Jian J Wang , Kun Qin , Liming Gao Subject: [PATCH v1 1/1] MdeModulePkg/ReportStatusCodeRouter: Revert end pointer on out of resources Date: Fri, 10 Apr 2020 13:49:43 -0700 Message-ID: X-Mailer: git-send-email 2.16.3.windows.1 X-ClientProxiedBy: MWHPR22CA0022.namprd22.prod.outlook.com (2603:10b6:300:ef::32) To MWHPR07MB3440.namprd07.prod.outlook.com (2603:10b6:301:69::28) Return-Path: michael.kubacki@outlook.com X-Microsoft-Original-Message-ID: <20200410204943.23392-1-michael.kubacki@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (2001:4898:80e8:1:71cb:63a2:e2d4:2255) by MWHPR22CA0022.namprd22.prod.outlook.com (2603:10b6:300:ef::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2900.15 via Frontend Transport; Fri, 10 Apr 2020 20:50:10 +0000 X-Mailer: git-send-email 2.16.3.windows.1 X-Microsoft-Original-Message-ID: <20200410204943.23392-1-michael.kubacki@outlook.com> X-TMN: [k3/baz9OjrvTGOfMaFl6DWXnwQXRBfAiSR3XTKiNe5XPPiDCsoOvxUnlrDdc/xv9] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 47 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 2f3f70e4-2515-41a4-448b-08d7dd90c2c8 X-MS-TrafficTypeDiagnostic: BN8NAM12HT100: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nOh07SX38AiauRCXdNfIEEU63bl/ZuwJ/VHJM4jWNGXg4faNxhYaaw5JjbKk6tVCUZqon8Sl74uDx/QHc3PB8njpqLSqnGIBrvQTGmSyIvmj0AQG2nKsuOOykjStNSpJFjpqoEArjsqqzghXHka9w+/1CvC+CL11u2fNfqLqPF8osSjwmuYdyY6p8Jo+gb/3lt3PyPiyJaiqCFo/Yb3c83ll/xcc/C6zUWKxdVxVzE4= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:0;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR07MB3440.namprd07.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:;DIR:OUT;SFP:1901; X-MS-Exchange-AntiSpam-MessageData: +S/njrRL+WhpY6XNZ6jLL2QJHfiM0R9mPj33v2SjeYNMyzF7/9biYC6NGe8dFMguUeG/fQryPSIiOlCiyJEyA0zhlXQ5abbE1V8oBwly+GCLMyqtNVDogGXtn/hbBkKOChsJffPN/AGkoA6+tJZz32DCgLwoHsQ0Dd29susA0hf4vzHWVjOmhICL14BLQdeRkaabJqufPRUS2RXa8dd7IA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2f3f70e4-2515-41a4-448b-08d7dd90c2c8 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Apr 2020 20:50:11.1297 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8NAM12HT100 Content-Type: text/plain From: Michael Kubacki REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2665 ReportDispatcher() is called by a software module to report a status code. The interface is generic and can be called frequently throughout the boot under various conditions. A certain set of conditions can cause the currently implemented algorithm for resource exhaustion to fail. A sample scenario: 1. ReportStatusCode() is called at a TPL higher than one of the registered status code listeners making the call to the listener deferred until TPL is lowered. 2. Additional calls to ReportStatusCode() occur, so the data buffer continues to expand. 3. A call to ReportStatusCode() is made from within a memory allocation call (e.g. CoreAllocatePoolPages ()) which is protected from re- entrancy with mPoolMemoryLock. This will cause the ReallocatePool() call in ReportDispatcher() to fail. Because the end pointer was already moved to account for the data size, the end pointer is now moved beyond the buffer and invalid. This commit saves the original end pointer value into a local variable called "FailSafeEndPointer" which tracks a safe end pointer to revert to in the case the allocated buffer size (CallbackEntry->EndPointer - CallbackEntry->StatusCodeDataBuffer) is still not large enough for the data. Cc: Dandan Bi Cc: Hao A Wu Cc: Jian J Wang Cc: Kun Qin Cc: Liming Gao Signed-off-by: Michael Kubacki --- MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.c b/MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.c index 6ca7e180ebb3..d7dc0a75ac83 100644 --- a/MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.c +++ b/MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.c @@ -3,6 +3,7 @@ and Status Code Runtime Protocol. Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
+ Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -237,6 +238,7 @@ ReportDispatcher ( RSC_DATA_ENTRY *RscData; EFI_STATUS Status; VOID *NewBuffer; + EFI_PHYSICAL_ADDRESS FailSafeEndPointer; // // Use atom operation to avoid the reentant of report. @@ -267,6 +269,7 @@ ReportDispatcher ( // If callback is registered with TPL lower than TPL_HIGH_LEVEL, event must be signaled at boot time to possibly wait for // allowed TPL to report status code. Related data should also be stored in data buffer. // + FailSafeEndPointer = CallbackEntry->EndPointer; CallbackEntry->EndPointer = ALIGN_VARIABLE (CallbackEntry->EndPointer); RscData = (RSC_DATA_ENTRY *) (UINTN) CallbackEntry->EndPointer; CallbackEntry->EndPointer += sizeof (RSC_DATA_ENTRY); @@ -285,6 +288,7 @@ ReportDispatcher ( (VOID *) (UINTN) CallbackEntry->StatusCodeDataBuffer ); if (NewBuffer != NULL) { + FailSafeEndPointer = (EFI_PHYSICAL_ADDRESS) (UINTN) NewBuffer + (FailSafeEndPointer - CallbackEntry->StatusCodeDataBuffer); CallbackEntry->EndPointer = (EFI_PHYSICAL_ADDRESS) (UINTN) NewBuffer + (CallbackEntry->EndPointer - CallbackEntry->StatusCodeDataBuffer); CallbackEntry->StatusCodeDataBuffer = (EFI_PHYSICAL_ADDRESS) (UINTN) NewBuffer; CallbackEntry->BufferSize *= 2; @@ -296,6 +300,7 @@ ReportDispatcher ( // If data buffer is used up, do not report for this time. // if (CallbackEntry->EndPointer > (CallbackEntry->StatusCodeDataBuffer + CallbackEntry->BufferSize)) { + CallbackEntry->EndPointer = FailSafeEndPointer; continue; } -- 2.16.3.windows.1