Skip to content

Commit 0288e5e

Browse files
AviSternjmberg-intel
authored andcommitted
cfg80211: avoid double free of PMSR request
If cfg80211_pmsr_process_abort() moves all the PMSR requests that need to be freed into a local list before aborting and freeing them. As a result, it is possible that cfg80211_pmsr_complete() will run in parallel and free the same PMSR request. Fix it by freeing the request in cfg80211_pmsr_complete() only if it is still in the original pmsr list. Cc: [email protected] Fixes: 9bb7e0f ("cfg80211: add peer measurement with FTM initiator API") Signed-off-by: Avraham Stern <[email protected]> Signed-off-by: Luca Coelho <[email protected]> Link: https://lore.kernel.org/r/iwlwifi.20210618133832.1fbef57e269a.I00294bebdb0680b892f8d1d5c871fd9dbe785a5e@changeid Signed-off-by: Johannes Berg <[email protected]>
1 parent b564247 commit 0288e5e

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

net/wireless/pmsr.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ void cfg80211_pmsr_complete(struct wireless_dev *wdev,
334334
gfp_t gfp)
335335
{
336336
struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
337+
struct cfg80211_pmsr_request *tmp, *prev, *to_free = NULL;
337338
struct sk_buff *msg;
338339
void *hdr;
339340

@@ -364,9 +365,20 @@ void cfg80211_pmsr_complete(struct wireless_dev *wdev,
364365
nlmsg_free(msg);
365366
free_request:
366367
spin_lock_bh(&wdev->pmsr_lock);
367-
list_del(&req->list);
368+
/*
369+
* cfg80211_pmsr_process_abort() may have already moved this request
370+
* to the free list, and will free it later. In this case, don't free
371+
* it here.
372+
*/
373+
list_for_each_entry_safe(tmp, prev, &wdev->pmsr_list, list) {
374+
if (tmp == req) {
375+
list_del(&req->list);
376+
to_free = req;
377+
break;
378+
}
379+
}
368380
spin_unlock_bh(&wdev->pmsr_lock);
369-
kfree(req);
381+
kfree(to_free);
370382
}
371383
EXPORT_SYMBOL_GPL(cfg80211_pmsr_complete);
372384

0 commit comments

Comments
 (0)