From: Benjamin Dornel <benjamindornel@gmail.com>
To: Miri Korenblit <miriam.rachel.korenblit@intel.com>,
Johannes Berg <johannes@sipsolutions.net>
Cc: linux-wireless@vger.kernel.org, Kees Cook <kees@kernel.org>,
linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org,
Benjamin Dornel <benjamindornel@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH wireless] wifi: iwlwifi: mld: fix net-detect wakeup report after kzalloc_flex()
Date: Wed, 25 Nov 2026 19:03:47 +0800 [thread overview]
Message-ID: <20261125110347.884775-1-benjamindornel@gmail.com> (raw)
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.
Fixes: 69050f8d6d07 ("treewide: Replace kmalloc with kmalloc_obj for non-scalar types")
Cc: stable@vger.kernel.org
Signed-off-by: Benjamin Dornel <benjamindornel@gmail.com>
---
drivers/net/wireless/intel/iwlwifi/mld/d3.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/drivers/net/wireless/intel/iwlwifi/mld/d3.c b/drivers/net/wireless/intel/iwlwifi/mld/d3.c
index 77e4850..e67a22a 100644
--- a/drivers/net/wireless/intel/iwlwifi/mld/d3.c
+++ b/drivers/net/wireless/intel/iwlwifi/mld/d3.c
@@ -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
--
2.56.1
reply other threads:[~2026-11-25 11:03 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261125110347.884775-1-benjamindornel@gmail.com \
--to=benjamindornel@gmail.com \
--cc=johannes@sipsolutions.net \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=miriam.rachel.korenblit@intel.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®