* [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; 3+ 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] 3+ 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 0:35 ` [PATCH wireless 2/2] wifi: mac80211: widen the mesh IE offsets a u8 cannot hold Piyus Kedia
1 sibling, 0 replies; 3+ 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] 3+ 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
1 sibling, 0 replies; 3+ 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] 3+ messages in thread
end of thread, other threads:[~2026-11-24 0:35 UTC | newest]
Thread overview: 3+ 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 0:35 ` [PATCH wireless 2/2] wifi: mac80211: widen the mesh IE offsets a u8 cannot hold Piyus Kedia
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®