* [PATCH] ieee802154: socket: fix shared skb BUG_ON and double header subtraction in dgram_ioctl()
@ 2026-09-19 21:28 Hui Peng
2026-09-20 13:12 ` Miquel Raynal
0 siblings, 1 reply; 2+ messages in thread
From: Hui Peng @ 2026-09-19 21:28 UTC (permalink / raw)
To: alex.aring, stefan, miquel.raynal, davem, edumazet, kuba, pabeni
Cc: horms, linux-wpan, netdev, linux-kernel
In `dgram_ioctl()` (`SIOCINQ`), the queued skb at the head of
`sk->sk_receive_queue` has already had its MAC header stripped by
`ieee802154_subif_frame()` prior to `dgram_deliver()`, so `skb->len` is
already the exact payload length that `dgram_recvmsg()` will return to
userspace.
However, `dgram_ioctl()` computes `*karg = skb->len -
ieee802154_hdr_length(skb)`. Calling `ieee802154_hdr_length(skb)`
re-parses the payload bytes as an 802.15.4 MAC header and calls
`pskb_may_pull(skb, ...)` while holding `sk->sk_receive_queue.lock`.
When multiple `SOCK_DGRAM` sockets receive a cloned copy of the frame
(`skb_shared(skb)` is true) and the payload is non-linear,
`pskb_may_pull()` calls `pskb_expand_head()`, which triggers
`BUG_ON(skb_shared(skb))`. Even on unshared linear skbs, subtracting
`ieee802154_hdr_length(skb)` a second time underflows `*karg` to a
negative value when the payload is shorter than the bogus parsed header
length.
Set `*karg = skb->len` directly in `dgram_ioctl()`.
Fixes: e1d001fa5b47 ("net: ioctl: Use kernel memory on protocol ioctl callbacks")
Assisted-by: LLM
Signed-off-by: Hui Peng <benquike@gmail.com>
---
net/ieee802154/socket.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/ieee802154/socket.c b/net/ieee802154/socket.c
index 5a36e87893f6..8d660fe87d4e 100644
--- a/net/ieee802154/socket.c
+++ b/net/ieee802154/socket.c
@@ -552,7 +552,7 @@ static int dgram_ioctl(struct sock *sk, int cmd, int *karg)
* of this packet since that is all
* that will be read.
*/
- *karg = skb->len - ieee802154_hdr_length(skb);
+ *karg = skb->len;
}
spin_unlock_bh(&sk->sk_receive_queue.lock);
return 0;
--
2.55.0.1082.g2b9226bbc0-goog
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] ieee802154: socket: fix shared skb BUG_ON and double header subtraction in dgram_ioctl()
2026-09-19 21:28 [PATCH] ieee802154: socket: fix shared skb BUG_ON and double header subtraction in dgram_ioctl() Hui Peng
@ 2026-09-20 13:12 ` Miquel Raynal
0 siblings, 0 replies; 2+ messages in thread
From: Miquel Raynal @ 2026-09-20 13:12 UTC (permalink / raw)
To: Hui Peng
Cc: alex.aring, stefan, davem, edumazet, kuba, pabeni, horms,
linux-wpan, netdev, linux-kernel
On 19/09/2026 at 21:28:55 GMT, Hui Peng <benquike@gmail.com> wrote:
> In `dgram_ioctl()` (`SIOCINQ`), the queued skb at the head of
> `sk->sk_receive_queue` has already had its MAC header stripped by
> `ieee802154_subif_frame()` prior to `dgram_deliver()`, so `skb->len` is
> already the exact payload length that `dgram_recvmsg()` will return to
> userspace.
>
> However, `dgram_ioctl()` computes `*karg = skb->len -
> ieee802154_hdr_length(skb)`. Calling `ieee802154_hdr_length(skb)`
> re-parses the payload bytes as an 802.15.4 MAC header and calls
> `pskb_may_pull(skb, ...)` while holding `sk->sk_receive_queue.lock`.
> When multiple `SOCK_DGRAM` sockets receive a cloned copy of the frame
> (`skb_shared(skb)` is true) and the payload is non-linear,
> `pskb_may_pull()` calls `pskb_expand_head()`, which triggers
> `BUG_ON(skb_shared(skb))`. Even on unshared linear skbs, subtracting
> `ieee802154_hdr_length(skb)` a second time underflows `*karg` to a
> negative value when the payload is shorter than the bogus parsed header
> length.
>
> Set `*karg = skb->len` directly in `dgram_ioctl()`.
>
> Fixes: e1d001fa5b47 ("net: ioctl: Use kernel memory on protocol ioctl callbacks")
> Assisted-by: LLM
> Signed-off-by: Hui Peng <benquike@gmail.com>
Looks legitimate.
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Thanks,
Miquèl
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-20 13:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-19 21:28 [PATCH] ieee802154: socket: fix shared skb BUG_ON and double header subtraction in dgram_ioctl() Hui Peng
2026-09-20 13:12 ` Miquel Raynal
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®