mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [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	[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

all inboxes | Powered by JetHome®