From nobody Sun Jun 26 08:46:15 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id A2D5C8748AC; Sun, 26 Jun 2022 08:46:15 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LW4Fz2Vxmz4kWt; Sun, 26 Jun 2022 08:46:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656233175; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=9gZmU8SbxJqhpbq2mdb7u+tExbNRbQifEjMevoqXb8M=; b=IoxIhpZv9WXlmmQTz+QnDXD2o/lpxUlWuG/y0MHuBlNYWtB94/eyR8GJibQlKf46Y1CYKe WTBIjarux/IDaa/5tq5exeqtgsxI0oYPMGg0qRG5n2kI9Dr3rMY6mnfbvLQalEmO8JLAGT PE4RMNg8IxI9Xgth2Hb2F0GdMcdFrnbnfUih/pnrxKbHMYiZHgYFXu3zPssSH4qbNZBsZP 4AOHwrlt18uDKfx8yq/zxx6ynuTVmezGrixGIW9uZeEtUwVrSzznNAU5gHOG5pSZj7eou3 K7dnz/mISmhOq3nBbC/NTvEyASX6wReX2EvuRFOi5c9ZpqF4CvcShzD+XWrglw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 3754214466; Sun, 26 Jun 2022 08:46:15 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 25Q8kFge004263; Sun, 26 Jun 2022 08:46:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25Q8kF4u004262; Sun, 26 Jun 2022 08:46:15 GMT (envelope-from git) Date: Sun, 26 Jun 2022 08:46:15 GMT Message-Id: <202206260846.25Q8kF4u004262@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Toomas Soome Subject: git: c796ba5824d8 - stable/13 - loader.efi: fix panic() after BS off List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: tsoome X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: c796ba5824d8809f087058d55929b1496f9e52b3 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656233175; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=9gZmU8SbxJqhpbq2mdb7u+tExbNRbQifEjMevoqXb8M=; b=BeIC8wD7jDFClJTcNdd4GkelJ13mQ8SprRNzeprJXOCYabHCrLS4RbXCQ4fKXHvEkZE5sq HHjIDwFkcjlGURUVhFDB6aTSmNDwCrRjIfxTCFF1uvPM6teKUG6K/2jHUx3tNWuepvP1xQ Y1bcbVeu4tcXUZbVBOg1tlL6Tww2mQcMs6rxDdXS+iRAq1OIXOtl8od+AALWu9rbnTSwha GKiFi80gOzSUv5iV6FPCKuA3braw+YxgpoNdo2wxAKTOTtfbS4yDvHAB6nzNYLudIFmVsP 7/s/Kz6HhbfPx4EM+8XxucLHzbF6jof2RmIIMsdR5mlmDBJ88GXn1NXlUkMCpA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1656233175; a=rsa-sha256; cv=none; b=I2BOl1jiChDzERKvsFU0rQ1m6pzQnarbY86U691PFN5SDj4UAyJX/EbOhlH7NaH/5HYNME YURP0qYJpWFP1X5k8afWHgZi5qY/SBRjNZTGGw/21KAo+s4UdkPraHd+yWcPgxd5zILO5g 27K4aOb5qM5FTCV+bZjlqCd7SrYvduAoOsBsfnqrNc6Tj4I/Aa6G97ehAjVT+qdUNe1THR 7EkUeLuUN3KNORYI/8eHNIa6H+ynT68iJ9dmotSBDaBrQNyqUgF9O29FqtMRIrjaB46FPi MJEKpDFoFT5i4W3sMeH0O0/V0LF6Jo5nOZHeV4gcTzIxsTJb+i4lV10obUMOTA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by tsoome: URL: https://cgit.FreeBSD.org/src/commit/?id=c796ba5824d8809f087058d55929b1496f9e52b3 commit c796ba5824d8809f087058d55929b1496f9e52b3 Author: Toomas Soome AuthorDate: 2021-09-08 00:14:51 +0000 Commit: Toomas Soome CommitDate: 2022-06-26 05:18:13 +0000 loader.efi: fix panic() after BS off panic() is using multiple services - attempting to read keyboard, accessing time functions and finally, exiting the loader. Protect all the accessed listed above. Note, when BS are off, we really can not just exit the loader, we only can reboot. (cherry-picked from commit a2e02d9d8e100bc41cf99b8fd04738954e48a94e) --- stand/efi/include/efiapi.h | 2 +- stand/efi/libefi/delay.c | 3 ++- stand/efi/libefi/efi_console.c | 6 ++++++ stand/efi/loader/efi_main.c | 8 ++++++-- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/stand/efi/include/efiapi.h b/stand/efi/include/efiapi.h index 0118027d4b3c..2347a4d9cf73 100644 --- a/stand/efi/include/efiapi.h +++ b/stand/efi/include/efiapi.h @@ -438,7 +438,7 @@ VOID IN EFI_STATUS ResetStatus, IN UINTN DataSize, IN CHAR16 *ResetData OPTIONAL - ); + ) __dead2; typedef EFI_STATUS diff --git a/stand/efi/libefi/delay.c b/stand/efi/libefi/delay.c index 9eb123096636..9bf40d28f96b 100644 --- a/stand/efi/libefi/delay.c +++ b/stand/efi/libefi/delay.c @@ -33,5 +33,6 @@ __FBSDID("$FreeBSD$"); void delay(int usecs) { - BS->Stall(usecs); + if (boot_services_active) + BS->Stall(usecs); } diff --git a/stand/efi/libefi/efi_console.c b/stand/efi/libefi/efi_console.c index 7166b7a3cfbe..1aeb94344c58 100644 --- a/stand/efi/libefi/efi_console.c +++ b/stand/efi/libefi/efi_console.c @@ -1362,6 +1362,9 @@ efi_cons_getchar(void) if ((c = keybuf_getchar()) != 0) return (c); + if (!boot_services_active) + return (-1); + key_pending = 0; if (coninex == NULL) { @@ -1383,6 +1386,9 @@ efi_cons_poll(void) if (keybuf_ischar() || key_pending) return (1); + if (!boot_services_active) + return (0); + /* * Some EFI implementation (u-boot for example) do not support * WaitForKey(). diff --git a/stand/efi/loader/efi_main.c b/stand/efi/loader/efi_main.c index 736c1aa56c99..3e1fa06638e9 100644 --- a/stand/efi/loader/efi_main.c +++ b/stand/efi/loader/efi_main.c @@ -40,8 +40,12 @@ void efi_exit(EFI_STATUS exit_code) { - BS->FreePages(heap, EFI_SIZE_TO_PAGES(heapsize)); - BS->Exit(IH, exit_code, 0, NULL); + if (boot_services_active) { + BS->FreePages(heap, EFI_SIZE_TO_PAGES(heapsize)); + BS->Exit(IH, exit_code, 0, NULL); + } else { + RS->ResetSystem(EfiResetCold, EFI_SUCCESS, 0, NULL); + } } void