From: Hui Peng <benquike@gmail.com>
To: alex.aring@gmail.com, stefan@datenfreihafen.org,
miquel.raynal@bootlin.com, davem@davemloft.net,
edumazet@google.com, kuba@kernel.org, pabeni@redhat.com
Cc: linux-wpan@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH] mac802154: rx: fix beacon/mac_cmd skb leak and short skb_trim underflow
Date: Sat, 19 Sep 2026 21:36:36 +0000 [thread overview]
Message-ID: <20260919213637.3314421-1-benquike@gmail.com> (raw)
Fix two sk_buff handling bugs in `net/mac802154/rx.c`:
1. In `ieee802154_subif_frame()`, the `skb` passed by
`__ieee802154_rx_handle_packet()` is already a dedicated
`skb_clone()` owned by `ieee802154_subif_frame()` (with `skb->users
== 1`), and all normal return paths consume it without extra
reference increments. However, the `IEEE802154_FC_TYPE_BEACON` and
`IEEE802154_FC_TYPE_MAC_CMD` branches call `mac_pkt->skb =
skb_get(skb)` (incrementing `skb->users` to `2`) and return
`NET_RX_SUCCESS`. When the worker later calls
`kfree_skb(mac_pkt->skb)`, `skb->users` only drops from `2` to `1`,
permanently leaking every received Beacon and MAC Command `sk_buff`.
Assign `mac_pkt->skb = skb` directly.
2. In `ieee802154_rx()`, when `IEEE802154_HW_RX_OMIT_CKSUM` is set,
`skb_put(skb, 2)` is called without ensuring 2 bytes of tailroom, and
when `IEEE802154_HW_RX_OMIT_CKSUM` is not set,
`__ieee802154_rx_handle_packet()` calls `skb_trim(skb, skb->len - 2)`
without verifying `skb->len >= 2`. Ensure tailroom with
`pskb_expand_head(skb, 0, 2, GFP_ATOMIC)` and drop frames shorter
than 2 bytes.
Fixes: 57588c71177f ("mac802154: Handle passive scanning")
Fixes: d021d218f6d9 ("mac802154: Handle received BEACON_REQ")
Assisted-by: LLM
Signed-off-by: Hui Peng <benquike@gmail.com>
---
net/mac802154/rx.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/net/mac802154/rx.c b/net/mac802154/rx.c
index 19b5382e85a8..dbdaf5962ca7 100644
--- a/net/mac802154/rx.c
+++ b/net/mac802154/rx.c
@@ -287,7 +287,7 @@ ieee802154_subif_frame(struct ieee802154_sub_if_data *sdata,
if (!mac_pkt)
goto fail;
- mac_pkt->skb = skb_get(skb);
+ mac_pkt->skb = skb;
mac_pkt->sdata = sdata;
mac_pkt->page = sdata->local->scan_page;
mac_pkt->channel = sdata->local->scan_channel;
@@ -304,7 +304,7 @@ ieee802154_subif_frame(struct ieee802154_sub_if_data *sdata,
if (!mac_pkt)
goto fail;
- mac_pkt->skb = skb_get(skb);
+ mac_pkt->skb = skb;
mac_pkt->sdata = sdata;
netdev_hold(sdata->dev, &mac_pkt->dev_tracker, GFP_ATOMIC);
spin_lock(&sdata->local->rx_lock);
@@ -487,10 +487,15 @@ void ieee802154_rx(struct ieee802154_local *local, struct sk_buff *skb)
* solution because the monitor needs a crc here.
*/
if (local->hw.flags & IEEE802154_HW_RX_OMIT_CKSUM) {
+ if (pskb_expand_head(skb, 0, 2, GFP_ATOMIC))
+ goto free_skb;
crc = crc_ccitt(0, skb->data, skb->len);
put_unaligned_le16(crc, skb_put(skb, 2));
}
+ if (skb->len < 2)
+ goto free_skb;
+
rcu_read_lock();
ieee802154_monitors_rx(local, skb);
--
2.55.0.1082.g2b9226bbc0-goog
next reply other threads:[~2026-09-19 21:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-19 21:36 Hui Peng [this message]
2026-09-20 13:10 ` [PATCH] mac802154: rx: fix beacon/mac_cmd skb leak and short skb_trim underflow Miquel Raynal
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=20260919213637.3314421-1-benquike@gmail.com \
--to=benquike@gmail.com \
--cc=alex.aring@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wpan@vger.kernel.org \
--cc=miquel.raynal@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stefan@datenfreihafen.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.