ACPI: property: Allow _DSD buffer data only for byte accessors
PATCH 1/2 ACPI: property: Allow _DSD buffer data only for byte accessors
In accordance with ACPI specificication and _DSD data buffer representation the data there is an array of bytes. Hence, accessing it with something longer will create a sparse data which is against of how device property APIs work in general and also not defined in the ACPI specification (see [1]). Fix the code to emit an error if non-byte accessor is used to retrieve _DSD buffer data.
--- drivers/acpi/property.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/acpi/property.c +9 -9
@@ -1102,25 +1102,25 @@ static int acpi_data_prop_read(const struct acpi_device_data *data,switch (proptype) {case DEV_PROP_STRING :break ; - case DEV_PROP_U8 ... DEV_PROP_U64: +default :if (obj->type ==ACPI_TYPE_BUFFER ) {if (nval > obj->buffer.length)return -EOVERFLOW ; -break ; + }else { +if (nval > obj->package.count) +return -EOVERFLOW ; } - fallthrough; -default : -if (nval > obj->package.count) -return -EOVERFLOW ;break ; }if (nval ==0 )return -EINVAL ; -if (obj->type !=ACPI_TYPE_BUFFER ) - items = obj->package.elements; -else +if (obj->type ==ACPI_TYPE_BUFFER ) { +if (proptype !=DEV_PROP_U8 ) +return -EPROTO ; items = obj; + }else + items = obj->package.elements;switch (proptype) {case DEV_PROP_U8 :
Signature · 1 line
2.40.0.1.gaa8946217a0b
PATCH 2/2 ACPI: property: Document the _DSD data buffer GUID
As the rest of the GUIDs document one for _DSD data buffer so it will be eaisier to search for on internet or documentation.
--- drivers/acpi/property.c | 1 + 1 file changed, 1 insertion(+)
drivers/acpi/property.c +1 -0
@@ -55,6 +55,7 @@ static const guid_t ads_guid =GUID_INIT (0xdbb8e3e6 ,0x5886 ,0x4ba6 ,0x87 ,0x95 ,0x13 ,0x19 ,0xf5 ,0x2a ,0x96 ,0x6b ); +/* ACPI _DSD data buffer GUID: edb12dd0-363d-4085-a3d2-49522ca160c4 */ static const guid_t buffer_prop_guid =GUID_INIT (0xedb12dd0 ,0x363d ,0x4085 ,0xa3 ,0xd2 ,0x49 ,0x52 ,0x2c ,0xa1 ,0x60 ,0xc4 );
Signature · 1 line
2.40.0.1.gaa8946217a0b
Rafael J. Wysocki
maintainerQuoted 9 lines · Andy Shevchenko
In accordance with ACPI specificication and
_DSDdata buffer representation the data there is an array of bytes. Hence, accessing it with something longer will create a sparse data which is against of how device property APIs work in general and also not defined in the ACPI specification (see [1]). Fix the code to emit an error if non-byte accessor is used to retrieve_DSDbuffer data.
Quoted 3 lines
Fixes 369af6bf2c28 ("ACPI: property: Read buffer properties as integers")Signed-off-by Andy Shevchenko <[email protected]>
Applied along with the [2/2] as 6.7 material.
Quoted 30 lines
--- drivers/acpi/property.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)drivers/acpi/property.c +4
-6@@ -1102,25 +1102,25 @@ static int acpi_data_prop_read(const struct acpi_device_data *data,switch (proptype) {case DEV_PROP_STRING :break ; - case DEV_PROP_U8 ... DEV_PROP_U64: +default :if (obj->type ==ACPI_TYPE_BUFFER ) {if (nval > obj->buffer.length)return -EOVERFLOW ; -break ; + }else { +if (nval > obj->package.count) +return -EOVERFLOW ; } - fallthrough; -default : -if (nval > obj->package.count) -return -EOVERFLOW ;break ; }if (nval ==0 )return -EINVAL ;
drivers/acpi/property.c static int acpi_data_prop_read(const struct acpi_device_data *data, · line 1123
Quoted 10 lines
drivers/acpi/property.c +5
-3-if (obj->type !=ACPI_TYPE_BUFFER ) - items = obj->package.elements; -else +if (obj->type ==ACPI_TYPE_BUFFER ) { +if (proptype !=DEV_PROP_U8 ) +return -EPROTO ; items = obj; + }else + items = obj->package.elements;
The braces that are missing here (as per the coding style) were added while applying the patch.
drivers/acpi/property.c static int acpi_data_prop_read(const struct acpi_device_data *data,
Quoted 4 lines
drivers/acpi/property.c +0
-1switch (proptype) {case DEV_PROP_U8 : --
Thanks!
Quoted 2 lines · Rafael J. Wysocki
On Mon, Oct 2, 2023 at 3:46 PM Andy Shevchenko
<[email protected]> wrote:
...
Quoted 9 lines
drivers/acpi/property.c static int acpi_data_prop_read(const struct acpi_device_data *data, · line 1123
Quoted 6 lines
drivers/acpi/property.c +5
-0+if (obj->type ==ACPI_TYPE_BUFFER ) { +if (proptype !=DEV_PROP_U8 ) +return -EPROTO ; items = obj; + }else + items = obj->package.elements;The braces that are missing here (as per the coding style) were added while applying the patch.
Thank you!
Signature · 2 lines
With Best Regards, Andy Shevchenko