@@ -295,8 +295,8 @@ struct cfg80211_beacon_registration {
struct cfg80211_cqm_config {
u32 rssi_hyst;
s32 last_rssi_event_value;
- int n_rssi_thresholds;
- s32 rssi_thresholds[];
+ DECLARE_FLEX_ARRAY_ELEMENTS_COUNT(int, n_rssi_thresholds);
+ DECLARE_FLEX_ARRAY_ELEMENTS(s32, rssi_thresholds);
};
void cfg80211_destroy_ifaces(struct cfg80211_registered_device *rdev);
@@ -12096,21 +12096,14 @@ static int nl80211_set_cqm_rssi(struct genl_info *info,
wdev_lock(wdev);
if (n_thresholds) {
- struct cfg80211_cqm_config *cqm_config;
+ struct cfg80211_cqm_config *cqm_config = NULL;
- cqm_config = kzalloc(struct_size(cqm_config, rssi_thresholds,
- n_thresholds),
- GFP_KERNEL);
- if (!cqm_config) {
- err = -ENOMEM;
+ err = mem_to_flex_dup(&cqm_config, thresholds, n_thresholds,
+ GFP_KERNEL);
+ if (err)
goto unlock;
- }
cqm_config->rssi_hyst = hysteresis;
- cqm_config->n_rssi_thresholds = n_thresholds;
- memcpy(cqm_config->rssi_thresholds, thresholds,
- flex_array_size(cqm_config, rssi_thresholds,
- n_thresholds));
wdev->cqm_config = cqm_config;
}
As part of the work to perform bounds checking on all memcpy() uses, replace the open-coded a deserialization of bytes out of memory into a trailing flexible array by using a flex_array.h helper to perform the allocation, bounds checking, and copying. Cc: Johannes Berg <johannes@sipsolutions.net> Cc: "David S. Miller" <davem@davemloft.net> Cc: Jakub Kicinski <kuba@kernel.org> Cc: Paolo Abeni <pabeni@redhat.com> Cc: linux-wireless@vger.kernel.org Cc: netdev@vger.kernel.org Cc: Eric Dumazet <edumazet@google.com> Signed-off-by: Kees Cook <keescook@chromium.org> --- net/wireless/core.h | 4 ++-- net/wireless/nl80211.c | 15 ++++----------- 2 files changed, 6 insertions(+), 13 deletions(-)