[PATCH v2 38/42] ACPICA: executer: Fix copying PCC source buffer data

From: Maciej Wieczor-Retman

Date: Fri Nov 20 2026 - 12:24:13 EST


Paths leading up to AcpiExWriteDataToField() group Integer, Buffer and
String together when handling the operand type. In the operand type
union, the integer's value and buffer's pointer share the same space.

One issue can be that the number stored in integer.value is interpreted
as buffer.pointer - which can happen if ACPI_TYPE_INTEGER is the source
operand type. The following code should result in a memory fault as it
will read the value as the address, and won't use the address of the
variable as it should:

COMD = 0x01

Other problem is if SourceDesc->Buffer.Length is smaller than DataLength
- then more data will be read from the source operand than planned. For
example the following ASL code would result in extra data getting read
from BUF0 to COSP:

Name (BUF0, Buffer (2) {0x01, 0x02})
COSP = BUF0

Fix the first problem by moving the Buffer and BufferLength assignment
before the PCC buffer code path.

Fix the second problem by copying only as much space as the source
operand has. If it has less than the destination just zero-extend the
extra space as similar Field operations do (AcpiExInsertIntoField() for
example).

Link: https://github.com/acpica/acpica/commit/9ea9025e30bd
Fixes: aa6ec56b574d ("ACPICA: ACPI 6.3: add PCC operation region support for AML interpreter")
Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@xxxxxxxxx>
---
drivers/acpi/acpica/exfield.c | 63 ++++++++++++++++++++---------------
1 file changed, 36 insertions(+), 27 deletions(-)

diff --git a/drivers/acpi/acpica/exfield.c b/drivers/acpi/acpica/exfield.c
index 632fc8693f23..2199d054ed58 100644
--- a/drivers/acpi/acpica/exfield.c
+++ b/drivers/acpi/acpica/exfield.c
@@ -291,6 +291,7 @@ acpi_ex_write_data_to_field(union acpi_operand_object *source_desc,
acpi_status status;
u32 buffer_length;
u32 data_length;
+ u32 copy_length;
void *buffer;

ACPI_FUNCTION_TRACE_PTR(ex_write_data_to_field, obj_desc);
@@ -338,7 +339,34 @@ acpi_ex_write_data_to_field(union acpi_operand_object *source_desc,
acpi_ex_write_serial_bus(source_desc, obj_desc,
result_desc);
return_ACPI_STATUS(status);
- } else if ((obj_desc->common.type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
+ }
+
+ /* Get a pointer to the data to be written */
+
+ switch (source_desc->common.type) {
+ case ACPI_TYPE_INTEGER:
+
+ buffer = &source_desc->integer.value;
+ buffer_length = sizeof(source_desc->integer.value);
+ break;
+
+ case ACPI_TYPE_BUFFER:
+
+ buffer = source_desc->buffer.pointer;
+ buffer_length = source_desc->buffer.length;
+ break;
+
+ case ACPI_TYPE_STRING:
+
+ buffer = source_desc->string.pointer;
+ buffer_length = source_desc->string.length;
+ break;
+
+ default:
+ return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
+ }
+
+ if ((obj_desc->common.type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
(obj_desc->field.region_obj->region.space_id ==
ACPI_ADR_SPACE_PLATFORM_COMM)) {
/*
@@ -369,9 +397,15 @@ acpi_ex_write_data_to_field(union acpi_operand_object *source_desc,
return_ACPI_STATUS(AE_AML_BUFFER_LIMIT);
}

+ copy_length = ACPI_MIN(data_length, buffer_length);
+
+ memset(obj_desc->field.region_obj->field.internal_pcc_buffer +
+ obj_desc->field.base_byte_offset,
+ 0, data_length);
+
memcpy(obj_desc->field.region_obj->field.internal_pcc_buffer +
obj_desc->field.base_byte_offset,
- source_desc->buffer.pointer, data_length);
+ buffer, copy_length);

if (MASTER_SUBSPACE_COMMAND(obj_desc->field.base_byte_offset)) {

@@ -391,31 +425,6 @@ acpi_ex_write_data_to_field(union acpi_operand_object *source_desc,
return (AE_OK);
}

- /* Get a pointer to the data to be written */
-
- switch (source_desc->common.type) {
- case ACPI_TYPE_INTEGER:
-
- buffer = &source_desc->integer.value;
- buffer_length = sizeof(source_desc->integer.value);
- break;
-
- case ACPI_TYPE_BUFFER:
-
- buffer = source_desc->buffer.pointer;
- buffer_length = source_desc->buffer.length;
- break;
-
- case ACPI_TYPE_STRING:
-
- buffer = source_desc->string.pointer;
- buffer_length = source_desc->string.length;
- break;
-
- default:
- return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
- }
-
ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
"FieldWrite [FROM]: Obj %p (%s:%X), Buf %p, ByteLen %X\n",
source_desc,
--
2.56.0