From: Armin Wolf <W_Armin@gmx.de>
To: hansg@kernel.org
Cc: ilpo.jarvinen@linux.intel.com,
platform-driver-x86@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 5/6] platform/wmi: Extend wmidev_query_block() to reject undersized data
Date: Mon, 6 Apr 2026 22:32:36 +0200 [thread overview]
Message-ID: <20260406203237.2970-6-W_Armin@gmx.de> (raw)
In-Reply-To: <20260406203237.2970-1-W_Armin@gmx.de>
WMI drivers using the buffer-based WMI API are expected to reject
undersized query results. Extend wmidev_query_block() to enable
the WMI driver core to perform this size check internally.
Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
drivers/platform/wmi/core.c | 10 ++++++----
drivers/platform/x86/intel/wmi/sbl-fw-update.c | 7 +------
drivers/platform/x86/wmi-bmof.c | 2 +-
include/linux/wmi.h | 3 ++-
4 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/drivers/platform/wmi/core.c b/drivers/platform/wmi/core.c
index a1a612f33233..87b0e54dde5a 100644
--- a/drivers/platform/wmi/core.c
+++ b/drivers/platform/wmi/core.c
@@ -565,13 +565,15 @@ EXPORT_SYMBOL_GPL(wmidev_block_query);
* @wdev: A wmi bus device from a driver
* @instance: Instance index
* @out: WMI buffer to fill
+ * @min_size: Minimum size of the result data in bytes
*
- * Query a WMI data block, the caller must free the resulting data inside @out.
- * Said data is guaranteed to be aligned on a 8-byte boundary.
+ * Query a WMI data block, the caller must free the resulting data inside @out
+ * using kfree(). Said data is guaranteed to be aligned on a 8-byte boundary.
*
* Return: 0 on success or a negative error code on failure.
*/
-int wmidev_query_block(struct wmi_device *wdev, u8 instance, struct wmi_buffer *out)
+int wmidev_query_block(struct wmi_device *wdev, u8 instance, struct wmi_buffer *out,
+ size_t min_size)
{
union acpi_object *obj;
int ret;
@@ -580,7 +582,7 @@ int wmidev_query_block(struct wmi_device *wdev, u8 instance, struct wmi_buffer *
if (!obj)
return -EIO;
- ret = wmi_unmarshal_acpi_object(obj, out, 0);
+ ret = wmi_unmarshal_acpi_object(obj, out, min_size);
kfree(obj);
return ret;
diff --git a/drivers/platform/x86/intel/wmi/sbl-fw-update.c b/drivers/platform/x86/intel/wmi/sbl-fw-update.c
index 3716ccaaed6a..62c9c7f1842b 100644
--- a/drivers/platform/x86/intel/wmi/sbl-fw-update.c
+++ b/drivers/platform/x86/intel/wmi/sbl-fw-update.c
@@ -28,15 +28,10 @@ static int get_fwu_request(struct device *dev, u32 *out)
__le32 *result;
int ret;
- ret = wmidev_query_block(to_wmi_device(dev), 0, &buffer);
+ ret = wmidev_query_block(to_wmi_device(dev), 0, &buffer, sizeof(*result));
if (ret < 0)
return ret;
- if (buffer.length < sizeof(*result)) {
- kfree(buffer.data);
- return -ENODATA;
- }
-
result = buffer.data;
*out = le32_to_cpu(*result);
kfree(result);
diff --git a/drivers/platform/x86/wmi-bmof.c b/drivers/platform/x86/wmi-bmof.c
index e3a126de421b..6623cf60e4b4 100644
--- a/drivers/platform/x86/wmi-bmof.c
+++ b/drivers/platform/x86/wmi-bmof.c
@@ -62,7 +62,7 @@ static int wmi_bmof_probe(struct wmi_device *wdev, const void *context)
if (!buffer)
return -ENOMEM;
- ret = wmidev_query_block(wdev, 0, buffer);
+ ret = wmidev_query_block(wdev, 0, buffer, 0);
if (ret < 0)
return ret;
diff --git a/include/linux/wmi.h b/include/linux/wmi.h
index 858398beb01a..da94580572a9 100644
--- a/include/linux/wmi.h
+++ b/include/linux/wmi.h
@@ -73,7 +73,8 @@ int wmidev_invoke_method(struct wmi_device *wdev, u8 instance, u32 method_id,
int wmidev_invoke_procedure(struct wmi_device *wdev, u8 instance, u32 method_id,
const struct wmi_buffer *in);
-int wmidev_query_block(struct wmi_device *wdev, u8 instance, struct wmi_buffer *out);
+int wmidev_query_block(struct wmi_device *wdev, u8 instance, struct wmi_buffer *out,
+ size_t min_size);
int wmidev_set_block(struct wmi_device *wdev, u8 instance, const struct wmi_buffer *in);
--
2.39.5
next prev parent reply other threads:[~2026-04-06 21:17 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-06 20:32 [PATCH 0/6] platform/wmi: Use WMI driver core for size checks Armin Wolf
2026-04-06 20:32 ` [PATCH 1/6] platform/wmi: Add wmidev_invoke_procedure() Armin Wolf
2026-04-06 20:32 ` [PATCH 2/6] platform/wmi: Convert drivers to use wmidev_invoke_procedure() Armin Wolf
2026-04-06 20:32 ` [PATCH 3/6] platform/wmi: Prepare to reject undersized unmarshalling results Armin Wolf
2026-04-06 20:32 ` [PATCH 4/6] platform/wmi: Extend wmidev_invoke_method() to reject undersized data Armin Wolf
2026-04-06 20:32 ` Armin Wolf [this message]
2026-04-06 20:32 ` [PATCH 6/6] platform/wmi: Replace .no_notify_data with .min_event_size Armin Wolf
2026-04-10 16:28 ` [PATCH 0/6] platform/wmi: Use WMI driver core for size checks Ilpo Järvinen
2026-04-13 6:20 ` Armin Wolf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260406203237.2970-6-W_Armin@gmx.de \
--to=w_armin@gmx.de \
--cc=hansg@kernel.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=platform-driver-x86@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®