๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
3 messages
3 total messages Started by Piyus Kedia Tue, 24 Nov 2026 00:35
[PATCH wireless 2/2] wifi: mac80211: widen the mesh IE offsets a u8 cannot hold
#21401
Author: Piyus Kedia
Date: Tue, 24 Nov 2026 00:35
70 lines
12792 bytes
The extra IE blob a mesh join carries is bounded by IEEE80211_MAX_DATA_LEN,
2304 bytes, and ifmsh->ie_len is a size_t.  Two places that walk it use u8
for values derived from that length.

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;

ieee80211_ie_split_vendor() returns a size_t.  A blob whose vendor IEs
begin past byte 255 truncates the offset to a smaller value, so the copy
starts in the middle of an earlier element and emits bytes that are not
vendor IEs at all; len truncates with it.

mesh_add_rsn_ie():

	u8 len = 0;
	...
	len = data[1] + 2;

An element's length byte reaches 255, so this is 257 for the largest RSN IE
and truncates to 1 - the IE is then emitted as a two-byte stub, and a
secure mesh advertises a malformed RSN element.

Neither is a memory-safety problem: the preceding patch makes the two
builders cover disjoint ranges, so the beacon's single ifmsh->ie_len budget
holds whatever these values are.  Use types that can hold them.

How this was found: alongside the out-of-bounds write fixed in the
preceding patch, by AI-driven fuzzing built on top of syzkaller, then
checked by hand against the code.

Fixes: 2b5e19677592 ("mac80211: cache mesh beacon")
Signed-off-by: Kapil Vaswani <kapil@presceralabs.ai>
Signed-off-by: Piyus Kedia <piyus@iiitd.ac.in>
---
 net/mac80211/mesh.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c
index eb54bd98f282..4ab776e174d9 100644
--- a/net/mac80211/mesh.c
+++ b/net/mac80211/mesh.c
@@ -354,7 +354,7 @@ int mesh_add_vendor_ies(struct ieee80211_sub_if_data *sdata,
 			struct sk_buff *skb)
 {
 	struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
-	u8 offset, len;
+	size_t offset, len;
 	const u8 *data;
 
 	if (!ifmsh->ie || !ifmsh->ie_len)
@@ -377,9 +377,9 @@ 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;
-	u8 len = 0;
 	const u8 *data;
 	size_t prefix;
+	unsigned int len;
 
 	if (!ifmsh->ie || !ifmsh->ie_len)
 		return 0;
-- 
2.34.1
Re: [PATCH wireless 2/2] wifi: mac80211: widen the mesh IE offsets a u8 cannot hold
#22226
Author: netdev-bot+sashiko
Date: Wed, 25 Nov 2026 01:28
168 lines
14205 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 1 ยท High: 0 ยท Medium: 0 ยท Low: 1

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).

- [Critical] The fix rests on a false premise, and it makes the series'
  beacon-tail heap overflow reachable for the largest RSN IEs.
- [Low] wifi: mac80211: Fixes trailer cites 2b5e19677592 instead of
  082ebb0c258d

--

wifi: mac80211: widen the mesh IE offsets a u8 cannot hold

This patch changes the locals in mesh_add_vendor_ies() from u8 to size_t
and the RSN element length in mesh_add_rsn_ie() from u8 to unsigned int.
The goal is to stop values derived from the mesh IE blob length from being
truncated. The commit message says this is not a memory-safety change,
because the preceding patch makes the two builders cover disjoint ranges.

> diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c
> index eb54bd98f282a..4ab776e174d9c 100644
> --- a/net/mac80211/mesh.c
> +++ b/net/mac80211/mesh.c
> @@ -354,7 +354,7 @@ int mesh_add_vendor_ies(struct ieee80211_sub_if_data *sdata,
>  			struct sk_buff *skb)
>  {
>  	struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
> -	u8 offset, len;
> +	size_t offset, len;
>  	const u8 *data;
>  
>  	if (!ifmsh->ie || !ifmsh->ie_len)
> @@ -377,9 +377,9 @@ 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;
> -	u8 len = 0;
>  	const u8 *data;
>  	size_t prefix;
> +	unsigned int len;

[Severity: Low]
The Fixes: tag points at 2b5e19677592 ("mac80211: cache mesh beacon").
As far as I can tell, that commit did not add the u8 locals this patch
widens. It moved the beacon-side calls to mesh_add_vendor_ies() and
mesh_add_rsn_ie() into ieee80211_mesh_build_beacon(), and
mesh_plink_frame_tx() kept calling both helpers as before.

The helpers themselves look like they came in with 082ebb0c258d
("mac80211: fix mesh beacon format"). That includes "u8 offset, len" in
mesh_add_vendor_ies() and "u8 len = 0" in mesh_add_rsn_ie().

The truncation predates the beacon caching. It also affects the peering
frames built by mesh_plink_frame_tx(), not only the cached beacon.
Should the tag be:

  Fixes: 082ebb0c258d ("mac80211: fix mesh beacon format")

instead? There is no runtime impact, but the tag decides which stable
trees pick this up.

[Severity: Critical]
The commit message says:

  "The extra IE blob a mesh join carries is bounded by
  IEEE80211_MAX_DATA_LEN, 2304 bytes, and ifmsh->ie_len is a size_t."

Is that accurate? struct ieee80211_if_mesh in net/mac80211/ieee80211_i.h
still declares:

	const u8 *ie;
	u8 ie_len;

struct mesh_setup::ie_len in include/net/cfg80211.h is a size_t.
nl80211_parse_mesh_setup() sets it from nla_len() of NL80211_MESH_SETUP_IE,
and the policy allows up to IEEE80211_MAX_DATA_LEN. copy_mesh_setup() in
net/mac80211/cfg.c then does:

	if (setup->ie_len) {
		new_ie = kmemdup(setup->ie, setup->ie_len,
				GFP_KERNEL);
		...
	}
	ifmsh->ie_len = setup->ie_len;

So the buffer holds the whole blob, but only the low 8 bits of its length
are stored.

ifmsh->ie_len is never above 255, so the vendor IE case in the commit
message (vendor IEs starting past byte 255) can't reach
mesh_add_vendor_ies() as described. The truncation still happens, just
earlier, at the struct field.

If the blob length is a multiple of 256, ie_len becomes 0. Both builders
then return early and a secure mesh drops its RSN IE.
mesh_plink_frame_tx() in mesh_plink.c also sizes peering frames from the
same u8 field.

Widening offset is also not a complete no-op. When the vendor split
overshoots the truncated ie_len, the old u8 offset wrapped and a few bytes
got copied. Now nothing is copied.

More importantly, can the wider len now overflow the beacon_data
allocation in ieee80211_mesh_build_beacon()?

validate_ie_attr() checked the element chain against the full nla_len.
ieee80211_ie_split_vendor() steps through the blob by the real element
lengths:

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

With a truncated ielen, it can step over an element that crosses the
truncated end. It then returns a prefix larger than ifmsh->ie_len.
mesh_add_rsn_ie() then does:

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

Take a 257-byte RSN IE (length byte 255) followed by a 3-byte element.
That gives nla_len = 260, ifmsh->ie_len = 4 and prefix = 257. The RSN IE
is found, and with unsigned int len all 257 bytes are emitted. Before this
patch, the u8 len wrapped this to 1 (and 256 to 0).

ieee80211_mesh_build_beacon() only budgets the truncated length:

	tail_len = ... +
		   ifmsh->ie_len;

	bcn = kzalloc(sizeof(*bcn) + head_len + tail_len, GFP_KERNEL);
	/* need an skb for IE builders to operate on */
	skb = __dev_alloc_skb(max(head_len, tail_len), GFP_KERNEL);

The skb_tailroom() checks in the builders only bound the scratch skb. Its
head is rounded up by the allocator, so its tailroom can be much larger
than tail_len, for example on HE/EHT hardware with a long mesh ID. The
copy at the end then writes past bcn:

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

The preceding patch, "wifi: mac80211: do not copy the mesh RSN IE twice
into the beacon", argues that the split returns an element boundary not
past ifmsh->ie_len. That rests on the same assumption, so similar layouts
with smaller RSN IEs look like they already overflow there.

Would it be better to make struct ieee80211_if_mesh::ie_len a size_t to
match mesh_setup and the nl80211 policy? Rejecting setup->ie_len > 255 in
copy_mesh_setup(), or clamping prefix to ifmsh->ie_len in
mesh_add_rsn_ie(), would also work.

The "Neither is a memory-safety problem" statement in the commit message
may also need revisiting.

>  
>  	if (!ifmsh->ie || !ifmsh->ie_len)
>  		return 0;

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124003526.78471-2-piyus%40iiitd.ac.in
Re: [PATCH wireless 2/2] wifi: mac80211: widen the mesh IE offsets a u8 cannot hold
#22292
Author: Piyus Kedia
Date: Wed, 25 Nov 2026 04:38
130 lines
16624 bytes
Both findings are right, and the Critical one is right about the worst
possible thing: this patch was not the no-op its commit message claimed, it
removed a truncation that had been accidentally containing a copy, and it
said "Neither is a memory-safety problem" while doing it.  Thank you.

Checked against wireless.git at af6737b90668.  v2 is posted as a separate
thread:

  [PATCH wireless v2] wifi: mac80211: store the mesh IE blob's length
                      without truncating it

It applies on top of the v2 of the other patch of this series, which 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] The false premise, and what the widening cost

> Is that accurate? struct ieee80211_if_mesh in net/mac80211/ieee80211_i.h
> still declares:
>     const u8 *ie;
>     u8 ie_len;

It is not accurate.  ieee80211_i.h:829 is "u8 ie_len;", struct mesh_setup's
is a size_t, and copy_mesh_setup() at cfg.c:3449 assigns one to the other.
My commit message's "ifmsh->ie_len is a size_t" was simply false, and every
conclusion I drew from it is worthless.

> ifmsh->ie_len is never above 255, so the vendor IE case in the commit
> message (vendor IEs starting past byte 255) can't reach
> mesh_add_vendor_ies() as described. The truncation still happens, just
> earlier, at the struct field.

Right again, and that is the part I find most instructive: the patch widened
the locals that read a field which had already thrown the information away,
so it could not fix what it set out to fix even in principle.

> More importantly, can the wider len now overflow the beacon_data
> allocation in ieee80211_mesh_build_beacon()?
> Take a 257-byte RSN IE (length byte 255) followed by a 3-byte element.
> That gives nla_len = 260, ifmsh->ie_len = 4 and prefix = 257. The RSN IE
> is found, and with unsigned int len all 257 bytes are emitted. Before this
> patch, the u8 len wrapped this to 1 (and 256 to 0).

Yes.  Walked through it:

  validate_ie_attr()  frames the chain against the full nla_len, so a
                      257-byte element followed by a 3-byte one is accepted.
  copy_mesh_setup()   kmemdups 260 bytes and stores 4 as the length.
  split_vendor()      "pos += 2 + ies[pos + 1]" from 0 with ielen 4 returns
                      257, since it tests pos < ielen before stepping.
  find_ie(.., 257)    returns the RSN element at offset 0.
  u8 len              used to make that 257 & 0xff = 1.  unsigned int does
                      not.
  build_beacon()      budgeted ifmsh->ie_len = 4; bcn->tail_len = skb->len
                      and the memcpy writes the rest past the kzalloc.

So the widening is what makes it reachable, and the scratch skb's rounded-up
tailroom is what lets it past the skb_tailroom() checks, exactly as you say.
One distinction worth recording, since it is not symmetric: in the peering
frames mesh_plink_frame_tx() builds, the skb IS the frame and is sized from
the same u8 field, so there the same over-long emit is refused by the
tailroom check and the frame is dropped.  A failure, not a corruption.

> Would it be better to make struct ieee80211_if_mesh::ie_len a size_t to
> match mesh_setup and the nl80211 policy? Rejecting setup->ie_len > 255 in
> copy_mesh_setup(), or clamping prefix to ifmsh->ie_len in
> mesh_add_rsn_ie(), would also work.

v2 takes the first, and the subject now says so: "store the mesh IE blob's
length without truncating it".  The reason to prefer it over the other two is
that it is the only one that makes the stored length describe the blob again.
After it, the length is the one validate_ie_attr() framed, so the split
cannot overshoot; the beacon budget and the peering-frame budget are both the
size of what the builders may emit; and the two consequences you found below
go away with it rather than being contained.

Rejecting setup->ie_len > 255 would be an ABI change - a configuration the
kernel accepts today would start failing - for a field that has no reason to
be a u8.  And clamping alone would leave the other two problems in place.

> If the blob length is a multiple of 256, ie_len becomes 0. Both builders
> then return early and a secure mesh drops its RSN IE.

Confirmed, and v2's commit message states it: the kernel accepts the
configuration and then silently emits no RSN element, which for a secure mesh
is a functional failure with no diagnostic. 2304/256 = 9 such lengths are
reachable under the policy.

> Widening offset is also not a complete no-op. When the vendor split
> overshoots the truncated ie_len, the old u8 offset wrapped and a few bytes
> got copied. Now nothing is copied.

Also confirmed, and also now stated rather than left out.

> The preceding patch ... argues that the split returns an element boundary
> not past ifmsh->ie_len. That rests on the same assumption, so similar
> layouts with smaller RSN IEs look like they already overflow there.

They do, and that patch's own review found the same thing independently.  Its
v2 clamps the bound to ifmsh->ie_len, which makes it safe on its own whatever
the field's type is; with this patch applied as well the clamp becomes belt
and braces rather than load-bearing.  The two are answered separately because
they drew separate reviews, but they are the same mistake twice: a sentence
in a commit message asserting a bound that the code does not have.


2. [Low] The Fixes: tag

> Should the tag be:
>   Fixes: 082ebb0c258d ("mac80211: fix mesh beacon format")
> instead? There is no runtime impact, but the tag decides which stable
> trees pick this up.

It should, and v2 carries that.  Confirmed by reading the commit: 082ebb0c258d
is where "u8 offset, len" in mesh_add_vendor_ies() and "u8 len = 0" in
mesh_add_rsn_ie() were introduced, in 2011.  2b5e19677592 moved the
beacon-side calls into ieee80211_mesh_build_beacon() and left both helpers
as they were, so it is the right tag for the double-copy patch and the wrong
one for this.  Your point about the peering frames holds too: the truncation
reaches mesh_plink_frame_tx(), which predates the beacon caching entirely.


Thanks again.  Two reviews on two patches found the same false sentence from
two directions, which is a fair verdict on how that series was written.

pw-bot: cr
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads