linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] net: hso: do not call unregister if not registered
@ 2020-10-02 11:43 Greg KH
  2020-10-04  0:00 ` David Miller
  0 siblings, 1 reply; 6+ messages in thread
From: Greg KH @ 2020-10-02 11:43 UTC (permalink / raw)
  To: netdev
  Cc: Tuba Yavuz, David S. Miller, Jakub Kicinski, Oliver Neukum,
	linux-kernel, linux-usb

From: Tuba Yavuz <tuba@ece.ufl.edu>

On an error path inside the hso_create_net_device function of the hso
driver, hso_free_net_device gets called. This causes a use-after-free
and a double-free if register_netdev has not been called yet as
hso_free_net_device calls unregister_netdev regardless. I think the
driver should distinguish these cases and call unregister_netdev only if
register_netdev has been called.

Signed-off-by: Tuba Yavuz <tuba@ece.ufl.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v2: format cleaned up based on feedback from previous review
    Forward to Greg to submit due to email problems on Tuba's side

diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
index 2bb28db89432..e6b56bdf691d 100644
--- a/drivers/net/usb/hso.c
+++ b/drivers/net/usb/hso.c
@@ -2366,7 +2366,8 @@ static void hso_free_net_device(struct hso_device *hso_dev, bool bailout)
 
 	remove_net_device(hso_net->parent);
 
-	if (hso_net->net)
+	if (hso_net->net &&
+	    hso_net->net->reg_state == NETREG_REGISTERED)
 		unregister_netdev(hso_net->net);
 
 	/* start freeing */

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-08-17 15:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-02 11:43 [PATCH v2] net: hso: do not call unregister if not registered Greg KH
2020-10-04  0:00 ` David Miller
2020-10-04  7:14   ` Greg KH
2021-08-16  6:52     ` Salvatore Bonaccorso
2021-08-16  7:02       ` Greg KH
2021-08-17 15:19       ` Yavuz, Tuba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).