Open
fix(cve): 修复 CVE-2026-97876 在 grub2 中的漏洞 #626
infra_teamAdd on Oct 3
fix(cve): 修复 CVE-2026-97876 在 grub2 中的漏洞 #626
Open
Total: 3 files changed+227-2
Abackport-CVE-2026-97876-term-serial-Reject-caller-supplied-port-addresses-under-lockdown.patch+218-0
| @@ -0,0 +1,218 @@ | |||
| 1 | +From 26beaa3b2720fefdc4d04c1ae209b776fe6848d6 Mon Sep 17 00:00:00 2001 | ||
| 2 | +From: Andrew Hamilton <adhamilt@gmail.com> | ||
| 3 | +Date: Tue, 15 Sep 2026 17:49:10 -0500 | ||
| 4 | +Subject: [PATCH] fix: CVE-2026-97876 - term/serial: Reject caller-supplied port addresses under lockdown | ||
| 5 | + | ||
| 6 | +fix: CVE-2026-97876 - term/serial: Reject caller-supplied port addresses under lockdown | ||
| 7 | + | ||
| 8 | +Upstream-commit: https://gitlab.freedesktop.org/gnu-grub/grub/-/commit/26beaa3b2720fefdc4d04c1ae209b776fe6848d6 | ||
| 9 | +Signed-off-by: infra_team <zhaiwenjie1@huawei.com> | ||
| 10 | +--- | ||
| 11 | +diff --git a/grub-core/term/ns8250-spcr.c b/grub-core/term/ns8250-spcr.c | ||
| 12 | +index 8141364..19bc99a 100644 | ||
| 13 | +--- a/grub-core/term/ns8250-spcr.c | ||
| 14 | ++++ b/grub-core/term/ns8250-spcr.c | ||
| 15 | +@@ -82,11 +82,13 @@ grub_ns8250_spcr_init (void) | ||
| 16 | + | ||
| 17 | + switch (spcr->base_addr.space_id) | ||
| 18 | + { | ||
| 19 | ++ /* The address comes from the platform's own ACPI table, so it is trusted. */ | ||
| 20 | + case GRUB_ACPI_GENADDR_MEM_SPACE: | ||
| 21 | + return grub_serial_ns8250_add_mmio (spcr->base_addr.addr, | ||
| 22 | +- spcr->base_addr.access_size, &config); | ||
| 23 | ++ spcr->base_addr.access_size, &config, | ||
| 24 | ++ true); | ||
| 25 | + case GRUB_ACPI_GENADDR_IO_SPACE: | ||
| 26 | +- return grub_serial_ns8250_add_port (spcr->base_addr.addr, &config); | ||
| 27 | ++ return grub_serial_ns8250_add_port (spcr->base_addr.addr, &config, true); | ||
| 28 | + default: | ||
| 29 | + return NULL; | ||
| 30 | + }; | ||
| 31 | +diff --git a/grub-core/term/ns8250.c b/grub-core/term/ns8250.c | ||
| 32 | +index 23e8e09..014bb04 100644 | ||
| 33 | +--- a/grub-core/term/ns8250.c | ||
| 34 | ++++ b/grub-core/term/ns8250.c | ||
| 35 | +@@ -347,7 +347,8 @@ grub_ns8250_hw_get_port (const unsigned int unit) | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + struct grub_serial_port * | ||
| 39 | +-grub_serial_ns8250_add_port (grub_port_t port, struct grub_serial_config *config) | ||
| 40 | ++grub_serial_ns8250_add_port (grub_port_t port, struct grub_serial_config *config, | ||
| 41 | ++ bool trusted) | ||
| 42 | + { | ||
| 43 | + struct grub_serial_port *p; | ||
| 44 | + unsigned i; | ||
| 45 | +@@ -363,14 +364,23 @@ grub_serial_ns8250_add_port (grub_port_t port, struct grub_serial_config *config | ||
| 46 | + return &com_ports[i]; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | ++ /* | ||
| 50 | ++ * use_mmio and port share a union with the private data of every other back | ||
| 51 | ++ * end, so they only mean anything on a port this driver registered. | ||
| 52 | ++ */ | ||
| 53 | + FOR_SERIAL_PORTS (p) | ||
| 54 | +- if (p->use_mmio == false && p->port == port) | ||
| 55 | ++ if (p->driver == &grub_ns8250_driver | ||
| 56 | ++ && p->use_mmio == false && p->port == port) | ||
| 57 | + { | ||
| 58 | + if (config != NULL) | ||
| 59 | + grub_serial_port_configure (p, config); | ||
| 60 | + return p; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | ++ /* No port is registered here, so going on means probing the address. */ | ||
| 64 | ++ if (grub_serial_reject_untrusted_address (trusted) == true) | ||
| 65 | ++ return NULL; | ||
| 66 | ++ | ||
| 67 | + grub_outb (0x5a, port + UART_SR); | ||
| 68 | + if (grub_inb (port + UART_SR) != 0x5a) | ||
| 69 | + return NULL; | ||
| 70 | +@@ -402,7 +412,7 @@ grub_serial_ns8250_add_port (grub_port_t port, struct grub_serial_config *config | ||
| 71 | + | ||
| 72 | + struct grub_serial_port * | ||
| 73 | + grub_serial_ns8250_add_mmio (grub_addr_t addr, unsigned int acc_size, | ||
| 74 | +- struct grub_serial_config *config) | ||
| 75 | ++ struct grub_serial_config *config, bool trusted) | ||
| 76 | + { | ||
| 77 | + struct grub_serial_port *p; | ||
| 78 | + unsigned i; | ||
| 79 | +@@ -415,14 +425,23 @@ grub_serial_ns8250_add_mmio (grub_addr_t addr, unsigned int acc_size, | ||
| 80 | + return &com_ports[i]; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | ++ /* | ||
| 84 | ++ * use_mmio and mmio share a union with the private data of every other back | ||
| 85 | ++ * end, so they only mean anything on a port this driver registered. | ||
| 86 | ++ */ | ||
| 87 | + FOR_SERIAL_PORTS (p) | ||
| 88 | +- if (p->use_mmio == true && p->mmio.base == addr) | ||
| 89 | ++ if (p->driver == &grub_ns8250_driver | ||
| 90 | ++ && p->use_mmio == true && p->mmio.base == addr) | ||
| 91 | + { | ||
| 92 | + if (config != NULL) | ||
| 93 | + grub_serial_port_configure (p, config); | ||
| 94 | + return p; | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | ++ /* No port is registered here, so going on means programming the address. */ | ||
| 98 | ++ if (grub_serial_reject_untrusted_address (trusted) == true) | ||
| 99 | ++ return NULL; | ||
| 100 | ++ | ||
| 101 | + p = grub_malloc (sizeof (*p)); | ||
| 102 | + if (p == NULL) | ||
| 103 | + return NULL; | ||
| 104 | +diff --git a/grub-core/term/serial.c b/grub-core/term/serial.c | ||
| 105 | +index 8260dcb..968c4d1 100644 | ||
| 106 | +--- a/grub-core/term/serial.c | ||
| 107 | ++++ b/grub-core/term/serial.c | ||
| 108 | +@@ -28,6 +28,7 @@ | ||
| 109 | + #include <grub/extcmd.h> | ||
| 110 | + #include <grub/i18n.h> | ||
| 111 | + #include <grub/list.h> | ||
| 112 | ++#include <grub/lockdown.h> | ||
| 113 | + #ifdef GRUB_MACHINE_MIPS_LOONGSON | ||
| 114 | + #include <grub/machine/kernel.h> | ||
| 115 | + #endif | ||
| 116 | +@@ -140,6 +141,30 @@ static struct grub_term_output grub_serial_term_output = | ||
| 117 | + | ||
| 118 | + | ||
| 119 | + | ||
| 120 | ++/* | ||
| 121 | ++ * An address that no port is registered at cannot be honored while lockdown | ||
| 122 | ++ * is enforced: the probe and programming sequences in the ns8250 and pl011 | ||
| 123 | ++ * back ends write to fixed offsets from it with no way to tell a UART from | ||
| 124 | ++ * ordinary memory, so an address taken from an unauthenticated configuration | ||
| 125 | ++ * is a write primitive against whatever it points at. | ||
| 126 | ++ * | ||
| 127 | ++ * A back end calls this once its own lookup has found no port already | ||
| 128 | ++ * registered at the address, that is, at the point where it would otherwise | ||
| 129 | ++ * touch the hardware. TRUSTED is true when the address came from a platform | ||
| 130 | ++ * description -- grub_ns8250_init(), an ACPI SPCR table, PCI enumeration -- | ||
| 131 | ++ * rather than from the caller. | ||
| 132 | ++ */ | ||
| 133 | ++bool | ||
| 134 | ++grub_serial_reject_untrusted_address (bool trusted) | ||
| 135 | ++{ | ||
| 136 | ++ if (trusted == true || grub_is_lockdown () != GRUB_LOCKDOWN_ENABLED) | ||
| 137 | ++ return false; | ||
| 138 | ++ | ||
| 139 | ++ grub_error (GRUB_ERR_ACCESS_DENIED, | ||
| 140 | ++ N_("serial port address is not permitted when lockdown is enforced")); | ||
| 141 | ++ return true; | ||
| 142 | ++} | ||
| 143 | ++ | ||
| 144 | + struct grub_serial_port * | ||
| 145 | + grub_serial_find (const char *name) | ||
| 146 | + { | ||
| 147 | +@@ -158,8 +183,14 @@ grub_serial_find (const char *name) | ||
| 148 | + if (grub_strncmp (name, "port", sizeof ("port") - 1) == 0 | ||
| 149 | + && grub_isxdigit (name [sizeof ("port") - 1])) | ||
| 150 | + { | ||
| 151 | ++ /* | ||
| 152 | ++ * Everything below this point builds a port from an address the caller | ||
| 153 | ++ * gave us, so the back ends are told the address is untrusted: under | ||
| 154 | ++ * lockdown they hand back a port only if one is already registered at | ||
| 155 | ++ * that address, which means the platform described that UART. | ||
| 156 | ++ */ | ||
| 157 | + port = grub_serial_ns8250_add_port (grub_strtoul (&name[sizeof ("port") - 1], | ||
| 158 | +- 0, 16), NULL); | ||
| 159 | ++ 0, 16), NULL, false); | ||
| 160 | + if (port != NULL) | ||
| 161 | + return port; | ||
| 162 | + } | ||
| 163 | +@@ -205,7 +236,7 @@ grub_serial_find (const char *name) | ||
| 164 | + grub_error (GRUB_ERR_BAD_ARGUMENT, N_("incorrect MMIO access size")); | ||
| 165 | + } | ||
| 166 | + | ||
| 167 | +- port = grub_serial_ns8250_add_mmio (addr, acc_size, NULL); | ||
| 168 | ++ port = grub_serial_ns8250_add_mmio (addr, acc_size, NULL, false); | ||
| 169 | + if (port != NULL) | ||
| 170 | + return port; | ||
| 171 | + } | ||
| 172 | +@@ -275,9 +306,18 @@ grub_cmd_serial (grub_extcmd_context_t ctxt, int argc, char **args) | ||
| 173 | + | ||
| 174 | + port = grub_serial_find (name); | ||
| 175 | + if (!port) | ||
| 176 | +- return grub_error (GRUB_ERR_BAD_ARGUMENT, | ||
| 177 | +- N_("serial port `%s' isn't found"), | ||
| 178 | +- name); | ||
| 179 | ++ { | ||
| 180 | ++ /* | ||
| 181 | ++ * A back end that refused the port has already said why; keep that | ||
| 182 | ++ * rather than reporting a misleading "isn't found". | ||
| 183 | ++ */ | ||
| 184 | ++ if (grub_errno == GRUB_ERR_ACCESS_DENIED) | ||
| 185 | ++ return grub_errno; | ||
| 186 | ++ | ||
| 187 | ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, | ||
| 188 | ++ N_("serial port `%s' isn't found"), | ||
| 189 | ++ name); | ||
| 190 | ++ } | ||
| 191 | + | ||
| 192 | + config = port->config; | ||
| 193 | + | ||
| 194 | +diff --git a/include/grub/serial.h b/include/grub/serial.h | ||
| 195 | +index d7e0635..096209a 100644 | ||
| 196 | +--- a/include/grub/serial.h | ||
| 197 | ++++ b/include/grub/serial.h | ||
| 198 | +@@ -188,14 +188,18 @@ grub_serial_config_defaults (struct grub_serial_port *port) | ||
| 199 | + return port->driver->configure (port, &config); | ||
| 200 | + } | ||
| 201 | + | ||
| 202 | ++bool grub_serial_reject_untrusted_address (bool trusted); | ||
| 203 | ++ | ||
| 204 | + #if defined(__mips__) || defined (__i386__) || defined (__x86_64__) | ||
| 205 | + void grub_ns8250_init (void); | ||
| 206 | + struct grub_serial_port *grub_ns8250_spcr_init (void); | ||
| 207 | + struct grub_serial_port *grub_serial_ns8250_add_port (grub_port_t port, | ||
| 208 | +- struct grub_serial_config *config); | ||
| 209 | ++ struct grub_serial_config *config, | ||
| 210 | ++ bool trusted); | ||
| 211 | + struct grub_serial_port *grub_serial_ns8250_add_mmio (grub_addr_t addr, | ||
| 212 | + unsigned int acc_size, | ||
| 213 | +- struct grub_serial_config *config); | ||
| 214 | ++ struct grub_serial_config *config, | ||
| 215 | ++ bool trusted); | ||
| 216 | + #endif | ||
| 217 | + #ifdef GRUB_MACHINE_IEEE1275 | ||
| 218 | + void grub_ofserial_init (void); | ||
| @@ -393,4 +393,5 @@ Patch396: backport-nx-16-efi-split-allocation-policy-for-kernel-vs-initrd- | |||
| 393 | Patch397: backport-nx-17-efi-allocate-the-initrd-within-the-bounds-expressed-.patch | 393 | Patch397: backport-nx-17-efi-allocate-the-initrd-within-the-bounds-expressed-.patch |
| 394 | Patch398: backport-nx-18-efi-use-EFI_LOADER_-CODE-DATA-for-kernel-and-initrd-.patch | 394 | Patch398: backport-nx-18-efi-use-EFI_LOADER_-CODE-DATA-for-kernel-and-initrd-.patch |
| 395 | Patch399: backport-nx-19-x86-efi-Fix-an-incorrect-array-size-in-kernel-alloca.patch | 395 | Patch399: backport-nx-19-x86-efi-Fix-an-incorrect-array-size-in-kernel-alloca.patch |
| 396 | -Patch400: backport-grub_dl_load_segments-page-align-the-tramp-GOT-areas.patch | 396 | +Patch400: backport-grub_dl_load_segments-page-align-the-tramp-GOT-areas.patch |
| 397 | +Patch401: backport-CVE-2026-97876-term-serial-Reject-caller-supplied-port-addresses-under-lockdown.patch | ||
| @@ -32,7 +32,7 @@ | |||
| 32 | Name: grub2 | 32 | Name: grub2 |
| 33 | Epoch: 1 | 33 | Epoch: 1 |
| 34 | Version: 2.12 | 34 | Version: 2.12 |
| 35 | -Release: 56 | 35 | +Release: 57 |
| 36 | Summary: Bootloader with support for Linux, Multiboot and more | 36 | Summary: Bootloader with support for Linux, Multiboot and more |
| 37 | License: GPLv3+ | 37 | License: GPLv3+ |
| 38 | URL: http://www.gnu.org/software/grub/ | 38 | URL: http://www.gnu.org/software/grub/ |
| @@ -501,6 +501,12 @@ fi | |||
| 501 | %{_datadir}/man/man* | 501 | %{_datadir}/man/man* |
| 502 | 502 | ||
| 503 | %changelog | 503 | %changelog |
| 504 | +* Sat Oct 03 2026 infra_team <zhaiwenjie1@huawei.com> - 1:2.12-57 | ||
| 505 | +- Type:CVE | ||
| 506 | +- CVE:CVE-2026-97876 | ||
| 507 | +- SUG:NA | ||
| 508 | +- DESC:term/serial: Reject caller-supplied port addresses under lockdown | ||
| 509 | + | ||
| 504 | * Mon Sep 14 2026 zhaoyonghao10 <zhaoyonghao10@h-partners.com> - 1:2.12-56 | 510 | * Mon Sep 14 2026 zhaoyonghao10 <zhaoyonghao10@h-partners.com> - 1:2.12-56 |
| 505 | - Type:bugfix | 511 | - Type:bugfix |
| 506 | - CVE:NA | 512 | - CVE:NA |