mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Zhu Jun <zhujun2@cmss.chinamobile.com>
Cc: platform-driver-x86@vger.kernel.org,
	Hans de Goede <hansg@kernel.org>,
	 Dell.Client.Kernel@dell.com, LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] tools/wmi: Check the Dell SMBIOS buffer size read
Date: Fri, 20 Nov 2026 11:45:46 +0200 (EET)	[thread overview]
Message-ID: <3cbdaae9-d586-ceb3-e035-5f734080b0a9@linux.intel.com> (raw)
In-Reply-To: <20261120061927.98196-1-zhujun2@cmss.chinamobile.com>

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.


      reply	other threads:[~2026-11-20  9:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  6:19 Zhu Jun
2026-11-20  9:45 ` Ilpo Järvinen [this message]

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=3cbdaae9-d586-ceb3-e035-5f734080b0a9@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=Dell.Client.Kernel@dell.com \
    --cc=hansg@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=zhujun2@cmss.chinamobile.com \
    /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®