Blob Blame History Raw
From: Julian Wiedmann <jwi@linux.ibm.com>
Subject: s390/qeth: cancel close_dev work before removing a card
Patch-mainline: v5.0-rc6
Git-commit: c2780c1a3fb724560b1d44f7976e0de17bf153c7
References: LTC#175898, bsc#1127561

Description:   qeth: cancel close_dev work before removing a card 
Symptom:       Undefined behaviour, primarily when a device is notified
               by HW that the connected switch port no longer supports
               VEPA mode.
Problem:       A card's close_dev work is scheduled on a driver-wide
               workqueue. If the card is removed and freed while the work
               is still active, this causes a use-after-free.
Solution:      Make sure that the work is completed before freeing the card.
Reproduction:  - 

Upstream-Description:

              s390/qeth: cancel close_dev work before removing a card

              A card's close_dev work is scheduled on a driver-wide workqueue. If the
              card is removed and freed while the work is still active, this causes a
              use-after-free.
              So make sure that the work is completed before freeing the card.

              Fixes: 0f54761d167f ("qeth: Support VEPA mode")
              Signed-off-by: Julian Wiedmann <jwi@linux.ibm.com>
              Signed-off-by: David S. Miller <davem@davemloft.net>


Signed-off-by: Julian Wiedmann <jwi@linux.ibm.com>
Acked-by: Denis Kirjanov <dkirjanov@suse.com>
---
 drivers/s390/net/qeth_core.h    |    1 +
 drivers/s390/net/qeth_l2_main.c |    2 ++
 drivers/s390/net/qeth_l3_main.c |    1 +
 3 files changed, 4 insertions(+)

--- a/drivers/s390/net/qeth_core.h
+++ b/drivers/s390/net/qeth_core.h
@@ -21,6 +21,7 @@
 #include <linux/hashtable.h>
 #include <linux/ip.h>
 #include <linux/refcount.h>
+#include <linux/workqueue.h>
 
 #include <net/ipv6.h>
 #include <net/if_inet6.h>
--- a/drivers/s390/net/qeth_l2_main.c
+++ b/drivers/s390/net/qeth_l2_main.c
@@ -823,6 +823,8 @@ static void qeth_l2_remove_device(struct
 
 	if (cgdev->state == CCWGROUP_ONLINE)
 		qeth_l2_set_offline(cgdev);
+
+	cancel_work_sync(&card->close_dev_work);
 	if (qeth_netdev_is_registered(card->dev))
 		unregister_netdev(card->dev);
 }
--- a/drivers/s390/net/qeth_l3_main.c
+++ b/drivers/s390/net/qeth_l3_main.c
@@ -2474,6 +2474,7 @@ static void qeth_l3_remove_device(struct
 	if (cgdev->state == CCWGROUP_ONLINE)
 		qeth_l3_set_offline(cgdev);
 
+	cancel_work_sync(&card->close_dev_work);
 	if (qeth_netdev_is_registered(card->dev))
 		unregister_netdev(card->dev);
 	qeth_l3_clear_ip_htable(card, 0);