Skip to contentSkip to conversation

net/ncsi: Cancel the ncsi work before freeing the associated structure

PATCH Superseded Eddie James 2 participants 2 messages Sep 17, 2024 – Sep 24, 2024

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/ncsi: Cancel the ncsi work before freeing the associated structure

The work function can run after the ncsi device is freed, resulting in use-after-free bugs or kernel panic.

Fixes 2d283bdd079c ("net/ncsi: Resource management")
---
 net/ncsi/ncsi-manage.c | 2 ++
 1 file changed, 2 insertions(+)
net/ncsi/ncsi-manage.c +2 -0
index 5ecf611c8820..3eda24eac668 100644
@@ -1954,6 +1954,8 @@ void ncsi_unregister_dev(struct ncsi_dev *nd)
 	list_del_rcu(&ndp->node);
 	spin_unlock_irqrestore(&ncsi_dev_lock, flags);
 
+	cancel_work_sync(&ndp->work);
+
 	kfree(ndp);
 }
 EXPORT_SYMBOL_GPL(ncsi_unregister_dev);
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 14 lines · Eddie James

The work function can run after the ncsi device is freed, resulting in use-after-free bugs or kernel panic.

Fixes 2d283bdd079c ("net/ncsi: Resource management")
---
  net/ncsi/ncsi-manage.c | 2 ++
  1 file changed, 2 insertions(+)
net/ncsi/ncsi-manage.c +0 -0
index 5ecf611c8820..3eda24eac668 100644

net/ncsi/ncsi-manage.c void ncsi_unregister_dev(struct ncsi_dev *nd) · line 1957

Quoted 4 lines
net/ncsi/ncsi-manage.c +1 -0
@@ -1954,6 +1954,8 @@ void ncsi_unregister_dev(struct ncsi_dev *nd)
  	list_del_rcu(&ndp->node);
  	spin_unlock_irqrestore(&ncsi_dev_lock, flags);
 
+	cancel_work_sync(&ndp->work);

Possibly disable_work_sync(), just to be on the safe side?

Thanks,

Paolo