@@ -60,11 +60,19 @@ acpi_ex_get_serial_access_length(u32 accessor_type, u32 access_length)
6060
6161 case AML_FIELD_ATTRIB_MULTIBYTE :
6262 case AML_FIELD_ATTRIB_RAW_BYTES :
63- case AML_FIELD_ATTRIB_RAW_PROCESS :
6463
6564 length = access_length ;
6665 break ;
6766
67+ case AML_FIELD_ATTRIB_RAW_PROCESS :
68+ /*
69+ * Worst case bidirectional buffer size. This ignores the
70+ * access_length argument to access_as because it is not needed.
71+ * August 2018.
72+ */
73+ length = ACPI_MAX_GSBUS_BUFFER_SIZE ;
74+ break ;
75+
6876 case AML_FIELD_ATTRIB_BLOCK :
6977 case AML_FIELD_ATTRIB_BLOCK_CALL :
7078 default :
@@ -147,6 +155,13 @@ acpi_ex_read_data_from_field(struct acpi_walk_state *walk_state,
147155 } else if (obj_desc -> field .region_obj -> region .space_id ==
148156 ACPI_ADR_SPACE_GSBUS ) {
149157 accessor_type = obj_desc -> field .attribute ;
158+ if (accessor_type == AML_FIELD_ATTRIB_RAW_PROCESS ) {
159+ ACPI_ERROR ((AE_INFO ,
160+ "Invalid direct read using bidirectional write-then-read protocol" ));
161+
162+ return_ACPI_STATUS (AE_AML_PROTOCOL );
163+ }
164+
150165 length =
151166 acpi_ex_get_serial_access_length (accessor_type ,
152167 obj_desc -> field .
@@ -305,6 +320,7 @@ acpi_ex_write_data_to_field(union acpi_operand_object *source_desc,
305320{
306321 acpi_status status ;
307322 u32 length ;
323+ u32 data_length ;
308324 void * buffer ;
309325 union acpi_operand_object * buffer_desc ;
310326 u32 function ;
@@ -361,6 +377,7 @@ acpi_ex_write_data_to_field(union acpi_operand_object *source_desc,
361377 if (obj_desc -> field .region_obj -> region .space_id ==
362378 ACPI_ADR_SPACE_SMBUS ) {
363379 length = ACPI_SMBUS_BUFFER_SIZE ;
380+ data_length = length ;
364381 function =
365382 ACPI_WRITE | (obj_desc -> field .attribute << 16 );
366383 } else if (obj_desc -> field .region_obj -> region .space_id ==
@@ -372,38 +389,47 @@ acpi_ex_write_data_to_field(union acpi_operand_object *source_desc,
372389 access_length );
373390
374391 /*
375- * Add additional 2 bytes for the generic_serial_bus data buffer:
376- *
392+ * Buffer format for Generic Serial Bus protocols:
377393 * Status; (Byte 0 of the data buffer)
378394 * Length; (Byte 1 of the data buffer)
379395 * Data[x-1]: (Bytes 2-x of the arbitrary length data buffer)
380396 */
381- length += 2 ;
397+ data_length = source_desc -> buffer .pointer [1 ]; /* Data length is 2nd byte */
398+ if (!data_length ) {
399+ ACPI_ERROR ((AE_INFO ,
400+ "Invalid zero data length in transfer buffer" ));
401+
402+ return_ACPI_STATUS (AE_AML_BUFFER_LENGTH );
403+ }
404+
382405 function = ACPI_WRITE | (accessor_type << 16 );
383406 } else { /* IPMI */
384407
385408 length = ACPI_IPMI_BUFFER_SIZE ;
409+ data_length = length ;
386410 function = ACPI_WRITE ;
387411 }
388412
389- if (source_desc -> buffer .length < length ) {
413+ if (source_desc -> buffer .length < data_length ) {
390414 ACPI_ERROR ((AE_INFO ,
391415 "SMBus/IPMI/GenericSerialBus write requires "
392- "Buffer of length %u, found length %u" ,
393- length , source_desc -> buffer .length ));
416+ "Buffer data length %u, found buffer length %u" ,
417+ data_length , source_desc -> buffer .length ));
394418
395419 return_ACPI_STATUS (AE_AML_BUFFER_LIMIT );
396420 }
397421
398- /* Create the bi-directional buffer */
422+ /* Create the transfer/bidirectional buffer */
399423
400424 buffer_desc = acpi_ut_create_buffer_object (length );
401425 if (!buffer_desc ) {
402426 return_ACPI_STATUS (AE_NO_MEMORY );
403427 }
404428
429+ /* Copy the input buffer data to the transfer buffer */
430+
405431 buffer = buffer_desc -> buffer .pointer ;
406- memcpy (buffer , source_desc -> buffer .pointer , length );
432+ memcpy (buffer , source_desc -> buffer .pointer , data_length );
407433
408434 /* Lock entire transaction if requested */
409435
0 commit comments