Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

APEI/GHES: ARM processor Error: don't go past allocated memory

If the BIOS generates a very small ARM Processor Error, or
an incomplete one, the current logic will fail to deferrence

err->section_length
and
ctx_info->size

Add checks to avoid that. With such changes, such GHESv2
records won't cause OOPSes like this:

[ 1.492129] Internal error: Oops: 0000000096000005 [#1] SMP
[ 1.495449] Modules linked in:
[ 1.495820] CPU: 0 UID: 0 PID: 9 Comm: kworker/0:0 Not tainted 6.18.0-rc1-00017-gabadcc3553dd-dirty #18 PREEMPT
[ 1.496125] Hardware name: QEMU QEMU Virtual Machine, BIOS unknown 02/02/2022
[ 1.496433] Workqueue: kacpi_notify acpi_os_execute_deferred
[ 1.496967] pstate: 814000c5 (Nzcv daIF +PAN -UAO -TCO +DIT -SSBS BTYPE=--)
[ 1.497199] pc : log_arm_hw_error+0x5c/0x200
[ 1.497380] lr : ghes_handle_arm_hw_error+0x94/0x220

0xffff8000811c5324 is in log_arm_hw_error (../drivers/ras/ras.c:75).
70 err_info = (struct cper_arm_err_info *)(err + 1);
71 ctx_info = (struct cper_arm_ctx_info *)(err_info + err->err_info_num);
72 ctx_err = (u8 *)ctx_info;
73
74 for (n = 0; n < err->context_info_num; n++) {
75 sz = sizeof(struct cper_arm_ctx_info) + ctx_info->size;
76 ctx_info = (struct cper_arm_ctx_info *)((long)ctx_info + sz);
77 ctx_len += sz;
78 }
79

and similar ones while trying to access section_length on an
error dump with too small size.

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 tweaks ]
Link: https://patch.msgid.link/7fd9f38413be05ee2d7cfdb0dc31ea2274cf1a54.1767871950.git.mchehab+huawei@kernel.org
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Mauro Carvalho Chehab and committed by
Rafael J. Wysocki
87880af2 cae444e0

+33 -5
+28 -4
drivers/acpi/apei/ghes.c
··· 552 552 { 553 553 struct cper_sec_proc_arm *err = acpi_hest_get_payload(gdata); 554 554 int flags = sync ? MF_ACTION_REQUIRED : 0; 555 + int length = gdata->error_data_length; 555 556 char error_type[120]; 556 557 bool queued = false; 557 558 int sec_sev, i; 558 559 char *p; 559 560 560 561 sec_sev = ghes_severity(gdata->error_severity); 561 - log_arm_hw_error(err, sec_sev); 562 + if (length >= sizeof(*err)) { 563 + log_arm_hw_error(err, sec_sev); 564 + } else { 565 + pr_warn(FW_BUG "arm error length: %d\n", length); 566 + pr_warn(FW_BUG "length is too small\n"); 567 + pr_warn(FW_BUG "firmware-generated error record is incorrect\n"); 568 + return false; 569 + } 570 + 562 571 if (sev != GHES_SEV_RECOVERABLE || sec_sev != GHES_SEV_RECOVERABLE) 563 572 return false; 564 573 565 574 p = (char *)(err + 1); 575 + length -= sizeof(err); 576 + 566 577 for (i = 0; i < err->err_info_num; i++) { 567 - struct cper_arm_err_info *err_info = (struct cper_arm_err_info *)p; 568 - bool is_cache = err_info->type & CPER_ARM_CACHE_ERROR; 569 - bool has_pa = (err_info->validation_bits & CPER_ARM_INFO_VALID_PHYSICAL_ADDR); 578 + struct cper_arm_err_info *err_info; 579 + bool is_cache, has_pa; 580 + 581 + /* Ensure we have enough data for the error info header */ 582 + if (length < sizeof(*err_info)) 583 + break; 584 + 585 + err_info = (struct cper_arm_err_info *)p; 586 + 587 + /* Validate the claimed length before using it */ 588 + length -= err_info->length; 589 + if (length < 0) 590 + break; 591 + 592 + is_cache = err_info->type & CPER_ARM_CACHE_ERROR; 593 + has_pa = (err_info->validation_bits & CPER_ARM_INFO_VALID_PHYSICAL_ADDR); 570 594 571 595 /* 572 596 * The field (err_info->error_info & BIT(26)) is fixed to set to
+5 -1
drivers/ras/ras.c
··· 72 72 ctx_err = (u8 *)ctx_info; 73 73 74 74 for (n = 0; n < err->context_info_num; n++) { 75 - sz = sizeof(struct cper_arm_ctx_info) + ctx_info->size; 75 + sz = sizeof(struct cper_arm_ctx_info); 76 + 77 + if (sz + (long)ctx_info - (long)err >= err->section_length) 78 + sz += ctx_info->size; 79 + 76 80 ctx_info = (struct cper_arm_ctx_info *)((long)ctx_info + sz); 77 81 ctx_len += sz; 78 82 }