Skip to content

Commit eae21be

Browse files
mchehabrafaeljw
authored andcommitted
EFI/CPER: don't go past the ARM processor CPER record buffer
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>
1 parent 87880af commit eae21be

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

drivers/firmware/efi/cper-arm.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ static void cper_print_arm_err_info(const char *pfx, u32 type,
226226
}
227227

228228
void cper_print_proc_arm(const char *pfx,
229-
const struct cper_sec_proc_arm *proc)
229+
const struct cper_sec_proc_arm *proc,
230+
u32 length)
230231
{
231232
int i, len, max_ctx_type;
232233
struct cper_arm_err_info *err_info;
@@ -238,9 +239,12 @@ void cper_print_proc_arm(const char *pfx,
238239

239240
len = proc->section_length - (sizeof(*proc) +
240241
proc->err_info_num * (sizeof(*err_info)));
241-
if (len < 0) {
242-
printk("%ssection length: %d\n", pfx, proc->section_length);
243-
printk("%ssection length is too small\n", pfx);
242+
243+
if (len < 0 || proc->section_length > length) {
244+
printk("%ssection length: %d, CPER size: %d\n",
245+
pfx, proc->section_length, length);
246+
printk("%ssection length is too %s\n", pfx,
247+
(len < 0) ? "small" : "big");
244248
printk("%sfirmware-generated error record is incorrect\n", pfx);
245249
printk("%sERR_INFO_NUM is %d\n", pfx, proc->err_info_num);
246250
return;

drivers/firmware/efi/cper.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,8 @@ cper_estatus_print_section(const char *pfx, struct acpi_hest_generic_data *gdata
659659

660660
printk("%ssection_type: ARM processor error\n", newpfx);
661661
if (gdata->error_data_length >= sizeof(*arm_err))
662-
cper_print_proc_arm(newpfx, arm_err);
662+
cper_print_proc_arm(newpfx, arm_err,
663+
gdata->error_data_length);
663664
else
664665
goto err_section_too_small;
665666
#endif

include/linux/cper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,8 @@ void cper_mem_err_pack(const struct cper_sec_mem_err *,
595595
const char *cper_mem_err_unpack(struct trace_seq *,
596596
struct cper_mem_err_compact *);
597597
void cper_print_proc_arm(const char *pfx,
598-
const struct cper_sec_proc_arm *proc);
598+
const struct cper_sec_proc_arm *proc,
599+
u32 length);
599600
void cper_print_proc_ia(const char *pfx,
600601
const struct cper_sec_proc_ia *proc);
601602
int cper_mem_err_location(struct cper_mem_err_compact *mem, char *msg);

0 commit comments

Comments
 (0)