Linux wireless drivers development
 help / color / mirror / Atom feed
* [PATCH wireless v3] wifi: mac80211: mesh: avoid duplicating RSN IE after vendor IEs
@ 2026-11-29 17:17 Piyus Kedia
  2026-11-30 17:21 ` netdev-bot+sashiko
  0 siblings, 1 reply; 2+ messages in thread
From: Piyus Kedia @ 2026-11-29 17:17 UTC (permalink / raw)
  To: Johannes Berg, linux-wireless; +Cc: netdev, linux-kernel, Kapil Vaswani, stable

mesh_add_rsn_ie() searches the entire mesh IE blob for an RSN element,
while mesh_add_vendor_ies() copies everything from the first vendor IE
to the end verbatim.  When an RSN IE follows a vendor IE, both helpers
emit it, exceeding the single ifmsh->ie_len allocation reserved by
ieee80211_mesh_build_beacon().  Because the scratch skb's rounded-up
tailroom absorbs the extra bytes, the builders' skb_tailroom() checks
succeed and the subsequent memcpy() into beacon_data overflows.

Restrict mesh_add_rsn_ie() to the prefix before the first vendor IE so
the two helpers cover disjoint ranges (an RSN IE after a vendor IE is
still emitted as part of the trailing vendor block).  Clamp the split
offset to ifmsh->ie_len, as ieee80211_ie_split_vendor() can overshoot
when ifmsh->ie_len (truncated to u8 in copy_mesh_setup()) ends
mid-element.

This also stops mesh_plink_frame_tx() from emitting duplicate RSN IEs
in peering frames, as it uses the same two helpers.

Found by AI-driven fuzzing on top of syzkaller via a mesh join with a
vendor IE followed by an RSN IE in NL80211_MESH_SETUP_IE.  On net.git
main it writes 479 bytes past the allocation:

BUG: KASAN: slab-out-of-bounds in ieee80211_mesh_build_beacon+0xe3f/0xec0
Write of size 479 at addr ffff88805ca1887b by task x/9448
 __asan_memcpy+0x40/0x70
 ieee80211_mesh_build_beacon+0xe3f/0xec0
 ieee80211_start_mesh+0x192/0x220
 ieee80211_join_mesh+0x6e1/0x7a0
 rdev_join_mesh+0xcc/0x210
 __cfg80211_join_mesh+0x9b7/0xc10
 nl80211_join_mesh+0x932/0xa90
 genl_family_rcv_msg_doit+0x1b0/0x260
 netlink_rcv_skb+0x183/0x2b0
 netlink_sendmsg+0x6d2/0x840

Fixes: 2b5e19677592 ("mac80211: cache mesh beacon")
Cc: stable@vger.kernel.org
Signed-off-by: Kapil Vaswani <kapil@presceralabs.ai>
Signed-off-by: Piyus Kedia <piyus@iiitd.ac.in>
---
Link: https://lore.kernel.org/all/20261125043805.883952-1-piyus@iiitd.ac.in/

Changes in v3: the commit message, the subject, and the code comment.  The
code is byte-identical to v2 - the only lines that differ in the diff are
comment text.

v2's message restated the code at length and quoted fourteen lines of it;
this one keeps the three things the diff does not show - that the two
helpers' ranges overlap, why the bound has to be clamped, and that mesh
peering frames are affected too - and drops the rest.  The comment is cut
the same way.  The trimmed KASAN backtrace is new in v3; the full log is
in the [BUG] posting linked above.

Changes in v2, for the record: the search bound was clamped to ifmsh->ie_len,
without which this patch added a second route to the overrun it fixes; the
netlink attribute was corrected to NL80211_MESH_SETUP_IE; and the
peering-frame effect was documented.
---
 net/mac80211/mesh.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c
index 8f8814125375..3e1a3273801b 100644
--- a/net/mac80211/mesh.c
+++ b/net/mac80211/mesh.c
@@ -377,14 +377,27 @@ int mesh_add_vendor_ies(struct ieee80211_sub_if_data *sdata,
 int mesh_add_rsn_ie(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
 {
 	struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
+	size_t prefix;
 	u8 len = 0;
 	const u8 *data;
 
 	if (!ifmsh->ie || !ifmsh->ie_len)
 		return 0;
 
+	/*
+	 * Only search before the first vendor IE: mesh_add_vendor_ies()
+	 * copies everything from that point onward verbatim, so an RSN IE
+	 * after a vendor IE would otherwise be emitted twice and overrun
+	 * the beacon allocation.
+	 *
+	 * Clamp to ifmsh->ie_len because ieee80211_ie_split_vendor() can
+	 * overshoot if a truncated ifmsh->ie_len ends mid-element.
+	 */
+	prefix = ieee80211_ie_split_vendor(ifmsh->ie, ifmsh->ie_len, 0);
+	prefix = min_t(size_t, prefix, ifmsh->ie_len);
+
 	/* find RSN IE */
-	data = cfg80211_find_ie(WLAN_EID_RSN, ifmsh->ie, ifmsh->ie_len);
+	data = cfg80211_find_ie(WLAN_EID_RSN, ifmsh->ie, prefix);
 	if (!data)
 		return 0;
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-30 17:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 17:17 [PATCH wireless v3] wifi: mac80211: mesh: avoid duplicating RSN IE after vendor IEs Piyus Kedia
2026-11-30 17:21 ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox