Skip to content

Commit ae6b3e5

Browse files
jwrdegoederafaeljw
authored andcommitted
ACPICA: Fix handling of buffer-size in acpi_ex_write_data_to_field()
Generic Serial Bus transfers use a data struct like this: struct gsb_buffer { u8 status; u8 len; u8 data[0]; }; acpi_ex_write_data_to_field() copies the data which is to be written from the source-buffer to a temp-buffer. This is done because the OpReg-handler overwrites the status field and some transfers do a write + read-back. Commit f99b89e ("ACPICA: Update for generic_serial_bus and attrib_raw_process_bytes protocol") acpi_ex_write_data_to_field() introduces a number of problems with this: 1) It drops a "length += 2" statement used to calculate the temp-buffer size causing the temp-buffer to only be 1/2 bytes large for byte/word transfers while it should be 3/4 bytes (taking the status and len field into account). This is already fixed in commit e324e10 ("ACPICA: Update for field unit access") which refactors the code. The ACPI 6.0 spec (ACPI_6.0.pdf) "5.5.2.4.5.2 Declaring and Using a GenericSerialBusData Buffer" (page 232) states that the GenericSerialBus Data Buffer Length field is only valid when doing a Read/Write Block (AttribBlock) transfer, but since the troublesome commit we unconditionally use the len field to determine how much data to copy from the source-buffer into the temp-buffer passed to the OpRegion. This causes 3 further issues: 2) This may lead to not copying enough data to the temp-buffer causing the OpRegion handler for the serial-bus to write garbage to the hardware. 3) The temp-buffer passed to the OpRegion is allocated to the size returned by acpi_ex_get_serial_access_length(), which may be as little as 1, so potentially this may lead to a write overflow of the temp-buffer. 4) Commit e324e10 ("ACPICA: Update for field unit access") drops a length check on the source-buffer, leading to a potential read overflow of the source-buffer. This commit fixes all 3 remaining issues by not looking at the len field at all (the interpretation of this field is left up to the OpRegion handler), and copying the minimum of the source- and temp-buffer sizes from the source-buffer to the temp-buffer. This fixes e.g. an Acer S1003 no longer booting since the troublesome commit. Fixes: f99b89e (ACPICA: Update for generic_serial_bus and ...) Fixes: e324e10 (ACPICA: Update for field unit access) Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 9ff0119 commit ae6b3e5

1 file changed

Lines changed: 2 additions & 19 deletions

File tree

‎drivers/acpi/acpica/exserial.c‎

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ acpi_ex_write_serial_bus(union acpi_operand_object *source_desc,
244244
{
245245
acpi_status status;
246246
u32 buffer_length;
247-
u32 data_length;
248247
void *buffer;
249248
union acpi_operand_object *buffer_desc;
250249
u32 function;
@@ -282,14 +281,12 @@ acpi_ex_write_serial_bus(union acpi_operand_object *source_desc,
282281
case ACPI_ADR_SPACE_SMBUS:
283282

284283
buffer_length = ACPI_SMBUS_BUFFER_SIZE;
285-
data_length = ACPI_SMBUS_DATA_SIZE;
286284
function = ACPI_WRITE | (obj_desc->field.attribute << 16);
287285
break;
288286

289287
case ACPI_ADR_SPACE_IPMI:
290288

291289
buffer_length = ACPI_IPMI_BUFFER_SIZE;
292-
data_length = ACPI_IPMI_DATA_SIZE;
293290
function = ACPI_WRITE;
294291
break;
295292

@@ -310,28 +307,13 @@ acpi_ex_write_serial_bus(union acpi_operand_object *source_desc,
310307
/* Add header length to get the full size of the buffer */
311308

312309
buffer_length += ACPI_SERIAL_HEADER_SIZE;
313-
data_length = source_desc->buffer.pointer[1];
314310
function = ACPI_WRITE | (accessor_type << 16);
315311
break;
316312

317313
default:
318314
return_ACPI_STATUS(AE_AML_INVALID_SPACE_ID);
319315
}
320316

321-
#if 0
322-
OBSOLETE ?
323-
/* Check for possible buffer overflow */
324-
if (data_length > source_desc->buffer.length) {
325-
ACPI_ERROR((AE_INFO,
326-
"Length in buffer header (%u)(%u) is greater than "
327-
"the physical buffer length (%u) and will overflow",
328-
data_length, buffer_length,
329-
source_desc->buffer.length));
330-
331-
return_ACPI_STATUS(AE_AML_BUFFER_LIMIT);
332-
}
333-
#endif
334-
335317
/* Create the transfer/bidirectional/return buffer */
336318

337319
buffer_desc = acpi_ut_create_buffer_object(buffer_length);
@@ -342,7 +324,8 @@ acpi_ex_write_serial_bus(union acpi_operand_object *source_desc,
342324
/* Copy the input buffer data to the transfer buffer */
343325

344326
buffer = buffer_desc->buffer.pointer;
345-
memcpy(buffer, source_desc->buffer.pointer, data_length);
327+
memcpy(buffer, source_desc->buffer.pointer,
328+
min(buffer_length, source_desc->buffer.length));
346329

347330
/* Lock entire transaction if requested */
348331

0 commit comments

Comments
 (0)