lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20241002213741.GA280235@bhelgaas>
Date: Wed, 2 Oct 2024 16:37:41 -0500
From: Bjorn Helgaas <helgaas@...nel.org>
To: Todd Kjos <tkjos@...gle.com>
Cc: kernel-team@...roid.com, bhelgaas@...gle.com, linux-pci@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH] PCI: fix memory leak in reset_method_store()

On Tue, Oct 01, 2024 at 11:11:47PM +0000, Todd Kjos wrote:
> In reset_method_store(), a string is allocated via kstrndup()
> and assigned to the local "options". options is then used
> in with strsep() to find spaces:
> 
>   while ((name = strsep(&options, " ")) != NULL) {
> 
> If there are no remaining spaces, then options is set to NULL
> by strsep(), so the subsequent kfree(options) doesn't free the
> memory allocated via kstrndup().
> 
> Fix by using a separate tmp_options to iterate with
> strsep() so options is preserved.
> 
> Fixes: d88f521da3ef ("PCI: Allow userspace to query and set device reset mechanism")
> Signed-off-by: Todd Kjos <tkjos@...gle.com>

Applied to pci/misc for v6.13, thank you!

> ---
>  drivers/pci/pci.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 7d85c04fbba2..0e6562ff3dcf 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -5244,7 +5244,7 @@ static ssize_t reset_method_store(struct device *dev,
>  				  const char *buf, size_t count)
>  {
>  	struct pci_dev *pdev = to_pci_dev(dev);
> -	char *options, *name;
> +	char *options, *tmp_options, *name;
>  	int m, n;
>  	u8 reset_methods[PCI_NUM_RESET_METHODS] = { 0 };
>  
> @@ -5264,7 +5264,8 @@ static ssize_t reset_method_store(struct device *dev,
>  		return -ENOMEM;
>  
>  	n = 0;
> -	while ((name = strsep(&options, " ")) != NULL) {
> +	tmp_options = options;
> +	while ((name = strsep(&tmp_options, " ")) != NULL) {
>  		if (sysfs_streq(name, ""))
>  			continue;
>  
> -- 
> 2.46.1.824.gd892dcdcdd-goog
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ