From: Piyus Kedia <piyus@iiitd.ac.in>
To: Johannes Berg <johannes@sipsolutions.net>,
linux-wireless@vger.kernel.org
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Kapil Vaswani <kapil@presceralabs.ai>,
stable@vger.kernel.org
Subject: [PATCH wireless v2] wifi: mac80211: store the mesh IE blob's length without truncating it
Date: Wed, 25 Nov 2026 10:08:47 +0530 [thread overview]
Message-ID: <20261125043847.885053-1-piyus@iiitd.ac.in> (raw)
struct ieee80211_if_mesh keeps the length of the user's mesh IE blob in a
u8, and copy_mesh_setup() assigns it from a size_t that the netlink policy
allows to reach IEEE80211_MAX_DATA_LEN:
[NL80211_MESH_SETUP_IE] =
NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
IEEE80211_MAX_DATA_LEN),
...
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 and the field holds the low eight bits
of its length. Three things follow, and none of them is cosmetic.
A blob whose length is a multiple of 256 stores a length of zero, and both
builders return early on "!ifmsh->ie_len" - a secure mesh silently drops
its RSN element, from a configuration the kernel accepted.
The stored length also no longer describes the blob: it can fall inside an
element. ieee80211_ie_split_vendor() walks one whole element at a time,
while (pos < ielen && ies[pos] != WLAN_EID_VENDOR_SPECIFIC)
pos += 2 + ies[pos + 1];
so with a truncated ielen it steps over the element that crosses the
truncated end and returns a position past ielen. A 257-byte RSN element
followed by a three-byte element gives nla_len 260 and ifmsh->ie_len 4,
and the split returns 257.
And the beacon builder budgets the truncated length while copying what was
actually assembled:
tail_len = ... + ifmsh->ie_len;
bcn = kzalloc(sizeof(*bcn) + head_len + tail_len, GFP_KERNEL);
skb = __dev_alloc_skb(max(head_len, tail_len), GFP_KERNEL);
...
bcn->tail_len = skb->len;
memcpy(bcn->tail, skb->data, bcn->tail_len);
The builders' skb_tailroom() checks bound only that scratch skb, whose head
the allocator rounds up, so an emit larger than tail_len passes them and
the memcpy writes past the kzalloc()ed block. In the peering frames that
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.
Store the length as the size_t it is, and widen the two locals that derive
from it: offset and len in mesh_add_vendor_ies(), and len in
mesh_add_rsn_ie(), which truncated a 257-byte element to one byte and a
256-byte element to zero. With the field holding the real length, the
length again describes the blob validate_ie_attr() framed, the split
cannot overshoot it, and both the beacon budget and the peering-frame
budget are the size of what the builders may emit.
Fixes: 082ebb0c258d ("mac80211: fix mesh beacon format")
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-3-piyus@iiitd.ac.in/
This applies on top of the v2 of the other patch of the v1 series, "wifi:
mac80211: do not copy the mesh RSN IE twice into the beacon", which is posted
in its own thread and answers its own review. Each patch of the v1 series
drew a review of its own, so each is respun separately.
Changes in v2, all from the review of v1:
- THE PREMISE WAS FALSE AND THE PATCH WAS UNSAFE WITHOUT IT. v1 said "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", and the field is a u8. The
review showed what that cost: widening the RSN length to unsigned int
REMOVED the truncation that had been accidentally containing the copy, so
a 257-byte RSN element behind a 4-byte stored length went from emitting
one byte to emitting all 257 into a four-byte budget. v1's closing
"Neither is a memory-safety problem" was wrong in the one direction that
matters.
- So v2 fixes the field rather than only the locals: struct
ieee80211_if_mesh::ie_len becomes the size_t that struct mesh_setup and
the nl80211 policy already use. That is the first of the three remedies
the review offered, and it is the one that makes the stored length
describe the blob again - after which ieee80211_ie_split_vendor() cannot
overshoot it, the beacon budget is the size of what may be emitted, and
the peering-frame budget in mesh_plink_frame_tx(), which is sized from the
same field, is too.
- The subject and the commit message are rewritten around that. v1
described vendor elements starting past byte 255 reaching
mesh_add_vendor_ies(), which the review correctly points out cannot
happen - the truncation is at the struct field, earlier than v1 said.
- Two further consequences the review found are now stated: a blob whose
length is a multiple of 256 stores zero, so a secure mesh silently drops
its RSN element; and widening offset is not a no-op either, since the old
u8 wrapped on an overshooting split and copied a few bytes where nothing
is copied now.
- Fixes: is now 082ebb0c258d ("mac80211: fix mesh beacon format") rather
than 2b5e19677592 ("mac80211: cache mesh beacon"). Confirmed by reading
082ebb0c258d: it is the commit that added "u8 offset, len" to
mesh_add_vendor_ies() and "u8 len = 0" to mesh_add_rsn_ie(), and the
truncation predates the beacon caching and reaches the peering frames as
well. The review is right that this decides which stable trees take it.
Measured, and not: the beacon overrun this series is about was reproduced on
mainline 7.4-rc3 and on 7.3.1, with KASAN reporting a slab-out-of-bounds
write in ieee80211_mesh_build_beacon(). The truncation routes the review
found - the multiple-of-256 blob, and the 257-byte element with a four-byte
stored length - come from reading the code and have NOT been run here.
mesh.c, cfg.c and mesh_plink.c all build clean, and checkpatch --strict
reports nothing.
---
net/mac80211/ieee80211_i.h | 2 +-
net/mac80211/mesh.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index 7a64aef6890d..e0f1bc0a618f 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -826,7 +826,7 @@ struct ieee80211_if_mesh {
int num_gates;
struct beacon_data __rcu *beacon;
const u8 *ie;
- u8 ie_len;
+ size_t ie_len;
enum {
IEEE80211_MESH_SEC_NONE = 0x0,
IEEE80211_MESH_SEC_AUTHED = 0x1,
diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c
index c86be97bc921..940af399343a 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)
@@ -378,7 +378,7 @@ 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;
+ unsigned int len;
const u8 *data;
if (!ifmsh->ie || !ifmsh->ie_len)
--
2.34.1
next reply other threads:[~2026-11-25 4:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 4:38 Piyus Kedia [this message]
2026-11-25 4:43 ` netdev-bot+sinfo
2026-11-25 5:06 ` Piyus Kedia
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261125043847.885053-1-piyus@iiitd.ac.in \
--to=piyus@iiitd.ac.in \
--cc=johannes@sipsolutions.net \
--cc=kapil@presceralabs.ai \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®