ACPI: property: Allow _DSD buffer data only for byte accessors
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Mon, 2 Oct 2023 13:46:29 +0000 (16:46 +0300)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 3 Oct 2023 13:57:05 +0000 (15:57 +0200)
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.

Fixes: 369af6bf2c28 ("ACPI: property: Read buffer properties as integers")
Link: https://uefi.org/specs/ACPI/6.5/19_ASL_Reference.html#buffer-declare-buffer-object
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
[ rjw: Add missing braces ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/acpi/property.c

index 413e4fcadcaf7bd38d8fdf9f53d1c54d3f0d6972..99b4e33554355227e223a2f145859d6a2a8ad8b7 100644 (file)
@@ -1102,25 +1102,26 @@ 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: