term/ns8250-spcr: return if redirection is disabled

Compared to previous commit, this is a better approach to handle SPCR null base
address indicating no redirection, doing the null check on the caller instead of
the callee.

Resolves: #RHEL-68622
Signed-off-by: Leo Sandoval <lsandova@redhat.com>
This commit is contained in:
Leo Sandoval 2025-01-17 10:33:10 -06:00
parent 4052952894
commit ff6d9c809c
4 changed files with 41 additions and 31 deletions

View File

@ -1,29 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Leo Sandoval <lsandova@redhat.com>
Date: Wed, 8 Jan 2025 10:24:26 -0600
Subject: [PATCH] term/ns8250: return in case of a null SPCR base addresses
Serial SPCR MMIO null address are invalid, so return from function, otherwise
invalid 'mmio,0' port names are generated halting the system when running
terminal_input|output commands.
Resolves: #RHEL-68622
Signed-off-by: Leo Sandoval <lsandova@redhat.com>
---
grub-core/term/ns8250.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/grub-core/term/ns8250.c b/grub-core/term/ns8250.c
index 23e8e0904..4ac0bc06a 100644
--- a/grub-core/term/ns8250.c
+++ b/grub-core/term/ns8250.c
@@ -407,6 +407,9 @@ grub_serial_ns8250_add_mmio (grub_addr_t addr, unsigned int acc_size,
struct grub_serial_port *p;
unsigned i;
+ if (addr == NULL)
+ return NULL;
+
for (i = 0; i < GRUB_SERIAL_PORT_NUM; i++)
if (com_ports[i].use_mmio == true && com_ports[i].mmio.base == addr)
{

View File

@ -0,0 +1,35 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Date: Thu, 16 Jan 2025 10:22:48 -0600
Subject: [PATCH] term/ns8250-spcr: return if redirection is disabled
The Microsoft spec for SPCR says "The base address of the Serial Port register
set described using the ACPI Generic Address Structure, or 0 if console
redirection is disabled." so return if disable (base address = 0). If this check
is not done, we may get invalid ports for those particular machines that
redirection is disabled and at some point hanging the booting execution when
reading the grub.cfg configuration file.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Reviewed-by: Leo Sandoval <lsandova@redhat.com>
---
grub-core/term/ns8250-spcr.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/grub-core/term/ns8250-spcr.c b/grub-core/term/ns8250-spcr.c
index d52b52c26..86f1aa078 100644
--- a/grub-core/term/ns8250-spcr.c
+++ b/grub-core/term/ns8250-spcr.c
@@ -75,6 +75,11 @@ grub_ns8250_spcr_init (void)
config.speed = 115200;
break;
};
+
+ /* if base address is 0, it means redirection is disable, so return it */
+ if (spcr->base_addr.addr == 0)
+ return NULL;
+
switch (spcr->base_addr.space_id)
{
case GRUB_ACPI_GENADDR_MEM_SPACE:

View File

@ -281,4 +281,4 @@ Patch0280: 0280-grub2-mkconfig-Pass-all-boot-params-when-used-by-ana.patch
Patch0281: 0281-10_linux.in-escape-semicolon-and-ampersand-on-BLS-up.patch
Patch0282: 0282-acpi-Fix-out-of-bounds-access-in-grub_acpi_xsdt_find.patch
Patch0283: 0283-fs-xfs-Fix-large-extent-counters-incompat-feature-su.patch
Patch0284: 0284-term-ns8250-return-null-in-case-of-a-null-address.patch
Patch0284: 0284-term-ns8250-spcr-return-if-redirection-is-disabled.patch

View File

@ -17,7 +17,7 @@
Name: grub2
Epoch: 1
Version: 2.12
Release: 6%{?dist}
Release: 7%{?dist}
Summary: Bootloader with support for Linux, Multiboot and more
License: GPL-3.0-or-later
URL: http://www.gnu.org/software/grub/
@ -583,6 +583,10 @@ mv ${EFI_HOME}/grub.cfg.stb ${EFI_HOME}/grub.cfg
%endif
%changelog
* Fri Jan 17 2025 Leo Sandoval <lsandova@redhat.com> 2.12-7
- term/ns8250-spcr: return if redirection is disabled
- Resolves: #RHEL-68622
* Mon Jan 13 2025 Leo Sandoval <lsandova@redhat.com> 2.12-6
- term/ns8250: return in case of a null SPCR base addresses
- Resolves: #RHEL-68622