Skip to contentSkip to conversation

kni: unregister an unregisterd net_device could cause a kernel crash

PATCH In review zhouyangchao 2 participants 2 messages Sep 8, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kni: unregister an unregisterd net_device could cause a kernel crash

---
 lib/librte_eal/linuxapp/kni/kni_misc.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
lib/librte_eal/linuxapp/kni/kni_misc.c +3 -0
index 67e9b7d..17b6d7a 100644
@@ -361,6 +361,9 @@ kni_dev_remove(struct kni_dev *dev)
 		igb_kni_remove(dev->pci_dev);
 
 	if (dev->net_dev) {
+		if (dev->net_dev->state == NETREG_REGISTERED) {
+			unregister_netdev(dev->net_dev);
+		}
 		unregister_netdev(dev->net_dev);
 		free_netdev(dev->net_dev);
 	}
Signature · 1 line
1.7.1
#1 lore raw
Quoted 10 lines · On Fri, 9 Sep 2016 10:42:16 +0800 zhouyangchao <[email protected]> wrote:
---
 lib/librte_eal/linuxapp/kni/kni_misc.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
lib/librte_eal/linuxapp/kni/kni_misc.c +0 -0
index 67e9b7d..17b6d7a 100644

lib/librte_eal/linuxapp/kni/kni_misc.c kni_dev_remove(struct kni_dev *dev) · line 369

Quoted 9 lines
lib/librte_eal/linuxapp/kni/kni_misc.c +3 -0
@@ -361,6 +361,9 @@ kni_dev_remove(struct kni_dev *dev)
 		igb_kni_remove(dev->pci_dev);
 
 	if (dev->net_dev) {
+		if (dev->net_dev->state == NETREG_REGISTERED) {
+			unregister_netdev(dev->net_dev);
+		}
 		unregister_netdev(dev->net_dev);
 		free_netdev(dev->net_dev);
 	}

The real problem is kni_dev_remove should not be called when register_netdevice fails. Why not just fix that unwind path.