* [PATCH] tools/wmi: Check the Dell SMBIOS buffer size read
@ 2026-11-20 6:19 Zhu Jun
2026-11-20 9:45 ` Ilpo Järvinen
0 siblings, 1 reply; 2+ messages in thread
From: Zhu Jun @ 2026-11-20 6:19 UTC (permalink / raw)
To: platform-driver-x86
Cc: hansg, ilpo.jarvinen, Dell.Client.Kernel, linux-kernel, Zhu Jun
query_buffer_size() ignores an incomplete read, and main() can use a
partial size or reach free() before buffer has been initialized.
Require a complete size read and return failure before allocating or
freeing a buffer when the size is unavailable.
Fixes: 9d64fc08f6fe ("tools/wmi: add a sample for dell smbios communication over WMI")
Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
---
tools/wmi/dell-smbios-example.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/tools/wmi/dell-smbios-example.c b/tools/wmi/dell-smbios-example.c
index 1f3e7ab14b68..a4c63a6a0ee3 100644
--- a/tools/wmi/dell-smbios-example.c
+++ b/tools/wmi/dell-smbios-example.c
@@ -143,13 +143,15 @@ static int activate_token(struct dell_wmi_smbios_buffer *buffer,
static int query_buffer_size(__u64 *buffer_size)
{
FILE *f;
+ int ret;
f = fopen(ioctl_devfs, "rb");
if (!f)
- return -EINVAL;
- fread(buffer_size, sizeof(__u64), 1, f);
+ return -errno;
+ ret = fread(buffer_size, sizeof(*buffer_size), 1, f) == 1 ? 0 : -EIO;
fclose(f);
- return EXIT_SUCCESS;
+
+ return ret;
}
int main(void)
@@ -159,9 +161,9 @@ int main(void)
__u64 value = 0;
ret = query_buffer_size(&value);
- if (ret == EXIT_FAILURE || !value) {
+ if (ret || !value) {
printf("Unable to read buffer size\n");
- goto out;
+ return EXIT_FAILURE;
}
printf("Detected required buffer size %lld\n", value);
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] tools/wmi: Check the Dell SMBIOS buffer size read
2026-11-20 6:19 [PATCH] tools/wmi: Check the Dell SMBIOS buffer size read Zhu Jun
@ 2026-11-20 9:45 ` Ilpo Järvinen
0 siblings, 0 replies; 2+ messages in thread
From: Ilpo Järvinen @ 2026-11-20 9:45 UTC (permalink / raw)
To: Zhu Jun; +Cc: platform-driver-x86, Hans de Goede, Dell.Client.Kernel, LKML
In Fri, 20 Nov 2026, Zhu Jun wrote:
> query_buffer_size() ignores an incomplete read, and main() can use a
> partial size or reach free() before buffer has been initialized.
Huh?
free() doesn't care whether buffer is initialized or not, as long as it's
allocated?!?
> Require a complete size read and return failure before allocating or
> freeing a buffer when the size is unavailable.
>
> Fixes: 9d64fc08f6fe ("tools/wmi: add a sample for dell smbios communication over WMI")
> Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
> ---
> tools/wmi/dell-smbios-example.c | 12 +++++++-----
> 1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/tools/wmi/dell-smbios-example.c b/tools/wmi/dell-smbios-example.c
> index 1f3e7ab14b68..a4c63a6a0ee3 100644
> --- a/tools/wmi/dell-smbios-example.c
> +++ b/tools/wmi/dell-smbios-example.c
> @@ -143,13 +143,15 @@ static int activate_token(struct dell_wmi_smbios_buffer *buffer,
> static int query_buffer_size(__u64 *buffer_size)
> {
> FILE *f;
> + int ret;
>
> f = fopen(ioctl_devfs, "rb");
> if (!f)
> - return -EINVAL;
> - fread(buffer_size, sizeof(__u64), 1, f);
> + return -errno;
Look unreleated change to me.
Please make a proper series, with minimal, logical change done in each
patch instead.
> + ret = fread(buffer_size, sizeof(*buffer_size), 1, f) == 1 ? 0 : -EIO;
Could we like write this so it follows the normal style.
> fclose(f);
> - return EXIT_SUCCESS;
> +
> + return ret;
> }
>
> int main(void)
> @@ -159,9 +161,9 @@ int main(void)
> __u64 value = 0;
>
> ret = query_buffer_size(&value);
> - if (ret == EXIT_FAILURE || !value) {
> + if (ret || !value) {
> printf("Unable to read buffer size\n");
> - goto out;
> + return EXIT_FAILURE;
So this longer frees the buffer?
> }
> printf("Detected required buffer size %lld\n", value);
>
>
>
--
i.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-20 9:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 6:19 [PATCH] tools/wmi: Check the Dell SMBIOS buffer size read Zhu Jun
2026-11-20 9:45 ` Ilpo Järvinen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).