Skip to content

Commit db103b8

Browse files
mchehabSasha Levin
authored andcommitted
APEI/GHES: ARM processor Error: don't go past allocated memory
[ Upstream commit 87880af ] 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 Rust-for-Linux#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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 98bd9b2 commit db103b8

2 files changed

Lines changed: 33 additions & 5 deletions

File tree

drivers/acpi/apei/ghes.c

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -556,21 +556,45 @@ static bool ghes_handle_arm_hw_error(struct acpi_hest_generic_data *gdata,
556556
{
557557
struct cper_sec_proc_arm *err = acpi_hest_get_payload(gdata);
558558
int flags = sync ? MF_ACTION_REQUIRED : 0;
559+
int length = gdata->error_data_length;
559560
char error_type[120];
560561
bool queued = false;
561562
int sec_sev, i;
562563
char *p;
563564

564565
sec_sev = ghes_severity(gdata->error_severity);
565-
log_arm_hw_error(err, sec_sev);
566+
if (length >= sizeof(*err)) {
567+
log_arm_hw_error(err, sec_sev);
568+
} else {
569+
pr_warn(FW_BUG "arm error length: %d\n", length);
570+
pr_warn(FW_BUG "length is too small\n");
571+
pr_warn(FW_BUG "firmware-generated error record is incorrect\n");
572+
return false;
573+
}
574+
566575
if (sev != GHES_SEV_RECOVERABLE || sec_sev != GHES_SEV_RECOVERABLE)
567576
return false;
568577

569578
p = (char *)(err + 1);
579+
length -= sizeof(err);
580+
570581
for (i = 0; i < err->err_info_num; i++) {
571-
struct cper_arm_err_info *err_info = (struct cper_arm_err_info *)p;
572-
bool is_cache = err_info->type & CPER_ARM_CACHE_ERROR;
573-
bool has_pa = (err_info->validation_bits & CPER_ARM_INFO_VALID_PHYSICAL_ADDR);
582+
struct cper_arm_err_info *err_info;
583+
bool is_cache, has_pa;
584+
585+
/* Ensure we have enough data for the error info header */
586+
if (length < sizeof(*err_info))
587+
break;
588+
589+
err_info = (struct cper_arm_err_info *)p;
590+
591+
/* Validate the claimed length before using it */
592+
length -= err_info->length;
593+
if (length < 0)
594+
break;
595+
596+
is_cache = err_info->type & CPER_ARM_CACHE_ERROR;
597+
has_pa = (err_info->validation_bits & CPER_ARM_INFO_VALID_PHYSICAL_ADDR);
574598

575599
/*
576600
* The field (err_info->error_info & BIT(26)) is fixed to set to

drivers/ras/ras.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ void log_arm_hw_error(struct cper_sec_proc_arm *err, const u8 sev)
7272
ctx_err = (u8 *)ctx_info;
7373

7474
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+
7680
ctx_info = (struct cper_arm_ctx_info *)((long)ctx_info + sz);
7781
ctx_len += sz;
7882
}

0 commit comments

Comments
 (0)