Skip to contentSkip to conversation

apei/ghes: don't go past the ARM processor CPER record buffer

PATCH Jonathan Cameron 2 participants 2 messages Dec 8, 2025 – Dec 9, 2025 2 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): 0f03f383fa76e41747b95713d50350be21867ccb.1764326826.git.mchehab+huawei@kernel.org

#2 lore raw
Quoted 6 lines · On Fri, 28 Nov 2025 11:53:00 +0100 Mauro Carvalho Chehab…

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_lentgh, producing a very long dump. For instance, a 67

section_length

Quoted 54 lines

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

---
 drivers/acpi/apei/ghes.c        | 13 +++++++++++++
 drivers/firmware/efi/cper-arm.c | 14 +++++++++-----
 drivers/firmware/efi/cper.c     |  3 ++-
 include/linux/cper.h            |  3 ++-
 4 files changed, 26 insertions(+), 7 deletions(-)
drivers/acpi/apei/ghes.c +6 -0
index 56107aa00274..8b90b6f3e866 100644
@@ -557,6 +557,7 @@ static bool ghes_handle_arm_hw_error(struct acpi_hest_generic_data *gdata,
 {
 	struct cper_sec_proc_arm *err = acpi_hest_get_payload(gdata);
 	int flags = sync ? MF_ACTION_REQUIRED : 0;
+	int length = gdata->error_data_length;
 	char error_type[120];
 	bool queued = false;
 	int sec_sev, i;
@@ -568,7 +569,12 @@ static bool ghes_handle_arm_hw_error(struct acpi_hest_generic_data *gdata,
 		return false;
 
 	p = (char *)(err + 1);
+	length -= sizeof(err);
+
 	for (i = 0; i < err->err_info_num; i++) {
+		if (length <= 0)
+			break;
+
 		struct cper_arm_err_info *err_info = (struct cper_arm_err_info *)p;
 		bool is_cache = err_info->type & CPER_ARM_CACHE_ERROR;
 		bool has_pa = (err_info->validation_bits & CPER_ARM_INFO_VALID_PHYSICAL_ADDR);
@@ -580,10 +586,17 @@ static bool ghes_handle_arm_hw_error(struct acpi_hest_generic_data *gdata,
 		 * and don't filter out 'corrected' error here.
 		 */
 		if (is_cache && has_pa) {

drivers/acpi/apei/ghes.c static bool ghes_handle_arm_hw_error(struct acpi_hest_generic_data *gdata, · line 598

Quoted 10 lines
drivers/acpi/apei/ghes.c +6 -0
+			length -= err_info->length;
+			if (length < 0)
+				break;
 			queued = ghes_do_memory_failure(err_info->physical_fault_addr, flags);
 			p += err_info->length;
+
 			continue;
 		}
+		length -= err_info->length;
+			if (length < 0)

Indent odd.

Quoted 4 lines
drivers/acpi/apei/ghes.c +1 -0
+				break;
 
 		cper_bits_to_str(error_type, sizeof(error_type),
 				 FIELD_GET(CPER_ARM_ERR_TYPE_MASK, err_info->type),
#3 lore raw
In reply to a message not in the archive
Quoted 44 lines · Mauro Carvalho Chehab

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_lentgh, 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

---
  drivers/acpi/apei/ghes.c        | 13 +++++++++++++
  drivers/firmware/efi/cper-arm.c | 14 +++++++++-----
  drivers/firmware/efi/cper.c     |  3 ++-
  include/linux/cper.h            |  3 ++-
  4 files changed, 26 insertions(+), 7 deletions(-)
drivers/acpi/apei/ghes.c +1 -0
index 56107aa00274..8b90b6f3e866 100644
@@ -557,6 +557,7 @@ static bool ghes_handle_arm_hw_error(struct acpi_hest_generic_data *gdata,
  {
  	struct cper_sec_proc_arm *err = acpi_hest_get_payload(gdata);
  	int flags = sync ? MF_ACTION_REQUIRED : 0;
+	int length = gdata->error_data_length;
  	char error_type[120];
  	bool queued = false;
  	int sec_sev, i;

drivers/acpi/apei/ghes.c static bool ghes_handle_arm_hw_error(struct acpi_hest_generic_data *gdata, · line 577

Quoted 9 lines
drivers/acpi/apei/ghes.c +5 -0
@@ -568,7 +569,12 @@ static bool ghes_handle_arm_hw_error(struct acpi_hest_generic_data *gdata,
  		return false;
 
  	p = (char *)(err + 1);
+	length -= sizeof(err);
+
  	for (i = 0; i < err->err_info_num; i++) {
+		if (length <= 0)
+			break;
+

Hi, Mauro,

The bounds checking logic is duplicated - it appears both in the cache error handling branch and after it. This could be simplified. It would be better to ensure we have enough data for the error info header in one check.

		/* Ensure we have enough data for the error info header */
		if (length < sizeof(struct cper_arm_err_info))
			break;

And it would be better to validate the claimed length before using it.

		/* Validate the claimed length before using it */
		if (err_info->length < sizeof(struct cper_arm_err_info) ||
		    err_info->length > length)
			break;

Thanks.
Shuai