From: Kees Cook <kees@kernel.org>
To: Miri Korenblit <miriam.rachel.korenblit@intel.com>
Cc: Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
Emmanuel Grumbach <emmanuel.grumbach@intel.com>,
linux-wireless@vger.kernel.org, linux-hardening@vger.kernel.org,
Dennis Gilmore <dennis@ausil.us>,
stable@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] wifi: iwlwifi: mld: Start the netdetect match counts at zero
Date: Thu, 12 Nov 2026 22:56:09 -0800 [thread overview]
Message-ID: <20261113065608.i.785-kees@kernel.org> (raw)
iwl_mld_process_netdetect_res() allocates the netdetect results with
kzalloc_flex(), and iwl_mld_set_netdetect_info() allocates each match the
same way. kzalloc_flex() sets the __counted_by() counters "n_matches" and
"n_channels" to the allocated sizes when the compiler supports
__builtin_counted_by_ref(), but iwl_mld_set_netdetect_info() uses them as
the number of entries filled so far, expecting them to start at zero as
they did when the results came from kzalloc(). Starting from the
allocated sizes, every match and channel is stored past the end of its
array.
Reset both counters after allocation, since they are "usage" counters, not
"total allocation" counters. Also increment each counter before storing
the entry it counts, so that no store is beyond the __counted_by()
bound at the time it is made.
Build tested ARCH=x86_64 defconfig with CONFIG_IWLMLD=m and W=1, with
GCC 16.2.0.
Reported-by: Dennis Gilmore <dennis@ausil.us>
Closes: https://lore.kernel.org/all/20261112025252.71375-1-dennis@ausil.us/
Fixes: 69050f8d6d075 ("treewide: Replace kmalloc with kmalloc_obj for non-scalar types")
Cc: stable@vger.kernel.org
Signed-off-by: Kees Cook <kees@kernel.org>
---
drivers/net/wireless/intel/iwlwifi/mld/d3.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/drivers/net/wireless/intel/iwlwifi/mld/d3.c b/drivers/net/wireless/intel/iwlwifi/mld/d3.c
index ce959363f62c..711877ac4c23 100644
--- a/drivers/net/wireless/intel/iwlwifi/mld/d3.c
+++ b/drivers/net/wireless/intel/iwlwifi/mld/d3.c
@@ -1437,9 +1437,11 @@ iwl_mld_set_netdetect_info(struct iwl_mld *mld,
match = kzalloc_flex(*match, channels, n_channels);
if (!match)
return;
+ /* The channels are counted below as they are added. */
+ match->n_channels = 0;
- netdetect_info->matches[netdetect_info->n_matches] = match;
netdetect_info->n_matches++;
+ netdetect_info->matches[netdetect_info->n_matches - 1] = match;
/* We inverted the order of the SSIDs in the scan
* request, so invert the index here.
@@ -1457,9 +1459,9 @@ iwl_mld_set_netdetect_info(struct iwl_mld *mld,
for_each_set_bit(j,
(unsigned long *)&matches[i].matching_channels[0],
sizeof(matches[i].matching_channels)) {
- match->channels[match->n_channels] =
- netdetect_cfg->channels[j]->center_freq;
match->n_channels++;
+ match->channels[match->n_channels - 1] =
+ netdetect_cfg->channels[j]->center_freq;
}
}
}
@@ -1512,10 +1514,13 @@ iwl_mld_process_netdetect_res(struct iwl_mld *mld,
}
n_matches = hweight_long(matched_profiles);
netdetect_info = kzalloc_flex(*netdetect_info, matches, n_matches);
- if (netdetect_info)
+ if (netdetect_info) {
+ /* iwl_mld_set_netdetect_info() counts the matches it adds. */
+ netdetect_info->n_matches = 0;
iwl_mld_set_netdetect_info(mld, netdetect_cfg, netdetect_info,
resume_data->netdetect_res,
matched_profiles);
+ }
wakeup.net_detect = netdetect_info;
out:
--
2.55.0
reply other threads:[~2026-11-13 6:56 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=20261113065608.i.785-kees@kernel.org \
--to=kees@kernel.org \
--cc=dennis@ausil.us \
--cc=emmanuel.grumbach@intel.com \
--cc=gustavoars@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.