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] [thread-next>] [day] [month] [year] [list]
Message-ID: <23f1b79be57f1a4d6ce0806fa149d687c2c6d275.camel@redhat.com>
Date: Mon, 26 Aug 2024 08:55:22 +0200
From: Philipp Stanner <pstanner@...hat.com>
To: Christophe JAILLET <christophe.jaillet@...adoo.fr>
Cc: alexandre.torgue@...s.st.com, alvaro.karsz@...id-run.com,
 andy@...nel.org,  axboe@...nel.dk, bhelgaas@...gle.com, brgl@...ev.pl,
 broonie@...nel.org,  corbet@....net, davem@...emloft.net,
 dlechner@...libre.com, dlemoal@...nel.org,  edumazet@...gle.com,
 eperezma@...hat.com, hao.wu@...el.com, hare@...e.de,  jasowang@...hat.com,
 joabreu@...opsys.com, kch@...dia.com, kuba@...nel.org, 
 linus.walleij@...aro.org, linux-arm-kernel@...ts.infradead.org, 
 linux-block@...r.kernel.org, linux-doc@...r.kernel.org, 
 linux-fpga@...r.kernel.org, linux-gpio@...r.kernel.org, 
 linux-kernel@...r.kernel.org, linux-pci@...r.kernel.org, 
 linux-stm32@...md-mailman.stormreply.com, mcoquelin.stm32@...il.com, 
 mdf@...nel.org, mst@...hat.com, netdev@...r.kernel.org, pabeni@...hat.com, 
 richardcochran@...il.com, stable@...r.kernel.org, trix@...hat.com, 
 u.kleine-koenig@...gutronix.de, virtualization@...ts.linux.dev, 
 xuanzhuo@...ux.alibaba.com, yilun.xu@...el.com
Subject: Re: [PATCH v3 7/9] vdpa: solidrun: Fix UB bug with devres

On Thu, 2024-08-22 at 16:34 +0200, Christophe JAILLET wrote:
> Le 22/08/2024 à 15:47, Philipp Stanner a écrit :
> > In psnet_open_pf_bar() and snet_open_vf_bar() a string later passed
> > to
> > pcim_iomap_regions() is placed on the stack. Neither
> > pcim_iomap_regions() nor the functions it calls copy that string.
> > 
> > Should the string later ever be used, this, consequently, causes
> > undefined behavior since the stack frame will by then have
> > disappeared.
> > 
> > Fix the bug by allocating the strings on the heap through
> > devm_kasprintf().
> > 
> > Cc: stable@...r.kernel.org	# v6.3
> > Fixes: 51a8f9d7f587 ("virtio: vdpa: new SolidNET DPU driver.")
> > Reported-by: Christophe JAILLET <christophe.jaillet@...adoo.fr>
> > Closes:
> > https://lore.kernel.org/all/74e9109a-ac59-49e2-9b1d-d825c9c9f891@wanadoo.fr/
> > Suggested-by: Andy Shevchenko <andy@...nel.org>
> > Signed-off-by: Philipp Stanner <pstanner@...hat.com>
> > ---
> >   drivers/vdpa/solidrun/snet_main.c | 13 +++++++++----
> >   1 file changed, 9 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/vdpa/solidrun/snet_main.c
> > b/drivers/vdpa/solidrun/snet_main.c
> > index 99428a04068d..67235f6190ef 100644
> > --- a/drivers/vdpa/solidrun/snet_main.c
> > +++ b/drivers/vdpa/solidrun/snet_main.c
> > @@ -555,7 +555,7 @@ static const struct vdpa_config_ops
> > snet_config_ops = {
> >   
> >   static int psnet_open_pf_bar(struct pci_dev *pdev, struct psnet
> > *psnet)
> >   {
> > -	char name[50];
> > +	char *name;
> >   	int ret, i, mask = 0;
> >   	/* We don't know which BAR will be used to communicate..
> >   	 * We will map every bar with len > 0.
> > @@ -573,7 +573,10 @@ static int psnet_open_pf_bar(struct pci_dev
> > *pdev, struct psnet *psnet)
> >   		return -ENODEV;
> >   	}
> >   
> > -	snprintf(name, sizeof(name), "psnet[%s]-bars",
> > pci_name(pdev));
> > +	name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "psnet[%s]-
> > bars", pci_name(pdev));
> > +	if (!name)
> > +		return -ENOMEM;
> > +
> >   	ret = pcim_iomap_regions(pdev, mask, name);
> >   	if (ret) {
> >   		SNET_ERR(pdev, "Failed to request and map PCI
> > BARs\n");
> > @@ -590,10 +593,12 @@ static int psnet_open_pf_bar(struct pci_dev
> > *pdev, struct psnet *psnet)
> >   
> >   static int snet_open_vf_bar(struct pci_dev *pdev, struct snet
> > *snet)
> >   {
> > -	char name[50];
> > +	char *name;
> >   	int ret;
> >   
> > -	snprintf(name, sizeof(name), "snet[%s]-bar",
> > pci_name(pdev));
> > +	name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "psnet[%s]-
> > bars", pci_name(pdev));
> 
> s/psnet/snet/

sharp eyes ;)

Thx,
P.

> 
> > +	if (!name)
> > +		return -ENOMEM;
> >   	/* Request and map BAR */
> >   	ret = pcim_iomap_regions(pdev, BIT(snet->psnet-
> > >cfg.vf_bar), name);
> >   	if (ret) {
> 


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ