From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:400e:c05::241; helo=mail-pg0-x241.google.com; envelope-from=heyi.guo@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pg0-x241.google.com (mail-pg0-x241.google.com [IPv6:2607:f8b0:400e:c05::241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id E8E44209574C0 for ; Mon, 26 Feb 2018 00:24:30 -0800 (PST) Received: by mail-pg0-x241.google.com with SMTP id g12so5916882pgs.0 for ; Mon, 26 Feb 2018 00:30:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=4dfEogB+auFTfI/5z0bw1T3IblVEJ8801hxh98S1+Sk=; b=C8Hl5tGD6n0Enb21mf7jQ9ZXOp0mhMKWVU4sCMj6K5SNf8L+vsv3NVYIoIDOFbQsW6 t4bxH6x2p1/slJkxMe5609Z7EpmGdtHAY6O7h+hsaxINZT0KiuUoLJZzIHCs9I4Qe5Oj pVQG+LRil4Fd96butETJP/99avqWKIohrCiDM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=4dfEogB+auFTfI/5z0bw1T3IblVEJ8801hxh98S1+Sk=; b=pjDjYTwV7cP/8oSROPckkAkftK028FRzlhy8JUvpRy0uEU6Y1IPVL728AaHPPClIm2 MMGbAZA4hc5vIc5R63tLcZQCkNbmKN8UP2JExoDvn66bvzDZ/sh+xDosqiIWe5OagTuK S2GkrKjlcI96JBIxOC06o/AtGLlxldyradbAJI0RioJ4tLOhgLlWItcoALI6fc3nrDpd h4PB2BYdmk7R3A56P/AMmssmzo8Swt/XOUxHYQud5xiuJVofs267eyfv9Xzh02Q/KVad zicHpU71PzLUOAx3mOgCJ++1cYkVCSjvpX6TYiQjDdvdga/FXu6mni8PL6Y2uuRBPPyb RUZA== X-Gm-Message-State: APf1xPABw40otSN9lRP9ltWbbePlIOwl5Ca3ph0DRAR/mgvX437kL0+R GQZVS5FZHAPPijZNxgerltW6ckMcJAU= X-Google-Smtp-Source: AH8x224Aw+W6Jjf5IvN48naztJ0xFuKULNHJE0Su4DNTp3mVSEKXVxhEEiD8NLEN3a6HBFeuReLnZw== X-Received: by 10.101.97.139 with SMTP id c11mr7816389pgv.443.1519633835207; Mon, 26 Feb 2018 00:30:35 -0800 (PST) Received: from localhost.localdomain ([104.237.91.49]) by smtp.gmail.com with ESMTPSA id r78sm17723145pfb.24.2018.02.26.00.30.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Feb 2018 00:30:34 -0800 (PST) From: Heyi Guo To: edk2-devel@lists.01.org Cc: Heyi Guo , Star Zeng , Eric Dong , Ruiyu Ni Date: Mon, 26 Feb 2018 16:29:39 +0800 Message-Id: <1519633779-130687-1-git-send-email-heyi.guo@linaro.org> X-Mailer: git-send-email 2.7.4 Subject: [PATCH 1/1] MdeModulePkg/UefiBootManagerLib: limit recursive call depth X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Feb 2018 08:24:31 -0000 Function BmRepairAllControllers may recursively call itself if some driver health protocol returns EfiDriverHealthStatusReconnectRequired. However, driver health protocol of some buggy third party driver may always return such status even after one and another reconnect. The endless iteration will cause stack overflow and then system exception, and it may be not easy to find that the exception is actually caused by stack overflow. So we limit the number of reconnect retry to 10 to improve code robustness. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Heyi Guo Cc: Star Zeng Cc: Eric Dong Cc: Ruiyu Ni --- MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h | 6 ++++++ MdeModulePkg/Library/UefiBootManagerLib/BmDriverHealth.c | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h b/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h index 25a1d522fe84..9aa86b096525 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h +++ b/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h @@ -108,6 +108,12 @@ CHAR16 * #define BM_OPTION_NAME_LEN sizeof ("PlatformRecovery####") extern CHAR16 *mBmLoadOptionName[]; +// +// Maximum number of reconnect retry to repair controller; it is to limit the +// number of recursive call of BmRepairAllControllers. +// +#define MAX_RECONNECT_REPAIR 10 + /** Visitor function to be called by BmForEachVariable for each variable in variable storage. diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmDriverHealth.c b/MdeModulePkg/Library/UefiBootManagerLib/BmDriverHealth.c index ddcee8b0676f..30d70f32af84 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmDriverHealth.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmDriverHealth.c @@ -26,6 +26,12 @@ GLOBAL_REMOVE_IF_UNREFERENCED L"Reboot Required" }; +// +// Counter of reconnect retry to repair controller; it is to limit the +// number of recursive call of BmRepairAllControllers. +// +STATIC UINTN mReconnectRepairCount; + /** Return the controller name. @@ -549,7 +555,16 @@ BmRepairAllControllers ( if (ReconnectRequired) { - BmRepairAllControllers (); + if (mReconnectRepairCount < MAX_RECONNECT_REPAIR) { + mReconnectRepairCount++; + BmRepairAllControllers (); + } else { + DEBUG ((DEBUG_ERROR, "[%a:%d] Repair failed after %d retries.\n", + __FUNCTION__, __LINE__, mReconnectRepairCount)); + // Reset counter so that it will not affect calling + // BmRepairAllControllers() somewhere else + mReconnectRepairCount = 0; + } } DEBUG_CODE ( -- 2.7.4