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: <20241219013923.2996224-1-make_ruc2021@163.com>
Date: Thu, 19 Dec 2024 09:39:23 +0800
From: Ma Ke <make_ruc2021@....com>
To: ilpo.jarvinen@...ux.intel.com
Cc: bhelgaas@...gle.com,
	linux-kernel@...r.kernel.org,
	linux-pci@...r.kernel.org,
	lukas@...ner.de,
	make_ruc2021@....com,
	rafael.j.wysocki@...el.com,
	stable@...r.kernel.org,
	yinghai@...nel.org
Subject: Re: [PATCH] PCI: fix reference leak in pci_alloc_child_bus()

Ilpo Järvinen<ilpo.jarvinen@...ux.intel.com> wrote:
> Ma Ke <make_ruc2021@....com> writes:
> > When device_register(&child->dev) failed, calling put_device() to
> > explicitly release child->dev. Otherwise, it could cause double free
> > problem.
> > 
> > Found by code review.
> > 
> > Cc: stable@...r.kernel.org
> > Fixes: 4f535093cf8f ("PCI: Put pci_dev in device tree as early as possible")
> > Signed-off-by: Ma Ke <make_ruc2021@....com>
> > ---
> >  drivers/pci/probe.c | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> > index 2e81ab0f5a25..d3146c588d7f 100644
> > --- a/drivers/pci/probe.c
> > +++ b/drivers/pci/probe.c
> > @@ -1174,7 +1174,10 @@ static struct pci_bus *pci_alloc_child_bus(struct pci_bus *parent,
> >  add_dev:
> >  	pci_set_bus_msi_domain(child);
> >  	ret = device_register(&child->dev);
> > -	WARN_ON(ret < 0);
> > +	if (ret) {
> > +		WARN_ON(ret < 0);
> 
> The usual way is:
> 
> 	if (WARN_ON(ret < 0))
> 
> > +		put_device(&child->dev);
> > +	}
> >  
> >  	pcibios_add_bus(child);
> 
> But more serious problem here is that should this code even proceed as if 
> nothing happened when an error occurs? pci_register_host_bridge() does 
> proper rollback when device_register() fails but this function doesn't.
> 
> Into the same vein, is using WARN_ON() even correct here? Why should this 
> print a stacktrace if device_register() fails instead of simply printing 
> and error?
Thank you for your guidance and suggestions. I have the same confusion
about the simple handling(WARN_ON()) of errors if device_add() fails. 
I am looking forward to receiving guidance and insights from other 
experts.

--
Regards,

Ma Ke


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ