Skip to contentSkip to conversation

net: tg3: fix NULL pointer dereference in tg3_io_error_detected and tg3_io_slot_reset

PATCH In review Nithin Nayak Sujir 4 participants 7 messages Aug 13, 2013 – Aug 15, 2013

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

PATCH 1/1 net: tg3: fix NULL pointer dereference in tg3_io_error_detected and tg3_io_slot_reset

From: Daniel Borkmann <[email protected]>

Commit d8af4dfd8 ("net/tg3: Fix kernel crash") introduced a possible NULL pointer dereference in tg3 driver when !netdev || !netif_running(netdev) condition is met and netdev is NULL. Then, the jump to the 'done' label calls dev_close() with a netdevice that is NULL. Therefore, only call dev_close() when we have a netdevice, but one that is not running.

[ Add the same checks in tg3_io_slot_reset() per Gavin Shan - by Nithin Nayak Sujir ]

---
 drivers/net/ethernet/broadcom/tg3.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/net/ethernet/broadcom/tg3.c +8 -5
index ddebc7a..0da2214 100644
@@ -17796,8 +17796,10 @@ static pci_ers_result_t tg3_io_error_detected(struct pci_dev *pdev,
 
 done:
 	if (state == pci_channel_io_perm_failure) {
-		tg3_napi_enable(tp);
-		dev_close(netdev);
+		if (netdev) {
+			tg3_napi_enable(tp);
+			dev_close(netdev);
+		}
 		err = PCI_ERS_RESULT_DISCONNECT;
 	} else {
 		pci_disable_device(pdev);
@@ -17827,7 +17829,8 @@ static pci_ers_result_t tg3_io_slot_reset(struct pci_dev *pdev)
 	rtnl_lock();
 
 	if (pci_enable_device(pdev)) {
-		netdev_err(netdev, "Cannot re-enable PCI device after reset.\n");
+		dev_err(&pdev->dev,
+			"Cannot re-enable PCI device after reset.\n");
 		goto done;
 	}
 
@@ -17835,7 +17838,7 @@ static pci_ers_result_t tg3_io_slot_reset(struct pci_dev *pdev)
 	pci_restore_state(pdev);
 	pci_save_state(pdev);
 
-	if (!netif_running(netdev)) {
+	if (!netdev || !netif_running(netdev)) {
 		rc = PCI_ERS_RESULT_RECOVERED;
 		goto done;
 	}
@@ -17847,7 +17850,7 @@ static pci_ers_result_t tg3_io_slot_reset(struct pci_dev *pdev)
 	rc = PCI_ERS_RESULT_RECOVERED;
 
 done:
-	if (rc != PCI_ERS_RESULT_RECOVERED && netif_running(netdev)) {
+	if (rc != PCI_ERS_RESULT_RECOVERED && netdev && netif_running(netdev)) {
 		tg3_napi_enable(tp);
 		dev_close(netdev);
 	}
Signature · 1 line
1.8.1.4
maintainer
#1 lore raw

From: "Nithin Nayak Sujir" <[email protected]>
Date: Tue, 13 Aug 2013 11:45:13 -0700

Quoted 8 lines

From: Daniel Borkmann <[email protected]>

Commit d8af4dfd8 ("net/tg3: Fix kernel crash") introduced a possible NULL pointer dereference in tg3 driver when !netdev || !netif_running(netdev) condition is met and netdev is NULL. Then, the jump to the 'done' label calls dev_close() with a netdevice that is NULL. Therefore, only call dev_close() when we have a netdevice, but one that is not running.

Quoted 8 lines

[ Add the same checks in tg3_io_slot_reset() per Gavin Shan - by Nithin Nayak Sujir ]

Can I get some reviews from the Broadcom folks?

Thanks.

#2 lore raw
Quoted 21 lines · David Miller

From: "Nithin Nayak Sujir" <[email protected]>
Date: Tue, 13 Aug 2013 11:45:13 -0700

Quoted 8 lines

From: Daniel Borkmann <[email protected]>

Commit d8af4dfd8 ("net/tg3: Fix kernel crash") introduced a possible NULL pointer dereference in tg3 driver when !netdev || !netif_running(netdev) condition is met and netdev is NULL. Then, the jump to the 'done' label calls dev_close() with a netdevice that is NULL. Therefore, only call dev_close() when we have a netdevice, but one that is not running.

Quoted 8 lines

[ Add the same checks in tg3_io_slot_reset() per Gavin Shan - by Nithin Nayak Sujir ]

Quoted 3 lines

Can I get some reviews from the Broadcom folks?

Thanks.

You already have:

#3 lore raw
In reply to David Miller
Quoted 14 lines · David Miller

From: "Nithin Nayak Sujir" <[email protected]>
Date: Tue, 13 Aug 2013 11:45:13 -0700

Quoted 11 lines

From: Daniel Borkmann <[email protected]>

Commit d8af4dfd8 ("net/tg3: Fix kernel crash") introduced a possible NULL pointer dereference in tg3 driver when !netdev || !netif_running(netdev) condition is met and netdev is NULL. Then, the jump to the 'done' label calls dev_close() with a netdevice that is NULL. Therefore, only call dev_close() when we have a netdevice, but one that is not running.

[ Add the same checks in tg3_io_slot_reset() per Gavin Shan - by Nithin Nayak Sujir ]

Quoted 8 lines
Quoted 5 lines

Can I get some reviews from the Broadcom folks?

We worked with Daniel at Red Hat and Gavin at IBM on this patch. Thanks.

maintainer
#4 lore raw

From: "Michael Chan" <[email protected]>
Date: Thu, 15 Aug 2013 08:15:20 -0700

Quoted 21 lines · David Miller
Quoted 20 lines

From: "Nithin Nayak Sujir" <[email protected]>
Date: Tue, 13 Aug 2013 11:45:13 -0700

Quoted 16 lines

From: Daniel Borkmann <[email protected]>

Commit d8af4dfd8 ("net/tg3: Fix kernel crash") introduced a possible NULL pointer dereference in tg3 driver when !netdev || !netif_running(netdev) condition is met and netdev is NULL. Then, the jump to the 'done' label calls dev_close() with a netdevice that is NULL. Therefore, only call dev_close() when we have a netdevice, but one that is not running.

[ Add the same checks in tg3_io_slot_reset() per Gavin Shan - by Nithin Nayak Sujir ]

Quoted 7 lines
Quoted 2 lines

Can I get some reviews from the Broadcom folks?

We worked with Daniel at Red Hat and Gavin at IBM on this patch. Thanks.

Thanks for the info, applied.

#5 lore raw
In reply to David Miller
Quoted 7 lines
Quoted 4 lines

Can I get some reviews from the Broadcom folks?

David,
I made the additional changes to Daniel's patch and Michael Chan reviewed it before I submitted.

Sorry, I forgot to add Michael's Signed-off-by. Do you want me to resend it with his Signed-off-by added?

Thanks,
Nithin.

Quoted 2 lines

Thanks.

maintainer
#6 lore raw

From: "Nithin Nayak Sujir" <[email protected]>
Date: Thu, 15 Aug 2013 10:32:58 -0700

Quoted 2 lines

Sorry, I forgot to add Michael's Signed-off-by. Do you want me to resend it with his Signed-off-by added?

That's not necessary, it gets added automatically by patchwork since he replied and added it.