From: Ben Greear I saw an instance where use-after-free was found when attempting to delete sta's debugfs. Add check to netdev debugfs free logic to ensure any sta's that still exist have nulled out debugfs entries since netdev is going to do a recursive debugfs delete. Signed-off-by: Ben Greear --- net/mac80211/debugfs_netdev.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/net/mac80211/debugfs_netdev.c b/net/mac80211/debugfs_netdev.c index 000859b8c005..2e4bc34e6c5c 100644 --- a/net/mac80211/debugfs_netdev.c +++ b/net/mac80211/debugfs_netdev.c @@ -1063,6 +1063,8 @@ ieee80211_debugfs_clear_link_ptr(struct ieee80211_sub_if_data *sdata, void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata) { struct ieee80211_link_data *link; + struct rhashtable_iter hti; + struct sta_info *sta; struct dentry *dir; int i; @@ -1083,6 +1085,28 @@ void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata) link->debugfs_dir = NULL; } + + /* And, same for all stations. See ieee80211_sta_debugfs_add where + * they are added to the sdata->debugfs.subdir_stations directory + */ + rhashtable_walk_enter(&sdata->local->sta_hash.ht, &hti); + rhashtable_walk_start(&hti); + + while ((sta = rhashtable_walk_next(&hti))) { + if (IS_ERR(sta)) { + if (PTR_ERR(sta) != -EAGAIN) + break; + continue; + } + if (sta->sdata != sdata) + continue; + + sta->debugfs_dir = NULL; + } + + rhashtable_walk_stop(&hti); + rhashtable_walk_exit(&hti); + rcu_read_unlock(); dir = sdata->vif.debugfs_dir; -- 2.42.0