]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
EFI/CPER: don't go past the ARM processor CPER record buffer
authorMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Thu, 8 Jan 2026 11:35:04 +0000 (12:35 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 14 Jan 2026 16:04:21 +0000 (17:04 +0100)
There's a logic inside GHES/CPER to detect if the section_length
is too small, but it doesn't detect if it is too big.

Currently, if the firmware receives an ARM processor CPER record
stating that a section length is big, kernel will blindly trust
section_length, producing a very long dump. For instance, a 67
bytes record with ERR_INFO_NUM set 46198 and section length
set to 854918320 would dump a lot of data going a way past the
firmware memory-mapped area.

Fix it by adding a logic to prevent it to go past the buffer
if ERR_INFO_NUM is too big, making it report instead:

[Hardware Error]: Hardware error from APEI Generic Hardware Error Source: 1
[Hardware Error]: event severity: recoverable
[Hardware Error]:  Error 0, type: recoverable
[Hardware Error]:   section_type: ARM processor error
[Hardware Error]:   MIDR: 0xff304b2f8476870a
[Hardware Error]:   section length: 854918320, CPER size: 67
[Hardware Error]:   section length is too big
[Hardware Error]:   firmware-generated error record is incorrect
[Hardware Error]:   ERR_INFO_NUM is 46198

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Hanjun Guo <guohanjun@huawei.com>
[ rjw: Subject and changelog tweaks ]
Link: https://patch.msgid.link/41cd9f6b3ace3cdff7a5e864890849e4b1c58b63.1767871950.git.mchehab+huawei@kernel.org
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/firmware/efi/cper-arm.c
drivers/firmware/efi/cper.c
include/linux/cper.h

index 76542a53e20275cf0f059e9ce409fd898de16d4d..b21cb1232d82074c598f4406797a0e54e93258ee 100644 (file)
@@ -226,7 +226,8 @@ static void cper_print_arm_err_info(const char *pfx, u32 type,
 }
 
 void cper_print_proc_arm(const char *pfx,
-                        const struct cper_sec_proc_arm *proc)
+                        const struct cper_sec_proc_arm *proc,
+                        u32 length)
 {
        int i, len, max_ctx_type;
        struct cper_arm_err_info *err_info;
@@ -238,9 +239,12 @@ void cper_print_proc_arm(const char *pfx,
 
        len = proc->section_length - (sizeof(*proc) +
                proc->err_info_num * (sizeof(*err_info)));
-       if (len < 0) {
-               printk("%ssection length: %d\n", pfx, proc->section_length);
-               printk("%ssection length is too small\n", pfx);
+
+       if (len < 0 || proc->section_length > length) {
+               printk("%ssection length: %d, CPER size: %d\n",
+                      pfx, proc->section_length, length);
+               printk("%ssection length is too %s\n", pfx,
+                      (len < 0) ? "small" : "big");
                printk("%sfirmware-generated error record is incorrect\n", pfx);
                printk("%sERR_INFO_NUM is %d\n", pfx, proc->err_info_num);
                return;
index 0232bd040f61c9b4521ae50ec4b6a1b0bfa5cc19..88fc0293f8762ec6c92c3d395ddf1f9d190e9341 100644 (file)
@@ -659,7 +659,8 @@ cper_estatus_print_section(const char *pfx, struct acpi_hest_generic_data *gdata
 
                printk("%ssection_type: ARM processor error\n", newpfx);
                if (gdata->error_data_length >= sizeof(*arm_err))
-                       cper_print_proc_arm(newpfx, arm_err);
+                       cper_print_proc_arm(newpfx, arm_err,
+                                           gdata->error_data_length);
                else
                        goto err_section_too_small;
 #endif
index 5b1236d8c65bb7d285a327c457115a18fc9d7953..440b35e459e538be6534433b2643fce4b2d0dda1 100644 (file)
@@ -595,7 +595,8 @@ void cper_mem_err_pack(const struct cper_sec_mem_err *,
 const char *cper_mem_err_unpack(struct trace_seq *,
                                struct cper_mem_err_compact *);
 void cper_print_proc_arm(const char *pfx,
-                        const struct cper_sec_proc_arm *proc);
+                        const struct cper_sec_proc_arm *proc,
+                        u32 length);
 void cper_print_proc_ia(const char *pfx,
                        const struct cper_sec_proc_ia *proc);
 int cper_mem_err_location(struct cper_mem_err_compact *mem, char *msg);