* [PATCH v3 7/9] vdpa: solidrun: Fix UB bug with devres
[not found] <20240822134744.44919-1-pstanner@redhat.com>
@ 2024-08-22 13:47 ` Philipp Stanner
2024-08-22 14:34 ` Christophe JAILLET
2024-08-22 14:47 ` Andy Shevchenko
0 siblings, 2 replies; 4+ messages in thread
From: Philipp Stanner @ 2024-08-22 13:47 UTC (permalink / raw)
To: Jonathan Corbet, Jens Axboe, Wu Hao, Tom Rix, Moritz Fischer,
Xu Yilun, Andy Shevchenko, Linus Walleij, Bartosz Golaszewski,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Alexandre Torgue, Jose Abreu, Maxime Coquelin, Bjorn Helgaas,
Alvaro Karsz, Michael S. Tsirkin, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Richard Cochran, Mark Brown, David Lechner,
Uwe Kleine-König, Philipp Stanner, Damien Le Moal,
Hannes Reinecke, Chaitanya Kulkarni
Cc: linux-doc, linux-kernel, linux-block, linux-fpga, linux-gpio,
netdev, linux-stm32, linux-arm-kernel, linux-pci, virtualization,
stable, Christophe JAILLET
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@vger.kernel.org # v6.3
Fixes: 51a8f9d7f587 ("virtio: vdpa: new SolidNET DPU driver.")
Reported-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Closes: https://lore.kernel.org/all/74e9109a-ac59-49e2-9b1d-d825c9c9f891@wanadoo.fr/
Suggested-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Philipp Stanner <pstanner@redhat.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));
+ if (!name)
+ return -ENOMEM;
/* Request and map BAR */
ret = pcim_iomap_regions(pdev, BIT(snet->psnet->cfg.vf_bar), name);
if (ret) {
--
2.46.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3 7/9] vdpa: solidrun: Fix UB bug with devres
2024-08-22 13:47 ` [PATCH v3 7/9] vdpa: solidrun: Fix UB bug with devres Philipp Stanner
@ 2024-08-22 14:34 ` Christophe JAILLET
2024-08-26 6:55 ` Philipp Stanner
2024-08-22 14:47 ` Andy Shevchenko
1 sibling, 1 reply; 4+ messages in thread
From: Christophe JAILLET @ 2024-08-22 14:34 UTC (permalink / raw)
To: Philipp Stanner
Cc: alexandre.torgue, alvaro.karsz, andy, axboe, bhelgaas, brgl,
broonie, christophe.jaillet, corbet, davem, dlechner, dlemoal,
edumazet, eperezma, hao.wu, hare, jasowang, joabreu, kch, kuba,
linus.walleij, linux-arm-kernel, linux-block, linux-doc,
linux-fpga, linux-gpio, linux-kernel, linux-pci, linux-stm32,
mcoquelin.stm32, mdf, mst, netdev, pabeni, richardcochran, stable,
trix, u.kleine-koenig, virtualization, xuanzhuo, yilun.xu
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@vger.kernel.org # v6.3
> Fixes: 51a8f9d7f587 ("virtio: vdpa: new SolidNET DPU driver.")
> Reported-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> Closes: https://lore.kernel.org/all/74e9109a-ac59-49e2-9b1d-d825c9c9f891@wanadoo.fr/
> Suggested-by: Andy Shevchenko <andy@kernel.org>
> Signed-off-by: Philipp Stanner <pstanner@redhat.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/
> + if (!name)
> + return -ENOMEM;
> /* Request and map BAR */
> ret = pcim_iomap_regions(pdev, BIT(snet->psnet->cfg.vf_bar), name);
> if (ret) {
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3 7/9] vdpa: solidrun: Fix UB bug with devres
2024-08-22 13:47 ` [PATCH v3 7/9] vdpa: solidrun: Fix UB bug with devres Philipp Stanner
2024-08-22 14:34 ` Christophe JAILLET
@ 2024-08-22 14:47 ` Andy Shevchenko
1 sibling, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2024-08-22 14:47 UTC (permalink / raw)
To: Philipp Stanner
Cc: Jonathan Corbet, Jens Axboe, Wu Hao, Tom Rix, Moritz Fischer,
Xu Yilun, Linus Walleij, Bartosz Golaszewski, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Alexandre Torgue,
Jose Abreu, Maxime Coquelin, Bjorn Helgaas, Alvaro Karsz,
Michael S. Tsirkin, Jason Wang, Xuan Zhuo, Eugenio Pérez,
Richard Cochran, Mark Brown, David Lechner, Uwe Kleine-König,
Damien Le Moal, Hannes Reinecke, Chaitanya Kulkarni, linux-doc,
linux-kernel, linux-block, linux-fpga, linux-gpio, netdev,
linux-stm32, linux-arm-kernel, linux-pci, virtualization, stable,
Christophe JAILLET
On Thu, Aug 22, 2024 at 03:47:39PM +0200, Philipp Stanner wrote:
> 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().
...
> - 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);
...
> - snprintf(name, sizeof(name), "snet[%s]-bar", pci_name(pdev));
> + name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "psnet[%s]-bars", pci_name(pdev));
> + if (!name)
> + return -ENOMEM;
+ Blank line as in the above snippet?
> /* Request and map BAR */
> ret = pcim_iomap_regions(pdev, BIT(snet->psnet->cfg.vf_bar), name);
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3 7/9] vdpa: solidrun: Fix UB bug with devres
2024-08-22 14:34 ` Christophe JAILLET
@ 2024-08-26 6:55 ` Philipp Stanner
0 siblings, 0 replies; 4+ messages in thread
From: Philipp Stanner @ 2024-08-26 6:55 UTC (permalink / raw)
To: Christophe JAILLET
Cc: alexandre.torgue, alvaro.karsz, andy, axboe, bhelgaas, brgl,
broonie, corbet, davem, dlechner, dlemoal, edumazet, eperezma,
hao.wu, hare, jasowang, joabreu, kch, kuba, linus.walleij,
linux-arm-kernel, linux-block, linux-doc, linux-fpga, linux-gpio,
linux-kernel, linux-pci, linux-stm32, mcoquelin.stm32, mdf, mst,
netdev, pabeni, richardcochran, stable, trix, u.kleine-koenig,
virtualization, xuanzhuo, yilun.xu
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@vger.kernel.org # v6.3
> > Fixes: 51a8f9d7f587 ("virtio: vdpa: new SolidNET DPU driver.")
> > Reported-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> > Closes:
> > https://lore.kernel.org/all/74e9109a-ac59-49e2-9b1d-d825c9c9f891@wanadoo.fr/
> > Suggested-by: Andy Shevchenko <andy@kernel.org>
> > Signed-off-by: Philipp Stanner <pstanner@redhat.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) {
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-08-26 6:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20240822134744.44919-1-pstanner@redhat.com>
2024-08-22 13:47 ` [PATCH v3 7/9] vdpa: solidrun: Fix UB bug with devres Philipp Stanner
2024-08-22 14:34 ` Christophe JAILLET
2024-08-26 6:55 ` Philipp Stanner
2024-08-22 14:47 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox