Skip to content

Commit 838c7b8

Browse files
keesjmberg-intel
authored andcommitted
wifi: nl80211: Avoid address calculations via out of bounds array indexing
Before request->channels[] can be used, request->n_channels must be set. Additionally, address calculations for memory after the "channels" array need to be calculated from the allocation base ("request") rather than via the first "out of bounds" index of "channels", otherwise run-time bounds checking will throw a warning. Reported-by: Nathan Chancellor <[email protected]> Fixes: e3eac9f ("wifi: cfg80211: Annotate struct cfg80211_scan_request with __counted_by") Signed-off-by: Kees Cook <[email protected]> Tested-by: Nathan Chancellor <[email protected]> Link: https://msgid.link/[email protected] Signed-off-by: Johannes Berg <[email protected]>
1 parent 3d91371 commit 838c7b8

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

net/wireless/nl80211.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9162,6 +9162,7 @@ static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
91629162
struct wiphy *wiphy;
91639163
int err, tmp, n_ssids = 0, n_channels, i;
91649164
size_t ie_len, size;
9165+
size_t ssids_offset, ie_offset;
91659166

91669167
wiphy = &rdev->wiphy;
91679168

@@ -9207,21 +9208,20 @@ static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
92079208
return -EINVAL;
92089209

92099210
size = struct_size(request, channels, n_channels);
9211+
ssids_offset = size;
92109212
size = size_add(size, array_size(sizeof(*request->ssids), n_ssids));
9213+
ie_offset = size;
92119214
size = size_add(size, ie_len);
92129215
request = kzalloc(size, GFP_KERNEL);
92139216
if (!request)
92149217
return -ENOMEM;
9218+
request->n_channels = n_channels;
92159219

92169220
if (n_ssids)
9217-
request->ssids = (void *)&request->channels[n_channels];
9221+
request->ssids = (void *)request + ssids_offset;
92189222
request->n_ssids = n_ssids;
9219-
if (ie_len) {
9220-
if (n_ssids)
9221-
request->ie = (void *)(request->ssids + n_ssids);
9222-
else
9223-
request->ie = (void *)(request->channels + n_channels);
9224-
}
9223+
if (ie_len)
9224+
request->ie = (void *)request + ie_offset;
92259225

92269226
i = 0;
92279227
if (scan_freqs) {

0 commit comments

Comments
 (0)