Skip to contentSkip to conversation

wifi: mac80211: negotiated TTLM sparse-map cursor

PATCH New Michael Bommarito 1 participant 3 messages May 15 mac80211

lore
Share & tools
lore
#0 lore raw

cover wifi: mac80211: negotiated TTLM sparse-map cursor

ieee80211_parse_neg_ttlm() advances its cursor by map_size for every TID, even TIDs whose bit is clear in link_map_presence and therefore contribute no map bytes to the element. A sparse map then makes a later present TID read past the validated element.

Patch 1/2 moves the cursor advance inside the if-present branch so the parser walks the same layout that ieee80211_tid_to_link_map_size_ok() already validates.

Patch 2/2 adds two KUnit cases under the new mac80211-ttlm suite to lock the layout: sparse_presence_no_oob_read crafts a buffer sized exactly to the validated element so a pre-fix run is a KASAN slab-out-of-bounds report; dense_presence_baseline confirms the fix does not regress the path that was already correct.

Reach is adjacent (AV:A) from an associated peer MLD; the sender does not need privileges on the victim kernel. The OOB bytes are gated by valid_links before being applied to driver state, so a peer cannot turn the read into a policy change. KUnit + KASAN observes a slab- out-of-bounds read when the element is exactly sized. Whether the same read trips KASAN through the production RX frame path depends on allocator state; this series does not include an over-the-air hwsim replay.

Michael Bommarito (2):
wifi: mac80211: consume only present negotiated TTLM maps
wifi: mac80211: add KUnit coverage for negotiated TTLM parser

 net/mac80211/ieee80211_i.h      |   4 +
 net/mac80211/mlme.c             |   5 +-
 net/mac80211/tests/.kunitconfig |   4 +
 net/mac80211/tests/Makefile     |   2 +-
 net/mac80211/tests/ttlm.c       | 175 ++++++++++++++++++++++++++++++++
 5 files changed, 187 insertions(+), 3 deletions(-)
 create mode 100644 net/mac80211/tests/.kunitconfig
 create mode 100644 net/mac80211/tests/ttlm.c
Signature · 1 line
2.53.0
#1 lore raw

PATCH 1/2 wifi: mac80211: consume only present negotiated TTLM maps

ieee80211_tid_to_link_map_size_ok() validates negotiated TTLM elements against the number of link-map entries indicated by link_map_presence. ieee80211_parse_neg_ttlm() must consume the same layout.

The parser advanced its cursor for every TID, including TIDs whose presence bit is clear and therefore have no map bytes in the element. A sparse map can then make a later present TID read past the validated element.

The bad bytes land in neg_ttlm->{up,down}link[tid] but are gated by valid_links before being applied to driver state, so a peer cannot turn the read into a policy change. Under KUnit + KASAN with an exact-sized element allocation the OOB read is reported as a slab-out-of-bounds; whether the same trigger fires under the production RX path depends on surrounding allocator state.

Advance the cursor only when the current TID has a map present.

Fixes 8f500fbc6c65 ("wifi: mac80211: process and save negotiated TID to Link mapping request")
Assisted-by Claude:claude-opus-4-7
---
 net/mac80211/mlme.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/mac80211/mlme.c +1 -1
index 160ae65a5c645..c3a2844740a14 100644
@@ -8155,6 +8155,7 @@ ieee80211_parse_neg_ttlm(struct ieee80211_sub_if_data *sdata,
 					 "No active links for TID %d", tid);
 				return -EINVAL;
 			}
+			pos += map_size;
 		} else {
 			map = 0;
 		}
@@ -8173,7 +8174,6 @@ ieee80211_parse_neg_ttlm(struct ieee80211_sub_if_data *sdata,
 		default:
 			return -EINVAL;
 		}
-		pos += map_size;
 	}
 	return 0;
 }
Signature · 1 line
2.53.0
#2 lore raw

PATCH 2/2 wifi: mac80211: add KUnit coverage for negotiated TTLM parser

In reply to Michael Bommarito

Add KUnit coverage for ieee80211_parse_neg_ttlm() to lock the sparse link_map_presence layout against future regressions.

The sparse_presence_no_oob_read case crafts a negotiated TTLM element with link_map_presence = BIT(0) | BIT(7) and bm_size = 2 in a buffer sized exactly to the validated element length. Without the parser fix this would read 14 bytes past the buffer when processing TID 7; under KASAN that is a slab-out-of-bounds report.

The dense_presence_baseline case crafts a fully populated link_map_presence = 0xff element to confirm that the cursor-advance fix does not regress the path that was already correct.

Export ieee80211_parse_neg_ttlm via VISIBLE_IF_MAC80211_KUNIT so the test can call it directly.

Assisted-by Claude:claude-sonnet-4-6
---
 net/mac80211/ieee80211_i.h      |   4 +
 net/mac80211/mlme.c             |   3 +-
 net/mac80211/tests/.kunitconfig |   4 +
 net/mac80211/tests/Makefile     |   2 +-
 net/mac80211/tests/ttlm.c       | 175 ++++++++++++++++++++++++++++++++
 5 files changed, 186 insertions(+), 2 deletions(-)
 create mode 100644 net/mac80211/tests/.kunitconfig
 create mode 100644 net/mac80211/tests/ttlm.c
net/mac80211/ieee80211_i.h +4 -0
index 2a693406294bc..aa9c9781db92e 100644
@@ -2948,6 +2948,10 @@ ieee80211_determine_chan_mode(struct ieee80211_sub_if_data *sdata,
 			      struct ieee80211_chan_req *chanreq,
 			      struct cfg80211_chan_def *ap_chandef,
 			      unsigned long *userspace_selectors);
+int ieee80211_parse_neg_ttlm(struct ieee80211_sub_if_data *sdata,
+			     const struct ieee80211_ttlm_elem *ttlm,
+			     struct ieee80211_neg_ttlm *neg_ttlm,
+			     u8 *direction);
 #else
 #define EXPORT_SYMBOL_IF_MAC80211_KUNIT(sym)
 #define VISIBLE_IF_MAC80211_KUNIT static
net/mac80211/mlme.c +2 -1
index c3a2844740a14..9a51870a818da 100644
@@ -8096,7 +8096,7 @@ ieee80211_send_neg_ttlm_res(struct ieee80211_sub_if_data *sdata,
 	ieee80211_tx_skb(sdata, skb);
 }
 
-static int
+VISIBLE_IF_MAC80211_KUNIT int
 ieee80211_parse_neg_ttlm(struct ieee80211_sub_if_data *sdata,
 			 const struct ieee80211_ttlm_elem *ttlm,
 			 struct ieee80211_neg_ttlm *neg_ttlm,
@@ -8177,6 +8177,7 @@ ieee80211_parse_neg_ttlm(struct ieee80211_sub_if_data *sdata,
 	}
 	return 0;
 }
+EXPORT_SYMBOL_IF_MAC80211_KUNIT(ieee80211_parse_neg_ttlm);
 
 void ieee80211_process_neg_ttlm_req(struct ieee80211_sub_if_data *sdata,
 				    struct ieee80211_mgmt *mgmt, size_t len)
net/mac80211/tests/.kunitconfig new file +4 -0
new file mode 100644
index 0000000000000..ab2cc5cfc1f5c
@@ -0,0 +1,4 @@
+CONFIG_KUNIT=y
+CONFIG_CFG80211=y
+CONFIG_MAC80211=y
+CONFIG_MAC80211_KUNIT_TEST=y
net/mac80211/tests/Makefile +1 -1
index 3c7f874e5c412..2e9ade90f7b63 100644
@@ -1,3 +1,3 @@
-mac80211-tests-y += module.o util.o elems.o mfp.o tpe.o chan-mode.o s1g_tim.o
+mac80211-tests-y += module.o util.o elems.o mfp.o tpe.o chan-mode.o s1g_tim.o ttlm.o
 
 obj-$(CONFIG_MAC80211_KUNIT_TEST) += mac80211-tests.o
net/mac80211/tests/ttlm.c new file +175 -0

175 lines not on this page · raw message

Signature · 1 line
2.53.0