Skip to content

Commit 0b364cf

Browse files
Philipp Stannermstsirkin
authored andcommitted
vdpa: solidrun: Fix UB bug with devres
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: [email protected] # v6.3 Fixes: 51a8f9d ("virtio: vdpa: new SolidNET DPU driver.") Reported-by: Christophe JAILLET <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Suggested-by: Andy Shevchenko <[email protected]> Signed-off-by: Philipp Stanner <[email protected]> Reviewed-by: Stefano Garzarella <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent 6ca5753 commit 0b364cf

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

drivers/vdpa/solidrun/snet_main.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ static const struct vdpa_config_ops snet_config_ops = {
555555

556556
static int psnet_open_pf_bar(struct pci_dev *pdev, struct psnet *psnet)
557557
{
558-
char name[50];
558+
char *name;
559559
int ret, i, mask = 0;
560560
/* We don't know which BAR will be used to communicate..
561561
* 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)
573573
return -ENODEV;
574574
}
575575

576-
snprintf(name, sizeof(name), "psnet[%s]-bars", pci_name(pdev));
576+
name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "psnet[%s]-bars", pci_name(pdev));
577+
if (!name)
578+
return -ENOMEM;
579+
577580
ret = pcim_iomap_regions(pdev, mask, name);
578581
if (ret) {
579582
SNET_ERR(pdev, "Failed to request and map PCI BARs\n");
@@ -590,10 +593,13 @@ static int psnet_open_pf_bar(struct pci_dev *pdev, struct psnet *psnet)
590593

591594
static int snet_open_vf_bar(struct pci_dev *pdev, struct snet *snet)
592595
{
593-
char name[50];
596+
char *name;
594597
int ret;
595598

596-
snprintf(name, sizeof(name), "snet[%s]-bar", pci_name(pdev));
599+
name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "snet[%s]-bars", pci_name(pdev));
600+
if (!name)
601+
return -ENOMEM;
602+
597603
/* Request and map BAR */
598604
ret = pcim_iomap_regions(pdev, BIT(snet->psnet->cfg.vf_bar), name);
599605
if (ret) {

0 commit comments

Comments
 (0)