Skip to content

Commit f51fe83

Browse files
jmberg-intelgregkh
authored andcommitted
mac80211: add fragment cache to sta_info
commit 3a11ce0 upstream. Prior patches protected against fragmentation cache attacks by coloring keys, but this shows that it can lead to issues when multiple stations use the same sequence number. Add a fragment cache to struct sta_info (in addition to the one in the interface) to separate fragments for different stations properly. This then automatically clear most of the fragment cache when a station disconnects (or reassociates) from an AP, or when client interfaces disconnect from the network, etc. On the way, also fix the comment there since this brings us in line with the recommendation in 802.11-2016 ("An AP should support ..."). Additionally, remove a useless condition (since there's no problem purging an already empty list). Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20210511200110.fc35046b0d52.I1ef101e3784d13e8f6600d83de7ec9a3a45bcd52@changeid Signed-off-by: Johannes Berg <johannes.berg@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9b21fca commit f51fe83

5 files changed

Lines changed: 73 additions & 43 deletions

File tree

‎net/mac80211/ieee80211_i.h‎

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@ struct ieee80211_local;
5050
#define IEEE80211_ENCRYPT_HEADROOM 8
5151
#define IEEE80211_ENCRYPT_TAILROOM 18
5252

53-
/* IEEE 802.11 (Ch. 9.5 Defragmentation) requires support for concurrent
54-
* reception of at least three fragmented frames. This limit can be increased
55-
* by changing this define, at the cost of slower frame reassembly and
56-
* increased memory use (about 2 kB of RAM per entry). */
57-
#define IEEE80211_FRAGMENT_MAX 4
58-
5953
/* power level hasn't been configured (or set to automatic) */
6054
#define IEEE80211_UNSET_POWER_LEVEL INT_MIN
6155

@@ -88,19 +82,6 @@ extern const u8 ieee80211_ac_to_qos_mask[IEEE80211_NUM_ACS];
8882

8983
#define IEEE80211_MAX_NAN_INSTANCE_ID 255
9084

91-
struct ieee80211_fragment_entry {
92-
struct sk_buff_head skb_list;
93-
unsigned long first_frag_time;
94-
u16 seq;
95-
u16 extra_len;
96-
u16 last_frag;
97-
u8 rx_queue;
98-
bool check_sequential_pn; /* needed for CCMP/GCMP */
99-
u8 last_pn[6]; /* PN of the last fragment if CCMP was used */
100-
unsigned int key_color;
101-
};
102-
103-
10485
struct ieee80211_bss {
10586
u32 device_ts_beacon, device_ts_presp;
10687

@@ -907,9 +888,7 @@ struct ieee80211_sub_if_data {
907888

908889
char name[IFNAMSIZ];
909890

910-
/* Fragment table for host-based reassembly */
911-
struct ieee80211_fragment_entry fragments[IEEE80211_FRAGMENT_MAX];
912-
unsigned int fragment_next;
891+
struct ieee80211_fragment_cache frags;
913892

914893
/* TID bitmap for NoAck policy */
915894
u16 noack_map;
@@ -2328,4 +2307,7 @@ u32 ieee80211_calc_expected_tx_airtime(struct ieee80211_hw *hw,
23282307
#define debug_noinline
23292308
#endif
23302309

2310+
void ieee80211_init_frag_cache(struct ieee80211_fragment_cache *cache);
2311+
void ieee80211_destroy_frag_cache(struct ieee80211_fragment_cache *cache);
2312+
23312313
#endif /* IEEE80211_I_H */

‎net/mac80211/iface.c‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
99
* Copyright 2013-2014 Intel Mobile Communications GmbH
1010
* Copyright (c) 2016 Intel Deutschland GmbH
11-
* Copyright (C) 2018-2020 Intel Corporation
11+
* Copyright (C) 2018-2021 Intel Corporation
1212
*/
1313
#include <linux/slab.h>
1414
#include <linux/kernel.h>
@@ -679,16 +679,12 @@ static void ieee80211_set_multicast_list(struct net_device *dev)
679679
*/
680680
static void ieee80211_teardown_sdata(struct ieee80211_sub_if_data *sdata)
681681
{
682-
int i;
683-
684682
/* free extra data */
685683
ieee80211_free_keys(sdata, false);
686684

687685
ieee80211_debugfs_remove_netdev(sdata);
688686

689-
for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++)
690-
__skb_queue_purge(&sdata->fragments[i].skb_list);
691-
sdata->fragment_next = 0;
687+
ieee80211_destroy_frag_cache(&sdata->frags);
692688

693689
if (ieee80211_vif_is_mesh(&sdata->vif))
694690
ieee80211_mesh_teardown_sdata(sdata);
@@ -1950,8 +1946,7 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name,
19501946
sdata->wdev.wiphy = local->hw.wiphy;
19511947
sdata->local = local;
19521948

1953-
for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++)
1954-
skb_queue_head_init(&sdata->fragments[i].skb_list);
1949+
ieee80211_init_frag_cache(&sdata->frags);
19551950

19561951
INIT_LIST_HEAD(&sdata->key_list);
19571952

‎net/mac80211/rx.c‎

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,19 +2133,34 @@ ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
21332133
return result;
21342134
}
21352135

2136+
void ieee80211_init_frag_cache(struct ieee80211_fragment_cache *cache)
2137+
{
2138+
int i;
2139+
2140+
for (i = 0; i < ARRAY_SIZE(cache->entries); i++)
2141+
skb_queue_head_init(&cache->entries[i].skb_list);
2142+
}
2143+
2144+
void ieee80211_destroy_frag_cache(struct ieee80211_fragment_cache *cache)
2145+
{
2146+
int i;
2147+
2148+
for (i = 0; i < ARRAY_SIZE(cache->entries); i++)
2149+
__skb_queue_purge(&cache->entries[i].skb_list);
2150+
}
2151+
21362152
static inline struct ieee80211_fragment_entry *
2137-
ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
2153+
ieee80211_reassemble_add(struct ieee80211_fragment_cache *cache,
21382154
unsigned int frag, unsigned int seq, int rx_queue,
21392155
struct sk_buff **skb)
21402156
{
21412157
struct ieee80211_fragment_entry *entry;
21422158

2143-
entry = &sdata->fragments[sdata->fragment_next++];
2144-
if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
2145-
sdata->fragment_next = 0;
2159+
entry = &cache->entries[cache->next++];
2160+
if (cache->next >= IEEE80211_FRAGMENT_MAX)
2161+
cache->next = 0;
21462162

2147-
if (!skb_queue_empty(&entry->skb_list))
2148-
__skb_queue_purge(&entry->skb_list);
2163+
__skb_queue_purge(&entry->skb_list);
21492164

21502165
__skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
21512166
*skb = NULL;
@@ -2160,14 +2175,14 @@ ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
21602175
}
21612176

21622177
static inline struct ieee80211_fragment_entry *
2163-
ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
2178+
ieee80211_reassemble_find(struct ieee80211_fragment_cache *cache,
21642179
unsigned int frag, unsigned int seq,
21652180
int rx_queue, struct ieee80211_hdr *hdr)
21662181
{
21672182
struct ieee80211_fragment_entry *entry;
21682183
int i, idx;
21692184

2170-
idx = sdata->fragment_next;
2185+
idx = cache->next;
21712186
for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
21722187
struct ieee80211_hdr *f_hdr;
21732188
struct sk_buff *f_skb;
@@ -2176,7 +2191,7 @@ ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
21762191
if (idx < 0)
21772192
idx = IEEE80211_FRAGMENT_MAX - 1;
21782193

2179-
entry = &sdata->fragments[idx];
2194+
entry = &cache->entries[idx];
21802195
if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
21812196
entry->rx_queue != rx_queue ||
21822197
entry->last_frag + 1 != frag)
@@ -2217,6 +2232,7 @@ static bool requires_sequential_pn(struct ieee80211_rx_data *rx, __le16 fc)
22172232
static ieee80211_rx_result debug_noinline
22182233
ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
22192234
{
2235+
struct ieee80211_fragment_cache *cache = &rx->sdata->frags;
22202236
struct ieee80211_hdr *hdr;
22212237
u16 sc;
22222238
__le16 fc;
@@ -2238,6 +2254,9 @@ ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
22382254
goto out_no_led;
22392255
}
22402256

2257+
if (rx->sta)
2258+
cache = &rx->sta->frags;
2259+
22412260
if (likely(!ieee80211_has_morefrags(fc) && frag == 0))
22422261
goto out;
22432262

@@ -2256,7 +2275,7 @@ ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
22562275

22572276
if (frag == 0) {
22582277
/* This is the first fragment of a new frame. */
2259-
entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
2278+
entry = ieee80211_reassemble_add(cache, frag, seq,
22602279
rx->seqno_idx, &(rx->skb));
22612280
if (requires_sequential_pn(rx, fc)) {
22622281
int queue = rx->security_idx;
@@ -2284,7 +2303,7 @@ ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
22842303
/* This is a fragment for a frame that should already be pending in
22852304
* fragment cache. Add this fragment to the end of the pending entry.
22862305
*/
2287-
entry = ieee80211_reassemble_find(rx->sdata, frag, seq,
2306+
entry = ieee80211_reassemble_find(cache, frag, seq,
22882307
rx->seqno_idx, hdr);
22892308
if (!entry) {
22902309
I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);

‎net/mac80211/sta_info.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
55
* Copyright 2013-2014 Intel Mobile Communications GmbH
66
* Copyright (C) 2015 - 2017 Intel Deutschland GmbH
7-
* Copyright (C) 2018-2020 Intel Corporation
7+
* Copyright (C) 2018-2021 Intel Corporation
88
*/
99

1010
#include <linux/module.h>
@@ -392,6 +392,8 @@ struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
392392

393393
u64_stats_init(&sta->rx_stats.syncp);
394394

395+
ieee80211_init_frag_cache(&sta->frags);
396+
395397
sta->sta_state = IEEE80211_STA_NONE;
396398

397399
/* Mark TID as unreserved */
@@ -1102,6 +1104,8 @@ static void __sta_info_destroy_part2(struct sta_info *sta)
11021104

11031105
ieee80211_sta_debugfs_remove(sta);
11041106

1107+
ieee80211_destroy_frag_cache(&sta->frags);
1108+
11051109
cleanup_single_sta(sta);
11061110
}
11071111

‎net/mac80211/sta_info.h‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright 2002-2005, Devicescape Software, Inc.
44
* Copyright 2013-2014 Intel Mobile Communications GmbH
55
* Copyright(c) 2015-2017 Intel Deutschland GmbH
6-
* Copyright(c) 2020 Intel Corporation
6+
* Copyright(c) 2020-2021 Intel Corporation
77
*/
88

99
#ifndef STA_INFO_H
@@ -436,6 +436,33 @@ struct ieee80211_sta_rx_stats {
436436
u64 msdu[IEEE80211_NUM_TIDS + 1];
437437
};
438438

439+
/*
440+
* IEEE 802.11-2016 (10.6 "Defragmentation") recommends support for "concurrent
441+
* reception of at least one MSDU per access category per associated STA"
442+
* on APs, or "at least one MSDU per access category" on other interface types.
443+
*
444+
* This limit can be increased by changing this define, at the cost of slower
445+
* frame reassembly and increased memory use while fragments are pending.
446+
*/
447+
#define IEEE80211_FRAGMENT_MAX 4
448+
449+
struct ieee80211_fragment_entry {
450+
struct sk_buff_head skb_list;
451+
unsigned long first_frag_time;
452+
u16 seq;
453+
u16 extra_len;
454+
u16 last_frag;
455+
u8 rx_queue;
456+
bool check_sequential_pn; /* needed for CCMP/GCMP */
457+
u8 last_pn[6]; /* PN of the last fragment if CCMP was used */
458+
unsigned int key_color;
459+
};
460+
461+
struct ieee80211_fragment_cache {
462+
struct ieee80211_fragment_entry entries[IEEE80211_FRAGMENT_MAX];
463+
unsigned int next;
464+
};
465+
439466
/*
440467
* The bandwidth threshold below which the per-station CoDel parameters will be
441468
* scaled to be more lenient (to prevent starvation of slow stations). This
@@ -529,6 +556,7 @@ struct ieee80211_sta_rx_stats {
529556
* @status_stats.last_ack_signal: last ACK signal
530557
* @status_stats.ack_signal_filled: last ACK signal validity
531558
* @status_stats.avg_ack_signal: average ACK signal
559+
* @frags: fragment cache
532560
*/
533561
struct sta_info {
534562
/* General information, mostly static */
@@ -637,6 +665,8 @@ struct sta_info {
637665

638666
struct cfg80211_chan_def tdls_chandef;
639667

668+
struct ieee80211_fragment_cache frags;
669+
640670
/* keep last! */
641671
struct ieee80211_sta sta;
642672
};

0 commit comments

Comments
 (0)