Skip to contentSkip to conversation

b43legacy: Add checking for null for ssb_get_devtypedata(dev)

PATCH NAK Nikita Zhandarovich 4 participants 5 messages Apr 18, 2023 – May 5, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 b43legacy: Add checking for null for ssb_get_devtypedata(dev)

Since second call of ssb_get_devtypedata() may fail as well as the first one, the NULL return value in 'wl' will be later dereferenced in calls to b43legacy_one_core_attach() and schedule_work().

Instead of merely warning about this failure with B43legacy_WARN_ON(), properly return with error to avoid any further NULL pointer dereferences.

Found by Linux Verification Center (linuxtesting.org) with static analysis tool SVACE.

Fixes 75388acd0cd8 ("[B43LEGACY]: add mac80211-based driver for legacy BCM43xx devices")

---
v2: fix issues with overlooked null-ptr-dereferences pointed out by Simon Horman <[email protected]>

 drivers/net/wireless/broadcom/b43legacy/main.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/wireless/broadcom/b43legacy/main.c +5 -1
index 760136638a95..5a706dd0b1a4 100644
@@ -3857,7 +3857,11 @@ static int b43legacy_probe(struct ssb_device *dev,
 		if (err)
 			goto out;
 		wl = ssb_get_devtypedata(dev);
-		B43legacy_WARN_ON(!wl);
+		if (!wl) {
+			B43legacy_WARN_ON(!wl);
+			err = -ENODEV;
+			goto out;
+		}
 	}
 	err = b43legacy_one_core_attach(dev, wl);
 	if (err)
Signature · 1 line
2.25.1
#1 lore raw
Quoted 3 lines · On Tue, 18 Apr 2023 07:29:18 -0700 Nikita Zhandarovich…

Since second call of ssb_get_devtypedata() may fail as well as the first one, the NULL return value in 'wl' will be later dereferenced in calls to b43legacy_one_core_attach() and schedule_work().

No, the second call can't fail, because b43legacy_wireless_init() will always initialize it before returning 0.

drivers/net/wireless/broadcom/b43legacy/main.c static int b43legacy_probe(struct ssb_device *dev, · line 3863

Quoted 10 lines

a/drivers/net/wireless/broadcom/b43legacy/main.c +++ b/drivers/net/wireless/broadcom/b43legacy/main.c @@ -3857,7 +3857,11 @@ static int b43legacy_probe(struct ssb_device *dev, if (err)

drivers/net/wireless/broadcom/b43legacy/main.c +4 -1
 			goto out;
 		wl = ssb_get_devtypedata(dev);
-		B43legacy_WARN_ON(!wl);
+		if (!wl) {
+			B43legacy_WARN_ON(!wl);
+			err = -ENODEV;
+			goto out;

And the 'goto out' would be the wrong error recovery path, too.

drivers/net/wireless/broadcom/b43legacy/main.c static int b43legacy_probe(struct ssb_device *dev, · line 3867

Quoted 4 lines
drivers/net/wireless/broadcom/b43legacy/main.c +1 -0
+		}
 	}
 	err = b43legacy_one_core_attach(dev, wl);
 	if (err)

Nack.
Please drop this patch. The code is correct as-is.

Signature · 2 lines
Michael Büsch
https://bues.ch/

_______________________________________________
b43-dev mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/b43-dev

Reviewed-by on v2 1/1
#2 lore raw
In reply to Nikita Zhandarovich
Quoted 29 lines · Nikita Zhandarovich

Since second call of ssb_get_devtypedata() may fail as well as the first one, the NULL return value in 'wl' will be later dereferenced in calls to b43legacy_one_core_attach() and schedule_work().

Instead of merely warning about this failure with B43legacy_WARN_ON(), properly return with error to avoid any further NULL pointer dereferences.

Found by Linux Verification Center (linuxtesting.org) with static analysis tool SVACE.

Fixes 75388acd0cd8 ("[B43LEGACY]: add mac80211-based driver for legacy BCM43xx devices")

---
v2: fix issues with overlooked null-ptr-dereferences pointed out by Simon Horman <[email protected]>

  drivers/net/wireless/broadcom/b43legacy/main.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/wireless/broadcom/b43legacy/main.c +0 -0
index 760136638a95..5a706dd0b1a4 100644
@@ -3857,7 +3857,11 @@ static int b43legacy_probe(struct ssb_device *dev,
  		if (err)
  			goto out;

drivers/net/wireless/broadcom/b43legacy/main.c static int b43legacy_probe(struct ssb_device *dev, · line 3867

Quoted 10 lines
drivers/net/wireless/broadcom/b43legacy/main.c +5 -1
  		wl = ssb_get_devtypedata(dev);
-		B43legacy_WARN_ON(!wl);
+		if (!wl) {
+			B43legacy_WARN_ON(!wl);
+			err = -ENODEV;
+			goto out;
+		}
  	}
  	err = b43legacy_one_core_attach(dev, wl);
  	if (err)

I do not recall seeing v1. One additional nitpick: The latest convention would have the subject as "wifi: b43legacy:...". Kalle may be able to fix this on merging, but it not, a v3 might be required. Otherwise, the patch is good.

Thanks,

Larry

_______________________________________________
b43-dev mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/b43-dev

#3 lore raw
Quoted 17 lines · On Fri, 21 Apr 2023 17:14:18 -0500 Larry Finger <[email protected]>…

drivers/net/wireless/broadcom/b43legacy/main.c static int b43legacy_probe(struct ssb_device *dev, · line 3867

Quoted 11 lines

(err) goto out;
wl = ssb_get_devtypedata(dev);

drivers/net/wireless/broadcom/b43legacy/main.c +5 -1
-		B43legacy_WARN_ON(!wl);
+		if (!wl) {
+			B43legacy_WARN_ON(!wl);
+			err = -ENODEV;
+			goto out;
+		}
  	}
  	err = b43legacy_one_core_attach(dev, wl);
  	if (err)  

I do not recall seeing v1. One additional nitpick: The latest convention would have the subject as "wifi: b43legacy:...". Kalle may be able to fix this on merging, but it not, a v3 might be required. Otherwise, the patch is good.

Quoted 1 line

No, it's not good. It's wrong. I already replied to it. wl can never be NULL here and the goto-out path is wrong (if there was a chance for it to trigger).

Please drop this patch, Kalle.

Signature · 2 lines
Michael Büsch
https://bues.ch/
#4 lore raw
In reply to Nikita Zhandarovich
Quoted 8 lines · Nikita Zhandarovich

Since second call of ssb_get_devtypedata() may fail as well as the first one, the NULL return value in 'wl' will be later dereferenced in calls to b43legacy_one_core_attach() and schedule_work().

Instead of merely warning about this failure with B43legacy_WARN_ON(), properly return with error to avoid any further NULL pointer dereferences.

Quoted 7 lines

Found by Linux Verification Center (linuxtesting.org) with static analysis tool SVACE.

Fixes 75388acd0cd8 ("[B43LEGACY]: add mac80211-based driver for legacy BCM43xx devices")

Dropped per Michael's request.

Patch set to Rejected.

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches