mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH wireless v2] wifi: mac80211: do not copy the mesh RSN IE twice into the beacon
@ 2026-11-25  4:38 Piyus Kedia
  2026-11-29  4:54 ` netdev-bot+sashiko
  0 siblings, 1 reply; 2+ messages in thread
From: Piyus Kedia @ 2026-11-25  4:38 UTC (permalink / raw)
  To: Johannes Berg, linux-wireless; +Cc: netdev, linux-kernel, Kapil Vaswani, stable

mesh_add_rsn_ie() searches the whole of the user's mesh IE blob for an RSN
element, and mesh_add_vendor_ies() copies everything from the first vendor
element to the end of that blob verbatim:

	data = cfg80211_find_ie(WLAN_EID_RSN, ifmsh->ie, ifmsh->ie_len);
	...
	skb_put_data(skb, data, len);

	offset = ieee80211_ie_split_vendor(ifmsh->ie, ifmsh->ie_len, 0);
	...
	skb_put_data(skb, ifmsh->ie + offset, len);

So an RSN element placed BEHIND a vendor element is copied by both, while
ieee80211_mesh_build_beacon() reserved room for one copy:

	tail_len = ... + ifmsh->ie_len;
	bcn = kzalloc(sizeof(*bcn) + head_len + tail_len, GFP_KERNEL);
	...
	bcn->tail_len = skb->len;
	memcpy(bcn->tail, skb->data, bcn->tail_len);

The builder skb is allocated separately and rounds up to a kmalloc bucket,
so the skb_tailroom() checks pass; bcn->tail_len is then taken from what
was actually assembled, and the memcpy writes the excess past the end of
the kzalloc()ed block.  KASAN reports a slab-out-of-bounds write in
ieee80211_mesh_build_beacon().

The blob is NL80211_MESH_SETUP_IE, nested inside NL80211_ATTR_MESH_SETUP,
which nl80211_parse_mesh_setup() stores and copy_mesh_setup() kmemdup()s.
One NL80211_CMD_JOIN_MESH carrying a vendor element followed by an RSN
element is enough.

Search only the part of the blob that comes before the first vendor
element, so the two emitters cover disjoint ranges and their combined
output fits the budget.  An RSN element behind a vendor element is still
emitted, as part of that verbatim vendor range.

The bound is clamped to ifmsh->ie_len, which matters and is not belt and
braces: ieee80211_ie_split_vendor() advances one whole element at a time,

	while (pos < ielen && ies[pos] != WLAN_EID_VENDOR_SPECIFIC)
		pos += 2 + ies[pos + 1];

so it returns a position past ielen whenever ielen ends inside an element.
That is reachable, because ifmsh->ie_len is a u8 in struct
ieee80211_if_mesh while NL80211_MESH_SETUP_IE is policy-capped at
IEEE80211_MAX_DATA_LEN, and copy_mesh_setup() assigns the size_t length to
it:

	ifmsh->ie_len = setup->ie_len;

A 257-byte blob holding a 255-byte RSN element then leaves ifmsh->ie_len
at 1, and an unclamped search bound of 255 would copy 255 bytes into a
one-byte budget - the same overrun by another route.  With the clamp the
bound is never wider than the one this search had before it was narrowed,
and cfg80211_find_ie() returns only an element lying wholly inside its
bound (for_each_element() requires 2 + datalen to fit), so the copy fits.
The truncating assignment itself is a separate pre-existing problem.

This also changes Mesh Peering Open/Confirm frames, which
mesh_plink_frame_tx() builds with the same two helpers - mesh_add_rsn_ie()
after the extended supported rates, mesh_add_vendor_ies() at the end.  An
RSN element behind a vendor element used to appear twice there as well,
once in order and once in the trailing vendor block; now it appears once,
in the trailing block, after the Mesh ID, Mesh Config, MPM, HT, VHT, HE
and EHT elements.  Element order in a management frame is not something a
receiver may rely on - 802.11 parsers walk elements by id - and the
alternative is emitting the element twice, which is the bug.  A
configuration that puts its RSN element before its vendor elements, which
is what the ordering in these frames was built around, is unaffected.

Found by AI-driven fuzzing built on top of syzkaller, and reproduced on
mainline 7.4-rc3 and 7.3.1 with a 72-line program: one interface in mesh
point mode, one JOIN_MESH whose NL80211_MESH_SETUP_IE holds a vendor
element followed by an RSN element.

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/20261124003526.78471-2-piyus@iiitd.ac.in/

This respins 1/2 of the v1 series only - the one this review covered.  2/2
("wifi: mac80211: widen the mesh IE offsets a u8 cannot hold") drew its own
review and is answered in its own thread.

Changes in v2, all from the review of v1 1/2:

 - THE CLAMP, which is the reason for this respin.  The review found that
   v1 added a second route to the very overrun it was fixing:
   ieee80211_ie_split_vendor() walks one whole element at a time, so it
   returns a position past the length it was given whenever that length ends
   inside an element, and ifmsh->ie_len being a u8 assigned from the size_t
   that NL80211_MESH_SETUP_IE carries makes that reachable.  A 257-byte blob
   holding a 255-byte RSN element leaves ifmsh->ie_len at 1 while the search
   bound became 255, so 255 bytes were copied into a one-byte budget - no
   vendor element needed.  v1's claim that "the split returns an element
   boundary that is not past ifmsh->ie_len" was simply wrong.  v2 clamps the
   bound to ifmsh->ie_len, which restores the bound the search had before it
   was narrowed, and the commit message now says why that is sufficient:
   cfg80211_find_ie() returns only an element that fits wholly inside its
   bound, because for_each_element() requires 2 + datalen to fit.

 - The right netlink attribute.  v1 said NL80211_ATTR_IE; nl80211_join_mesh()
   does not read that attribute at all.  The blob is NL80211_MESH_SETUP_IE,
   nested inside NL80211_ATTR_MESH_SETUP, parsed by nl80211_parse_mesh_setup()
   and copied by copy_mesh_setup().  That matters beyond pedantry: it is the
   NL80211_MESH_SETUP_IE policy that allows IEEE80211_MAX_DATA_LEN bytes,
   which is what the u8 truncates.

 - The peering frames.  v1 did not mention that mesh_plink_frame_tx() builds
   Mesh Peering Open/Confirm with the same two helpers, so this patch moves
   an RSN element behind a vendor element out of its usual position there
   too.  The commit message now describes that and says why it is acceptable:
   a receiver walks elements by id, and the alternative is emitting the
   element twice, which is the bug.

Not changed here: the truncating "ifmsh->ie_len = setup->ie_len" itself.  The
review is right that the follow-up patch does not fix it either - it widens
local variables in mesh.c, and its commit message's claim that ifmsh->ie_len
is a size_t is wrong; the field is still a u8.  That is answered in that
patch's own thread.  This patch is safe without it: the clamp makes the bound
no wider than ifmsh->ie_len whatever ifmsh->ie_len happens to be.

Measured, and not: the original overrun was reproduced on mainline 7.4-rc3
and on 7.3.1, and KASAN reports a slab-out-of-bounds write in
ieee80211_mesh_build_beacon().  The route the review found - the truncated
length with no vendor element at all - has NOT been run here; it comes from
reading the code, as the review's does.  mesh.o builds clean and checkpatch
--strict reports nothing.
---
 net/mac80211/mesh.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c
index 8f8814125375..c86be97bc921 100644
--- a/net/mac80211/mesh.c
+++ b/net/mac80211/mesh.c
@@ -377,14 +377,32 @@ 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 the part before the first vendor element: mesh_add_vendor_ies()
+	 * emits everything from there to the end verbatim, so searching the
+	 * whole blob here makes an RSN element behind a vendor element be
+	 * copied by both, and ieee80211_mesh_build_beacon() reserved room for
+	 * one copy.
+	 *
+	 * CLAMPED, because ieee80211_ie_split_vendor() walks one whole element
+	 * at a time and returns a value past ifmsh->ie_len when the length
+	 * ends inside an element - which ifmsh->ie_len being a u8 truncated
+	 * from the size_t the netlink attribute carries makes reachable.  With
+	 * the clamp the bound is never wider than it was before this search
+	 * was narrowed, and cfg80211_find_ie() only returns an element lying
+	 * wholly inside its bound, so the copy below still fits the budget.
+	 */
+	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	[flat|nested] 2+ messages in thread

* Re: [PATCH wireless v2] wifi: mac80211: do not copy the mesh RSN IE twice into the beacon
  2026-11-25  4:38 [PATCH wireless v2] wifi: mac80211: do not copy the mesh RSN IE twice into the beacon Piyus Kedia
@ 2026-11-29  4:54 ` netdev-bot+sashiko
  0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-11-29  4:54 UTC (permalink / raw)
  To: piyus; +Cc: johannes, linux-wireless, netdev, linux-kernel, kapil, stable, kuba

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] The fix is incomplete.

--

wifi: mac80211: do not copy the mesh RSN IE twice into the beacon

This patch makes mesh_add_rsn_ie() search only the part of the mesh IE
blob that comes before the first vendor element. An RSN element placed
behind a vendor element is then no longer emitted by both
mesh_add_rsn_ie() and mesh_add_vendor_ies(). The search bound is clamped
to ifmsh->ie_len, because ifmsh->ie_len is a u8 that can be truncated
from the netlink attribute length.

Link: https://lore.kernel.org/all/20261124003526.78471-2-piyus@iiitd.ac.in/

> diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c
> index 8f88141253758..c86be97bc9219 100644
> --- a/net/mac80211/mesh.c
> +++ b/net/mac80211/mesh.c
> @@ -377,14 +377,32 @@ int mesh_add_vendor_ies(struct ieee80211_sub_if_data *sdata,

[ ... ]

> +	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);

[Severity: High]
Do the two helpers still use the same boundary when the split position
is 256 or more?

mesh_add_vendor_ies() stores the same ieee80211_ie_split_vendor() result
in a u8:

net/mac80211/mesh.c:mesh_add_vendor_ies() {
	u8 offset, len;
	...
	offset = ieee80211_ie_split_vendor(ifmsh->ie, ifmsh->ie_len, 0);

	if (offset < ifmsh->ie_len) {
		len = ifmsh->ie_len - offset;
		data = ifmsh->ie + offset;
		...
		skb_put_data(skb, data, len);
	}
}

As the new comment says, the split can return a value past
ifmsh->ie_len when ifmsh->ie_len was truncated. Suppose that value is
256:

  mesh_add_rsn_ie() clamps prefix to ifmsh->ie_len.

  mesh_add_vendor_ies() wraps offset to 0 and copies the whole
  [0, ie_len) range verbatim.

Here is an example. A JOIN_MESH with a 511-byte NL80211_MESH_SETUP_IE
leaves ifmsh->ie_len at 255 after copy_mesh_setup(). The blob is laid
out like this:

  offset 0:   RSN, len 252 (254 bytes)
  offset 254: non-vendor element, len 0 (2 bytes)
  offset 256: non-vendor element, len 253 (255 bytes)

The split walk goes 0 -> 254 -> 256 and returns 256. Then:

  mesh_add_rsn_ie() gets prefix = 255, finds the RSN element and emits
  254 bytes.

  mesh_add_vendor_ies() gets offset = (u8)256 = 0 and emits another 255
  bytes, which contain the same RSN element.

ieee80211_mesh_build_beacon() reserves ifmsh->ie_len bytes only once in
tail_len, and then does:

	bcn->tail_len = skb->len;
	memcpy(bcn->tail, skb->data, bcn->tail_len);

Wouldn't this be the same slab-out-of-bounds write in
ieee80211_mesh_build_beacon(), even with no vendor element in the blob?

This route also existed before the patch. However, the commit message
says:

    Search only the part of the blob that comes before the first vendor
    element, so the two emitters cover disjoint ranges and their combined
    output fits the budget.

The note below the fold also says:

    This patch is safe without it: the clamp makes the bound no wider than
    ifmsh->ie_len whatever ifmsh->ie_len happens to be.

The patch is tagged for stable as a standalone fix. A backport of only
this patch would therefore still leave the overrun in place.

Could the u8 truncation itself be removed instead? One option is to
reject setup->ie_len > 255 in copy_mesh_setup(). Another is to widen
ifmsh->ie_len and the offset and len locals in mesh_add_vendor_ies() to
size_t. Either one would also make the new clamp unnecessary.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125043805.883952-1-piyus%40iiitd.ac.in

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

end of thread, other threads:[~2026-11-29  4:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25  4:38 [PATCH wireless v2] wifi: mac80211: do not copy the mesh RSN IE twice into the beacon Piyus Kedia
2026-11-29  4:54 ` 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

all inboxes | Powered by JetHome®