* [BUG] wifi: mac80211: one JOIN_MESH writes 479 bytes past the mesh beacon, because the extra IE blob is budgeted once and copied twice
@ 2026-11-24 0:35 Piyus Kedia
2026-11-24 0:35 ` [PATCH wireless 1/2] wifi: mac80211: do not copy the mesh RSN IE twice into the beacon Piyus Kedia
2026-11-24 0:35 ` [PATCH wireless 2/2] wifi: mac80211: widen the mesh IE offsets a u8 cannot hold Piyus Kedia
0 siblings, 2 replies; 6+ messages in thread
From: Piyus Kedia @ 2026-11-24 0:35 UTC (permalink / raw)
To: Johannes Berg, linux-wireless; +Cc: netdev, linux-kernel, Kapil Vaswani
Hello,
ieee80211_mesh_build_beacon() sizes the beacon for the user's extra IE blob
once, and two of the builders that fill the tail both draw from that blob. An
IE blob that begins with a vendor IE and contains an RSN IE after it therefore
has that RSN IE emitted twice, and the tail copy runs past the allocation.
One NL80211_CMD_JOIN_MESH is enough. Reproduced on net.git main at
af6737b90668, 7.4.0-rc3-01164, with KASAN. A two-patch series follows in this
thread.
1. Root cause
net/mac80211/mesh.c, ieee80211_mesh_build_beacon():
tail_len = 2 + (IEEE80211_MAX_SUPP_RATES - 8) +
... +
ifmsh->ie_len; <-- the blob, counted once
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 tail is then built in an skb and copied in:
skb_trim(skb, 0);
bcn->tail = bcn->head + bcn->head_len;
if (ieee80211_put_srates_elem(...) ||
mesh_add_rsn_ie(sdata, skb) || <-- reads the blob
...
mesh_add_vendor_ies(sdata, skb)) <-- reads the blob
goto out_free;
bcn->tail_len = skb->len;
memcpy(bcn->tail, skb->data, bcn->tail_len);
mesh_add_vendor_ies() emits everything from the first vendor IE to the end of
the blob:
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;
if (skb_tailroom(skb) < len)
return -ENOMEM;
skb_put_data(skb, data, len);
}
and mesh_add_rsn_ie() searches all of it:
data = cfg80211_find_ie(WLAN_EID_RSN, ifmsh->ie, ifmsh->ie_len);
if (!data)
return 0;
len = data[1] + 2;
if (skb_tailroom(skb) < len)
return -ENOMEM;
skb_put_data(skb, data, len);
Put a vendor IE first and an RSN IE behind it, and
ieee80211_ie_split_vendor() returns 0: the vendor builder copies the whole
blob, and the RSN builder copies the RSN element a second time. The two
together exceed the one ifmsh->ie_len the beacon was sized with.
The skb_tailroom() tests in both builders do not catch it: the skb is
allocated max(head_len, tail_len), which is larger than tail_len whenever the
head is the bigger of the two, so the builders have room the destination does
not.
2. Impact
A heap out-of-bounds write of attacker-chosen bytes - the IE blob is the
attacker's own - immediately after a kzalloc'd beacon_data, from a single
netlink command. It needs CAP_NET_ADMIN in the owning netns and a
mesh-capable device, which a user namespace plus mac80211_hwsim provides.
The length is the attacker's choice up to the overrun, so this is a
controlled-content heap overflow rather than a crash: KASAN stops it, an
unprotected kernel does not.
3. KASAN report
net.git main, 7.4.0-rc3-01164-gaf6737b90668, KASAN (full log attached as
kasan-mesh-beacon-oob-write-mainline-7.4-rc3.txt):
BUG: KASAN: slab-out-of-bounds in ieee80211_mesh_build_beacon+0xe3f/0xf00
Write of size 479 at addr ffff88805ca1887b by task x/9448
__asan_memcpy mm/kasan/shadow.c:106
ieee80211_mesh_build_beacon net/mac80211/mesh.c:1110
ieee80211_start_mesh net/mac80211/mesh.c:1187
ieee80211_join_mesh net/mac80211/cfg.c:3330
rdev_join_mesh net/wireless/rdev-ops.h:361
__cfg80211_join_mesh net/wireless/mesh.c:214
nl80211_join_mesh net/wireless/nl80211.c:15399
genl_family_rcv_msg_doit net/netlink/genetlink.c:1114
The same reproducer on 7.3.1 gives the same write at the same source line
(kasan-mesh-beacon-oob-write-7.3.1.txt). net/mac80211/mesh.c is
byte-identical between 7.3.1 and af6737b90668, and nothing in the 34 commits
between af6737b90668 and today's net.git tip touches net/mac80211 or
net/wireless.
4. Reproducer
mesh_join_rsn_after_vendor_oob.c in this directory (sent off-list on request;
see the note at the end). It loads mac80211_hwsim, puts the interface into
mesh point mode and issues one JOIN_MESH whose NL80211_ATTR_IE holds a vendor
IE followed by an RSN IE. It faults on the first attempt on both trees.
CONFIG_MAC80211_MESH, CONFIG_MAC80211_HWSIM and KASAN are required.
5. Suggested fix
1/2 confines the RSN search to the non-vendor part of the blob, so the two
builders cover disjoint ranges and their total cannot exceed ifmsh->ie_len:
+ prefix = ieee80211_ie_split_vendor(ifmsh->ie, ifmsh->ie_len, 0);
+ data = cfg80211_find_ie(WLAN_EID_RSN, ifmsh->ie, prefix);
That split is safe to use as a length here: the blob has passed
validate_ie_attr(), which walks the element chain and requires it to end
exactly at the end of the attribute, so the result is an element boundary not
past ifmsh->ie_len. An RSN IE behind a vendor IE is still emitted, inside the
verbatim vendor range.
2/2 is not a memory-safety fix and can be dropped if you would rather take
only the first: the same two functions hold u8 values derived from a size_t
length that reaches IEEE80211_MAX_DATA_LEN. `offset` in
mesh_add_vendor_ies() truncates for a blob whose vendor IEs begin past byte
255, so the copy starts inside an earlier element; `len = data[1] + 2` in
mesh_add_rsn_ie() is 257 for the largest RSN IE and truncates to 1.
Both patches carry Fixes: 2b5e19677592 ("mac80211: cache mesh beacon"), which
is where the single budget term and the two builders arrived together. Cc:
stable is on 1/2 only. Checkpatch is clean on both.
6. What was and was not checked
Checked: the fault reproduces on net.git main under KASAN; the patched kernel
is clean on the same reproducer; a secure mesh whose blob carries the RSN IE
before any vendor IE still beacons with the RSN element present, with the
patches applied; mesh.c is identical between 7.3.1 and the current tip.
Not checked: real hardware - this is mac80211_hwsim under QEMU. We have not
measured whether a mesh peer can be made to accept the malformed RSN element
that 2/2 fixes.
This was found by AI-driven fuzzing built on top of syzkaller; its analysis
was then checked by hand against the code and every claim above was
reproduced.
Kapil Vaswani
Piyus Kedia
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH wireless 1/2] wifi: mac80211: do not copy the mesh RSN IE twice into the beacon
2026-11-24 0:35 [BUG] wifi: mac80211: one JOIN_MESH writes 479 bytes past the mesh beacon, because the extra IE blob is budgeted once and copied twice Piyus Kedia
@ 2026-11-24 0:35 ` Piyus Kedia
2026-11-24 14:02 ` Johannes Berg
2026-11-25 1:28 ` netdev-bot+sashiko
2026-11-24 0:35 ` [PATCH wireless 2/2] wifi: mac80211: widen the mesh IE offsets a u8 cannot hold Piyus Kedia
1 sibling, 2 replies; 6+ messages in thread
From: Piyus Kedia @ 2026-11-24 0:35 UTC (permalink / raw)
To: Johannes Berg, linux-wireless
Cc: netdev, linux-kernel, Kapil Vaswani, Piyus Kedia, stable
ieee80211_mesh_build_beacon() budgets the user's extra IE blob once:
tail_len = ... +
ifmsh->ie_len;
bcn = kzalloc(sizeof(*bcn) + head_len + tail_len, GFP_KERNEL);
but two of the builders that fill the tail draw from that blob.
mesh_add_vendor_ies() emits everything from the first vendor IE to the
end of it:
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);
while mesh_add_rsn_ie() searches the whole blob:
data = cfg80211_find_ie(WLAN_EID_RSN, ifmsh->ie, ifmsh->ie_len);
A blob that begins with a vendor IE therefore has its RSN IE emitted
twice - once inside the verbatim vendor range, once on its own - and the
tail copy runs past the allocation:
BUG: KASAN: slab-out-of-bounds in ieee80211_mesh_build_beacon+0xe3f
Write of size 479 at addr ffff88805ca1887b by task syz-executor
__asan_memcpy
ieee80211_mesh_build_beacon net/mac80211/mesh.c:1110
ieee80211_start_mesh net/mac80211/mesh.c:1187
ieee80211_join_mesh net/mac80211/cfg.c:3330
rdev_join_mesh
__cfg80211_join_mesh net/wireless/mesh.c:214
nl80211_join_mesh net/wireless/nl80211.c:15399
One NL80211_CMD_JOIN_MESH carrying such an NL80211_ATTR_IE is enough.
Confine the RSN search to the non-vendor part of the blob, so the two
builders cover disjoint ranges and their total cannot exceed the single
ifmsh->ie_len the beacon was sized with. The blob reaches us having passed
validate_ie_attr(), which walks the element chain and requires it to end
exactly at the end of the attribute, so the split returns an element
boundary that is not past ifmsh->ie_len.
An RSN IE placed behind a vendor IE is still emitted, as part of that
verbatim vendor range; nothing that a well-formed configuration sends is
dropped.
How this was found: by AI-driven fuzzing built on top of syzkaller. Its
analysis was checked by hand against the code, the fault was reproduced on
net.git main under KASAN, and the patched kernel is clean on the same
reproducer with ordinary secure-mesh beacons unaffected.
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>
---
net/mac80211/mesh.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c
index 8f8814125375..eb54bd98f282 100644
--- a/net/mac80211/mesh.c
+++ b/net/mac80211/mesh.c
@@ -379,12 +379,19 @@ 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;
if (!ifmsh->ie || !ifmsh->ie_len)
return 0;
- /* find RSN IE */
- data = cfg80211_find_ie(WLAN_EID_RSN, ifmsh->ie, ifmsh->ie_len);
+ /* Find the RSN IE in the non-vendor part of the blob only. Everything
+ * from the first vendor IE onwards is emitted verbatim by
+ * mesh_add_vendor_ies(), and ieee80211_mesh_build_beacon() budgets
+ * ifmsh->ie_len once for both of them, so an RSN IE sitting behind a
+ * vendor IE would be copied twice and overrun the beacon's tail.
+ */
+ prefix = ieee80211_ie_split_vendor(ifmsh->ie, ifmsh->ie_len, 0);
+ data = cfg80211_find_ie(WLAN_EID_RSN, ifmsh->ie, prefix);
if (!data)
return 0;
--
2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH wireless 1/2] wifi: mac80211: do not copy the mesh RSN IE twice into the beacon
2026-11-24 0:35 ` [PATCH wireless 1/2] wifi: mac80211: do not copy the mesh RSN IE twice into the beacon Piyus Kedia
@ 2026-11-24 14:02 ` Johannes Berg
2026-11-25 1:28 ` netdev-bot+sashiko
1 sibling, 0 replies; 6+ messages in thread
From: Johannes Berg @ 2026-11-24 14:02 UTC (permalink / raw)
To: Piyus Kedia, linux-wireless; +Cc: netdev, linux-kernel, Kapil Vaswani, stable
On Tue, 2026-11-24 at 06:05 +0530, Piyus Kedia wrote:
> ieee80211_mesh_build_beacon() budgets the user's extra IE blob once:
>
> tail_len = ... +
> ifmsh->ie_len;
>
> bcn = kzalloc(sizeof(*bcn) + head_len + tail_len, GFP_KERNEL);
>
> but two of the builders that fill the tail draw from that blob.
> mesh_add_vendor_ies() emits everything from the first vendor IE to the
> end of it:
>
> 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);
>
> while mesh_add_rsn_ie() searches the whole blob:
>
> data = cfg80211_find_ie(WLAN_EID_RSN, ifmsh->ie, ifmsh->ie_len);
>
> A blob that begins with a vendor IE therefore has its RSN IE emitted
> twice - once inside the verbatim vendor range, once on its own - and the
> tail copy runs past the allocation:
>
> BUG: KASAN: slab-out-of-bounds in ieee80211_mesh_build_beacon+0xe3f
> Write of size 479 at addr ffff88805ca1887b by task syz-executor
> __asan_memcpy
> ieee80211_mesh_build_beacon net/mac80211/mesh.c:1110
> ieee80211_start_mesh net/mac80211/mesh.c:1187
> ieee80211_join_mesh net/mac80211/cfg.c:3330
> rdev_join_mesh
> __cfg80211_join_mesh net/wireless/mesh.c:214
> nl80211_join_mesh net/wireless/nl80211.c:15399
>
> One NL80211_CMD_JOIN_MESH carrying such an NL80211_ATTR_IE is enough.
>
> Confine the RSN search to the non-vendor part of the blob, so the two
> builders cover disjoint ranges and their total cannot exceed the single
> ifmsh->ie_len the beacon was sized with. The blob reaches us having passed
> validate_ie_attr(), which walks the element chain and requires it to end
> exactly at the end of the attribute, so the split returns an element
> boundary that is not past ifmsh->ie_len.
>
> An RSN IE placed behind a vendor IE is still emitted, as part of that
> verbatim vendor range; nothing that a well-formed configuration sends is
> dropped.
>
> How this was found: by AI-driven fuzzing built on top of syzkaller. Its
> analysis was checked by hand against the code, the fault was reproduced on
> net.git main under KASAN, and the patched kernel is clean on the same
> reproducer with ordinary secure-mesh beacons unaffected.
>
Please write a better commit message. This is *mostly* just stating the
obvious, as LLMs always do.
johannes
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH wireless 1/2] wifi: mac80211: do not copy the mesh RSN IE twice into the beacon
2026-11-24 0:35 ` [PATCH wireless 1/2] wifi: mac80211: do not copy the mesh RSN IE twice into the beacon Piyus Kedia
2026-11-24 14:02 ` Johannes Berg
@ 2026-11-25 1:28 ` netdev-bot+sashiko
1 sibling, 0 replies; 6+ messages in thread
From: netdev-bot+sashiko @ 2026-11-25 1:28 UTC (permalink / raw)
To: piyus; +Cc: johannes, linux-wireless, netdev, linux-kernel, kapil, kuba
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 1 · High: 0 · Medium: 0 · Low: 2
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] This patch adds a new out-of-bounds write into the mesh
beacon buffer.
- [Low] The commit message names the wrong netlink attribute as the
trigger: "One NL80211_CMD_JOIN_MESH carrying such an NL80211_ATTR_IE…
- [Low] Changing mesh_add_rsn_ie() also changes Mesh Peering Open/Confirm
frames, which the commit message does not mention.
--
wifi: mac80211: do not copy the mesh RSN IE twice into the beacon
This commit limits the RSN IE search in mesh_add_rsn_ie() to the part of
the user's mesh IE blob that comes before the first vendor IE. That part
is found with ieee80211_ie_split_vendor(). The goal is for
mesh_add_rsn_ie() and mesh_add_vendor_ies() to cover disjoint ranges, so
their combined output fits the ifmsh->ie_len budget reserved in
ieee80211_mesh_build_beacon().
> One NL80211_CMD_JOIN_MESH carrying such an NL80211_ATTR_IE is enough.
[Severity: Low]
Is this the right attribute? nl80211_join_mesh() doesn't seem to read
NL80211_ATTR_IE. The blob that ends up in ifmsh->ie comes from
NL80211_MESH_SETUP_IE, which is nested inside NL80211_ATTR_MESH_SETUP:
net/wireless/nl80211.c:nl80211_parse_mesh_setup() {
...
if (tb[NL80211_MESH_SETUP_IE]) {
struct nlattr *ieattr =
tb[NL80211_MESH_SETUP_IE];
setup->ie = nla_data(ieattr);
setup->ie_len = nla_len(ieattr);
}
...
}
The attribute also matters for the analysis further down, because the
NL80211_MESH_SETUP_IE policy allows up to IEEE80211_MAX_DATA_LEN bytes.
> An RSN IE placed behind a vendor IE is still emitted, as part of that
> verbatim vendor range; nothing that a well-formed configuration sends is
> dropped.
[Severity: Low]
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?
In mesh_plink_frame_tx(), mesh_add_rsn_ie() runs right after the extended
supported rates. mesh_add_vendor_ies() runs at the end of the frame:
mesh_add_rsn_ie(sdata, skb) ||
...
if (mesh_add_vendor_ies(sdata, skb))
goto free;
Before this patch, an RSN IE placed behind a vendor IE appeared twice in
peering frames: once in its normal position and once in the trailing
vendor block. After this patch it appears only in the trailing vendor
block, after the Mesh ID, Mesh Config, MPM, HT, VHT, HE and EHT elements.
Beacons get the same reordering.
Could the commit message describe the peering frame change, and explain
why it is fine to move the RSN element out of the standard element order?
> diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c
> index 8f88141253758..eb54bd98f282a 100644
> --- a/net/mac80211/mesh.c
> +++ b/net/mac80211/mesh.c
> @@ -379,12 +379,19 @@ 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;
>
> if (!ifmsh->ie || !ifmsh->ie_len)
> return 0;
>
> - /* find RSN IE */
> - data = cfg80211_find_ie(WLAN_EID_RSN, ifmsh->ie, ifmsh->ie_len);
[ ... ]
> + prefix = ieee80211_ie_split_vendor(ifmsh->ie, ifmsh->ie_len, 0);
> + data = cfg80211_find_ie(WLAN_EID_RSN, ifmsh->ie, prefix);
[Severity: Critical]
Can prefix end up larger than ifmsh->ie_len here?
The commit message relies on "the split returns an element boundary that
is not past ifmsh->ie_len". However, ieee80211_ie_split_vendor() moves
forward one whole element at a time:
while (pos < ielen && ies[pos] != WLAN_EID_VENDOR_SPECIFIC)
pos += 2 + ies[pos + 1];
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:
[NL80211_MESH_SETUP_IE] =
NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
IEEE80211_MAX_DATA_LEN),
copy_mesh_setup() in net/mac80211/cfg.c kmemdup()s the full blob, then
does:
ifmsh->ie_len = setup->ie_len;
This truncates the length modulo 256. validate_ie_attr() checked element
framing only against the full nla_len, so the truncated length can fall
inside an element.
For example, take a 257 byte blob: an RSN element with a 253 byte body
(255 bytes in total), followed by a 2 byte non-vendor element. It passes
validate_ie_attr(), and ifmsh->ie_len becomes 1:
ieee80211_mesh_build_beacon()
tail_len = ... + ifmsh->ie_len; /* 1 byte budget */
mesh_add_rsn_ie()
prefix = ieee80211_ie_split_vendor(ie, 1, 0); /* 255 */
data = cfg80211_find_ie(WLAN_EID_RSN, ie, 255); /* offset 0 */
skb_put_data(skb, data, 255);
mesh_add_vendor_ies() /* nothing, 255 >= 1 */
memcpy(bcn->tail, skb->data, bcn->tail_len);
The builder skb comes from __dev_alloc_skb(max(head_len, tail_len),
GFP_KERNEL). Rounding up to the kmalloc bucket gives it slack, so the
skb_tailroom() checks pass.
Wouldn't the final memcpy() into bcn->tail then overrun the
kzalloc(sizeof(*bcn) + head_len + tail_len) allocation? That is the same
place the KASAN report in the commit message points to.
Before this patch the search was bounded by ifmsh->ie_len, so it could not
return an RSN element that extends past the budget. The sender controls
the residue of the length modulo 256 and where the RSN element straddles
it, so the overrun can reach about 253 bytes.
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, and prefix is still not clamped.
Would prefix = min(prefix, ifmsh->ie_len) fix this? 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.
> if (!data)
> return 0;
>
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124003526.78471-2-piyus%40iiitd.ac.in
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH wireless 2/2] wifi: mac80211: widen the mesh IE offsets a u8 cannot hold
2026-11-24 0:35 [BUG] wifi: mac80211: one JOIN_MESH writes 479 bytes past the mesh beacon, because the extra IE blob is budgeted once and copied twice Piyus Kedia
2026-11-24 0:35 ` [PATCH wireless 1/2] wifi: mac80211: do not copy the mesh RSN IE twice into the beacon Piyus Kedia
@ 2026-11-24 0:35 ` Piyus Kedia
2026-11-25 1:28 ` netdev-bot+sashiko
1 sibling, 1 reply; 6+ messages in thread
From: Piyus Kedia @ 2026-11-24 0:35 UTC (permalink / raw)
To: Johannes Berg, linux-wireless
Cc: netdev, linux-kernel, Kapil Vaswani, Piyus Kedia
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
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH wireless 2/2] wifi: mac80211: widen the mesh IE offsets a u8 cannot hold
2026-11-24 0:35 ` [PATCH wireless 2/2] wifi: mac80211: widen the mesh IE offsets a u8 cannot hold Piyus Kedia
@ 2026-11-25 1:28 ` netdev-bot+sashiko
0 siblings, 0 replies; 6+ messages in thread
From: netdev-bot+sashiko @ 2026-11-25 1:28 UTC (permalink / raw)
To: piyus; +Cc: johannes, linux-wireless, netdev, linux-kernel, kapil, kuba
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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-25 1:28 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-24 0:35 [BUG] wifi: mac80211: one JOIN_MESH writes 479 bytes past the mesh beacon, because the extra IE blob is budgeted once and copied twice Piyus Kedia
2026-11-24 0:35 ` [PATCH wireless 1/2] wifi: mac80211: do not copy the mesh RSN IE twice into the beacon Piyus Kedia
2026-11-24 14:02 ` Johannes Berg
2026-11-25 1:28 ` netdev-bot+sashiko
2026-11-24 0:35 ` [PATCH wireless 2/2] wifi: mac80211: widen the mesh IE offsets a u8 cannot hold Piyus Kedia
2026-11-25 1:28 ` 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®