Skip to contentSkip to conversation

vdpa: solidrun: Fix UB bug with devres

PATCH RESEND Superseded Philipp Stanner 5 participants 8 messages Oct 16, 2024 – Oct 18, 2024

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 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().

---
 drivers/vdpa/solidrun/snet_main.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/vdpa/solidrun/snet_main.c +10 -4
index 99428a04068d..c8b74980dbd1 100644
@@ -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,13 @@ 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, "snet[%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) {
Signature · 1 line
2.46.1
#1 lore raw
Quoted 11 lines · Philipp Stanner

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().

---

I haven't found the reason for resending. Can you elaborate here?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
Quoted 10 lines · Andy Shevchenko
Quoted 9 lines · Philipp Stanner

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.

Quoted 6 lines
Quoted 4 lines

Fix the bug by allocating the strings on the heap through devm_kasprintf().

---

I haven't found the reason for resending. Can you elaborate here?

Impatience ;p

This is not a v2.

I mean, it's a bug, easy to fix and merge [and it's blocking my other PCI work, *cough*]. Should contributors wait longer than 8 days until resending in your opinion?

P.

#3 lore raw
Quoted 2 lines · Philipp Stanner
Quoted 1 line · Andy Shevchenko

On Wed, Oct 16, 2024 at 09:25:54AM +0200, Philipp Stanner wrote:

...

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

---

I haven't found the reason for resending. Can you elaborate here?

Impatience ;p

This is not a v2.

It doesn't matter, the reviewers and maintainers should get a clue which version is to be used (even if it's a simple resend) and why it has been sent.

Quoted 3 lines

I mean, it's a bug, easy to fix and merge [and it's blocking my other PCI work, *cough*]. Should contributors wait longer than 8 days until resending in your opinion?

Usually we may ping for that. And yeah, depending on the maintainers it takes a while to get it to the point. In some (quite rare I believe) cases we may escalate up to Linus about this. I probably has only one case like that in my full period of working on the Linux kernel project (several years).

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#4 lore raw
In reply to Philipp Stanner
Quoted 18 lines · Philipp Stanner
Quoted 10 lines · Andy Shevchenko
Quoted 9 lines · Philipp Stanner

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.

Quoted 6 lines
Quoted 4 lines

Fix the bug by allocating the strings on the heap through devm_kasprintf().

---

I haven't found the reason for resending. Can you elaborate here?

Quoted 7 lines

Impatience ;p

This is not a v2.

I mean, it's a bug, easy to fix and merge [and it's blocking my other PCI work, *cough*]. Should contributors wait longer than 8 days until resending in your opinion?

2 weeks is normally the expected response time, but each subsystem might have other time limites, the documentation should show those that do.

While you wait, take the time to review other pending patches for that maintainer, that will ensure that your patches move to the top as they will be the only ones remaining.

thanks,

greg k-h

#5 lore raw
Quoted 32 lines · Greg KH
Quoted 23 lines · Philipp Stanner
Quoted 13 lines · Andy Shevchenko
Quoted 12 lines · Philipp Stanner

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.

Quoted 6 lines
Quoted 4 lines

Fix the bug by allocating the strings on the heap through devm_kasprintf().

---

I haven't found the reason for resending. Can you elaborate here?

Impatience ;p

Quoted 7 lines

This is not a v2.

I mean, it's a bug, easy to fix and merge [and it's blocking my other
PCI work, *cough*]. Should contributors wait longer than 8 days until
resending in your opinion?

Quoted 3 lines

2 weeks is normally the expected response time, but each subsystem might
have other time limites, the documentation should show those that do.

Where do we document that?

Regarding resend intervals, the official guide line is contradictory:
"You should receive comments within a few weeks (typically 2-3)" <-> "Wait for a minimum of one week before resubmitting or pinging reviewers" <--> "It’s also ok to resend the patch or the patch series after a couple of weeks"

https://www.kernel.org/doc/html/latest/process/submitting-patches.html#don-t-get-discouraged-or-impatient

We could make the docu more consistent and specify 2 weeks as the minimum time.

P.

Quoted 11 lines

While you wait, take the time to review other pending patches for that
maintainer, that will ensure that your patches move to the top as they
will be the only ones remaining.

thanks,

greg k-h

maintainer
#6 lore raw
Quoted 33 lines · Philipp Stanner
Quoted 32 lines · Greg KH
Quoted 30 lines · Philipp Stanner
Quoted 13 lines · Andy Shevchenko
Quoted 12 lines · Philipp Stanner

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.

Quoted 6 lines
Quoted 4 lines

Fix the bug by allocating the strings on the heap through devm_kasprintf().

---

I haven't found the reason for resending. Can you elaborate here?

Impatience ;p

This is not a v2.

I mean, it's a bug, easy to fix and merge [and it's blocking my other
PCI work, *cough*]. Should contributors wait longer than 8 days until
resending in your opinion?

Quoted 5 lines
Quoted 3 lines

2 weeks is normally the expected response time, but each subsystem might
have other time limites, the documentation should show those that do.

Where do we document that?

Documentation/process/maintainer-*

Quoted 11 lines

Regarding resend intervals, the official guide line is contradictory:
"You should receive comments within a few weeks (typically 2-3)" <-> "Wait for a minimum of one week before resubmitting or pinging reviewers" <--> "It’s also ok to resend the patch or the patch series after a couple of weeks"

https://www.kernel.org/doc/html/latest/process/submitting-patches.html#don-t-get-discouraged-or-impatient

We could make the docu more consistent and specify 2 weeks as the minimum time.

Trying to tell other people what they are required to do, when you don't pay them, is going to be a bit difficult :)

Just leave it as-is, and again, take the time to do reviews for the maintainers you are trying to get patches accepted for. That's the simplest way to make forward progress faster.

good luck!

greg k-h

Reviewed-by on v1 1/1
#7 lore raw
In reply to Philipp Stanner
Quoted 16 lines · Philipp Stanner

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().

Quoted 3 lines

---
drivers/vdpa/solidrun/snet_main.c | 14 ++++++++++----

1 file changed, 10 insertions(+), 4 deletions(-)

LGTM!

Quoted 46 lines
drivers/vdpa/solidrun/snet_main.c +10 -4
index 99428a04068d..c8b74980dbd1 100644
@@ -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,13 @@ 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, "snet[%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) {
Signature · 1 line
2.46.1