Re: [PATCH wireless 1/2] wifi: mac80211: do not copy the mesh RSN IE twice into the beacon

From: Piyus Kedia

Date: Tue Nov 24 2026 - 23:38:47 EST


You are right, and the Critical one is right in the way that matters most:
the patch added a second route to the overrun it was fixing, reachable
without any vendor element at all. Thank you for catching it before it went
anywhere.

All three points were checked against wireless.git at af6737b90668. v2 of
this patch is posted as a separate thread:

[PATCH wireless v2] wifi: mac80211: do not copy the mesh RSN IE twice
into the beacon

Only this patch is respun; 2/2 drew its own review and is answered in its own
thread. The v2 changelog is under the --- line, with a Link: back to this
posting.

Point by point.


1. [Critical] Can prefix end up larger than ifmsh->ie_len?

> So it returns pos > ielen whenever ielen ends in the middle of an element.
> That can happen because ifmsh->ie_len is still a u8 in struct
> ieee80211_if_mesh, while the policy allows NL80211_MESH_SETUP_IE up to
> IEEE80211_MAX_DATA_LEN (2304) bytes

Yes, and every step of that holds. Checked in order:

ieee80211_ie_split_vendor() net/mac80211/util.c - advances
pos += 2 + ies[pos + 1] while pos < ielen,
so a length that ends inside an element
makes it return past that length.
struct ieee80211_if_mesh ieee80211_i.h:829 - "u8 ie_len;".
struct mesh_setup cfg80211.h - "size_t ie_len;".
copy_mesh_setup() cfg.c:3449 - "ifmsh->ie_len = setup->ie_len;",
size_t into u8.
the policy nl80211.c:10888 - NL80211_MESH_SETUP_IE is
NLA_POLICY_VALIDATE_FN(...,
IEEE80211_MAX_DATA_LEN).

and the write lands exactly where you say it does:

bcn->tail_len = skb->len; /* mesh.c:1109 */
memcpy(bcn->tail, skb->data, bcn->tail_len); /* mesh.c:1110 */

bcn is kzalloc()ed to the PRECOMPUTED tail_len while bcn->tail_len is taken
from what was actually assembled, so anything the emitters put in the builder
skb beyond the budget is copied past the end of that block. Your 257-byte
example is right: a 255-byte RSN element leaves ifmsh->ie_len at 1, the
unclamped split returns 255, and 255 bytes go into a one-byte budget. My
commit message asserted "the split returns an element boundary that is not
past ifmsh->ie_len", and that assertion is false.

> Would prefix = min(prefix, ifmsh->ie_len) fix this?

It does, and v2 is exactly that:

prefix = ieee80211_ie_split_vendor(ifmsh->ie, ifmsh->ie_len, 0);
prefix = min_t(size_t, prefix, ifmsh->ie_len);
data = cfg80211_find_ie(WLAN_EID_RSN, ifmsh->ie, prefix);

Two things make it sufficient on its own, and the commit message now says
both rather than leaving them to be rediscovered:

- the clamped bound is never wider than ifmsh->ie_len, which is the bound
this search had BEFORE the patch narrowed it. So whatever ifmsh->ie_len
happens to be - truncated or not - the patch cannot make this copy
bigger than the unpatched code's could be.
- cfg80211_find_ie() returns only an element that lies wholly inside its
bound: for_each_element() requires sizeof(*elem) + elem->datalen to fit
in the length given. So len = 2 + data[1] cannot reach past the bound
either, and the skb_put_data() fits the budget.

> It would also need either ifmsh->ie_len changed to a size_t, or
> NL80211_MESH_SETUP_IE capped in the policy at what mac80211 can store.

Agreed that the truncating assignment is a bug in its own right - a
configuration is silently stored with a length that does not describe the
blob - but v2 does not need it fixed to be safe, for the first reason above.
I have left it out deliberately rather than widen a struct field inside a
patch whose subject is the double copy.

> The follow-up commit "wifi: mac80211: widen the mesh IE offsets a u8 cannot
> hold" doesn't appear to fix this. Its commit message says "ifmsh->ie_len is
> a size_t", but the field is still a u8 at the end of the series

Also right, and worse than a wrong sentence: that patch widens the LOCAL
variables in mesh_add_vendor_ies() and mesh_add_rsn_ie() and does not touch
the field, so the message describes something the series does not do. It has
its own review and I am answering it there; whichever of the two remedies you
prefer - the field to size_t, or the policy capped - belongs in that patch
rather than this one.


2. [Low] The wrong netlink attribute

> Is this the right attribute? nl80211_join_mesh() doesn't seem to read
> NL80211_ATTR_IE.

It is not, and it does not - nl80211_join_mesh() has no reference to
NL80211_ATTR_IE at all. The blob is NL80211_MESH_SETUP_IE, nested inside
NL80211_ATTR_MESH_SETUP, stored by nl80211_parse_mesh_setup() at
nl80211.c:11071 and kmemdup()ed by copy_mesh_setup(). v2 says that, and as
you note it is not pedantry: it is that attribute's policy that admits
IEEE80211_MAX_DATA_LEN, which is the half of the Critical issue the u8 then
truncates. The reproducer in the report thread sends the right attribute;
only the prose was wrong.


3. [Low] The peering frames

> mesh_plink_frame_tx() in net/mac80211/mesh_plink.c also calls
> mesh_add_rsn_ie(), so this patch changes Mesh Peering Open/Confirm frames
> as well as beacons. Should the commit message say so?

It should, and v2 does. mesh_plink_frame_tx() calls mesh_add_rsn_ie() at
mesh_plink.c:287, right after the extended supported rates, and
mesh_add_vendor_ies() at :349, at the end of the frame - so for a
configuration with an RSN element behind a vendor element, that element used
to appear twice in peering frames too, and now appears once, in the trailing
vendor block.

> and explain why it is fine to move the RSN element out of the standard
> element order?

The argument v2 makes is the narrow one. Element order in a management frame
is not something a receiver may rely on: 802.11 parsers walk elements by id,
and mac80211's own do. The alternative is to keep the in-order copy and
accept the duplicate, which is the bug. And the only configurations affected
are those that put an RSN element behind a vendor element - the ordering in
these frames was built around the RSN element coming first, and such a
configuration is untouched.

If you would rather the element kept its position and the DUPLICATE were
suppressed instead - have mesh_add_vendor_ies() skip an RSN element it finds
in the vendor range - say so and I will respin that way. It is a bigger
change than this one and it makes the vendor range no longer verbatim, which
is why I did not reach for it first.


Thanks again. The Critical one was a real defect in my patch and it is the
kind that the commit message's own confident sentence was hiding.

pw-bot: cr