wifi: iwlwifi: mld: fix net-detect wakeup report after kzalloc_flex()
Subsystems (2)
PATCH 1/1 wifi: iwlwifi: mld: fix net-detect wakeup report after kzalloc_flex()
Since commit 69050f8d6d07 ("treewide: Replace kmalloc with kmalloc_obj for non-scalar types"), the net-detect wakeup info and its matches are allocated with kzalloc_flex(). Both flexible arrays are annotated with __counted_by(), so on compilers that support __builtin_counted_by_ref() (clang >= 19, gcc >= 15) kzalloc_flex() also sets the counters, n_matches and n_channels, to the allocated sizes.
iwl_mld_set_netdetect_info() still uses those counters as the next free index, so every match and channel is written past the end of its allocation, matches[0..n-1] are left NULL, and the counters end up doubled. cfg80211_net_detect_results() then dereferences matches[0] on every net-detect wakeup that reports a match:
Oops: general protection fault, kernel NULL pointer dereference 0x20 RIP: 0010:cfg80211_report_wowlan_wakeup+0x46a/0x680 [cfg80211] Call Trace: iwl_mld_wowlan_resume+0x9d9/0xe40 [iwlmld] iwl_mld_resume+0x1d/0x50 [iwlmld] Workqueue: async async_run_entry_fn
(0x20 is the offset of ssid.ssid_len in struct cfg80211_wowlan_nd_match.) Without panic_on_oops the machine is left wedged mid-resume.
Fill both arrays using local indices and store the number of entries actually filled in, as iwlmvm already does. Also stop setting a match's channels when they can't be reported, rather than leaving n_channels at the allocated size, and report the matches found so far if an allocation fails instead of returning with n_matches unset.
Seen on an Intel BE200 (iwlmld) in a Dell Pro 14 Plus with kernel 7.3.5 built with clang 23, with net-detect armed via
"iw phy phy0 wowlan enable net-detect interval 10000 matches ssid <ssid>" and that SSID in range during s2idle (also with pm_test=devices). With this change the same setup reports the match and resumes normally.
--- drivers/net/wireless/intel/iwlwifi/mld/d3.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)
drivers/net/wireless/intel/iwlwifi/mld/d3.c +11 -8
@@ -1423,11 +1423,11 @@ iwl_mld_set_netdetect_info(struct iwl_mld *mld,struct iwl_mld_netdetect_res *netdetect_res, unsigned long matched_profiles) { - int i; + int i, n_matches = 0;for_each_set_bit (i, &matched_profiles, netdetect_cfg->n_match_sets) {struct cfg80211_wowlan_nd_match *match; -int idx, j, n_channels =0 ; +int idx, j, n_channels =0 , n_set =0 ;struct iwl_scan_offload_profile_match *matches = (void *)netdetect_res->matches;
@@ -1436,10 +1436,9 @@ iwl_mld_set_netdetect_info(struct iwl_mld *mld,hweight8 (matches[i].matching_channels[k]); match =kzalloc_flex (*match, channels, n_channels);if (!match) -return ; +break ; - netdetect_info->matches[netdetect_info->n_matches] = match; - netdetect_info->n_matches++; + netdetect_info->matches[n_matches++] = match;/* We inverted the order of the SSIDs in the scan * request, so invert the index here.
@@ -1451,17 +1450,21 @@ iwl_mld_set_netdetect_info(struct iwl_mld *mld, netdetect_cfg->match_sets[idx].ssid.ssid, match->ssid.ssid_len); -if (netdetect_cfg->n_channels < n_channels) +if (netdetect_cfg->n_channels < n_channels) { + match->n_channels =0 ;continue ; + }for_each_set_bit (j, (unsigned long *)&matches[i].matching_channels[0 ],sizeof (matches[i].matching_channels)) { - match->channels[match->n_channels] = + match->channels[n_set++] = netdetect_cfg->channels[j]->center_freq; - match->n_channels++; } + match->n_channels = n_set; } + + netdetect_info->n_matches = n_matches; } static void
Signature · 1 line
2.56.1