return 0;
}
- ret = wmi_unmarshal_acpi_object(obj, out);
+ ret = wmi_unmarshal_acpi_object(obj, out, 0);
kfree(obj);
return ret;
if (!obj)
return -EIO;
- ret = wmi_unmarshal_acpi_object(obj, out);
+ ret = wmi_unmarshal_acpi_object(obj, out, 0);
kfree(obj);
return ret;
return;
}
- ret = wmi_unmarshal_acpi_object(obj, &buffer);
+ ret = wmi_unmarshal_acpi_object(obj, &buffer, 0);
if (ret < 0) {
dev_warn(&wblock->dev.dev, "Failed to unmarshal event data: %d\n", ret);
return;
union acpi_object;
struct wmi_buffer;
-int wmi_unmarshal_acpi_object(const union acpi_object *obj, struct wmi_buffer *buffer);
+int wmi_unmarshal_acpi_object(const union acpi_object *obj, struct wmi_buffer *buffer,
+ size_t min_size);
int wmi_marshal_string(const struct wmi_buffer *buffer, struct acpi_buffer *out);
#endif /* _WMI_INTERNAL_H_ */
return 0;
}
-int wmi_unmarshal_acpi_object(const union acpi_object *obj, struct wmi_buffer *buffer)
+int wmi_unmarshal_acpi_object(const union acpi_object *obj, struct wmi_buffer *buffer,
+ size_t min_size)
{
size_t length, alloc_length;
u8 *data;
if (ret < 0)
return ret;
+ if (length < min_size)
+ return -ENODATA;
+
if (ARCH_KMALLOC_MINALIGN < 8) {
/*
* kmalloc() guarantees that the alignment of the resulting memory allocation is at
struct wmi_buffer result;
int ret;
- ret = wmi_unmarshal_acpi_object(¶m->obj, &result);
+ ret = wmi_unmarshal_acpi_object(¶m->obj, &result, param->buffer.length);
if (ret < 0)
KUNIT_FAIL_AND_ABORT(test, "Unmarshalling of ACPI object failed\n");
struct wmi_buffer result;
int ret;
- ret = wmi_unmarshal_acpi_object(¶m->obj, &result);
+ ret = wmi_unmarshal_acpi_object(¶m->obj, &result, 0);
if (ret < 0)
return;
KUNIT_FAIL(test, "Invalid string was not rejected\n");
}
+static void wmi_unmarshal_acpi_object_undersized_test(struct kunit *test)
+{
+ const union acpi_object obj = {
+ .integer = {
+ .type = ACPI_TYPE_INTEGER,
+ .value = 0xdeadbeef,
+ },
+ };
+ struct wmi_buffer result;
+ int ret;
+
+ ret = wmi_unmarshal_acpi_object(&obj, &result, sizeof(expected_single_integer) + 1);
+ if (ret < 0)
+ return;
+
+ kfree(result.data);
+ KUNIT_FAIL(test, "Undersized unmarshalling result was not rejected\n");
+}
+
static struct kunit_case wmi_marshalling_test_cases[] = {
KUNIT_CASE_PARAM(wmi_unmarshal_acpi_object_test,
wmi_unmarshal_acpi_object_gen_params),
wmi_unmarshal_acpi_object_failure_gen_params),
KUNIT_CASE_PARAM(wmi_marshal_string_failure_test,
wmi_marshal_string_failure_gen_params),
+ KUNIT_CASE(wmi_unmarshal_acpi_object_undersized_test),
{}
};