GHES first reads an error status header to validate its length and size the
destination buffer, then copies the complete status block. Firmware can
change the header between those operations. If the second header reports a
larger length, cper_estatus_check() can walk beyond the copied buffer.
Recalculate the length after the full copy and reject records that are
shorter than the status header or larger than the supplied buffer.
Fixes: e00a6e3392cb ("ACPI / APEI: Split ghes_read_estatus() to allow a peek at
the CPER length")
Reported-by: [email protected]
Link:
https://sashiko.dev/#/message/20260617141511.F13231F000E9%40smtp.kernel.org
Signed-off-by: Ahmed Tiba <[email protected]>
---
drivers/acpi/apei/ghes.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
index 6344bfc15a50..d4ddf3c79216 100644
--- a/drivers/acpi/apei/ghes.c
+++ b/drivers/acpi/apei/ghes.c
@@ -421,7 +421,21 @@ static int __ghes_read_estatus(struct
acpi_hest_generic_status *estatus,
u64 buf_paddr, enum fixed_addresses fixmap_idx,
size_t buf_len)
{
+ u32 len;
+
ghes_copy_tofrom_phys(estatus, buf_paddr, buf_len, 1, fixmap_idx);
+
+ len = cper_estatus_len(estatus);
+ if (len < sizeof(*estatus)) {
+ pr_warn_ratelimited(FW_WARN GHES_PFX "Truncated error status
block!\n");
+ return -EIO;
+ }
+
+ if (len > buf_len) {
+ pr_warn_ratelimited(FW_WARN GHES_PFX "Invalid error status
block length!\n");
+ return -EIO;
+ }
+
if (cper_estatus_check(estatus)) {
pr_warn_ratelimited(FW_WARN GHES_PFX
"Failed to read error status block!\n");
--
2.43.0