wifi: iwlwifi: fix RCU lifetime on setup failures
Subsystems (2)
cover wifi: iwlwifi: fix RCU lifetime on setup failures
Two key-add error paths remove packet-number state from RCU-protected pointers and then free it immediately. Concurrent RX readers can still hold the removed objects.
The MLD link-add error path has a related problem. It can free a link without first removing a restart-time published pointer, or free it immediately after unpublishing it on a later firmware failure.
Use the RCU-delayed freeing already used by the corresponding normal removal paths, and make the link mapping cleanup common to every failed link add. Keep the MVM and MLD fixes separate because their origins, objects and maintained-line exposure differ.
Zhao Li (3):
wifi: iwlwifi: mvm: defer freeing PTK PN state on key failure
wifi: iwlwifi: mld: defer freeing PTK PN state on key failure
wifi: iwlwifi: mld: unpublish links before freeing on add failure
drivers/net/wireless/intel/iwlwifi/mld/link.c | 4 ++-- drivers/net/wireless/intel/iwlwifi/mld/mac80211.c | 2 +- drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
base-commit: 50d3d79dc0743b616afb00d01a626c76758721f7
Signature · 1 line
2.55.0
PATCH 1/3 wifi: iwlwifi: mvm: defer freeing PTK PN state on key failure
The PTK packet-number state is published to RCU readers before the key is installed in firmware.
If firmware rejects the key, the error path clears the pointer and immediately frees the state while an RX reader may still hold it.
Defer the free until after an RCU grace period, matching the normal key removal path.
--- drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c +1 -1
@@ -4385,7 +4385,7 @@ static int __iwl_mvm_mac_set_key(struct ieee80211_hw *hw, key->hw_key_idx =STA_KEY_IDX_INVALID ;if (ptk_pn) {RCU_INIT_POINTER (mvmsta->ptk_pn[keyidx],NULL ); -kfree (ptk_pn); +kfree_rcu (ptk_pn, rcu_head); }/* * can't add key for RX, but we don't need it
Signature · 1 line
2.55.0
PATCH 2/3 wifi: iwlwifi: mld: defer freeing PTK PN state on key failure
In reply to Zhao LiThe PTK packet-number state is published to RCU readers before the key is installed in firmware.
If firmware rejects the key, the error path clears the pointer and immediately frees the state while an RX reader may still hold it.
Defer the free until after an RCU grace period, matching the normal key removal path.
--- drivers/net/wireless/intel/iwlwifi/mld/mac80211.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/intel/iwlwifi/mld/mac80211.c +1 -1
@@ -2265,7 +2265,7 @@ static int iwl_mld_set_key_add(struct iwl_mld *mld,if (ret) {if (ptk_pn) {RCU_INIT_POINTER (mld_sta->ptk_pn[keyidx],NULL ); -kfree (ptk_pn); +kfree_rcu (ptk_pn, rcu_head); }return -EOPNOTSUPP ;
Signature · 1 line
2.55.0
PATCH 3/3 wifi: iwlwifi: mld: unpublish links before freeing on add failure
In reply to Zhao LiDuring firmware restart, iwl_mld_add_link() can reuse a link that is already published in mld_vif->link[]. If link initialization fails, the common error path frees the link without clearing that pointer.
A later firmware-add failure does clear the pointer, but then immediately frees the link while an RCU reader may still hold it.
Clear mld_vif->link[] in the common error path and defer freeing dynamic links until after an RCU grace period, matching normal link removal.
iwl_mld_link_from_mac80211() reads that same slot under the wiphy mutex, so a NULL link means the slot is already NULL; the common clear cannot discard another link.
--- drivers/net/wireless/intel/iwlwifi/mld/link.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/intel/iwlwifi/mld/link.c +2 -2
@@ -541,15 +541,15 @@ int iwl_mld_add_link(struct iwl_mld *mld, ret =iwl_mld_add_link_to_fw (mld, bss_conf);if (ret) {RCU_INIT_POINTER (mld->fw_id_to_bss_conf[link->fw_id],NULL ); -RCU_INIT_POINTER (mld_vif->link[bss_conf->link_id],NULL ); goto free; }return ret; free: +RCU_INIT_POINTER (mld_vif->link[bss_conf->link_id],NULL );if (!is_deflink) -kfree (link); +kfree_rcu (link, rcu_head);return ret; }
Signature · 1 line
2.55.0