ieee802154: socket: fix shared skb BUG_ON and double header subtraction in dgram_ioctl()
Subsystems (3)
PATCH 1/1 ieee802154: socket: fix shared skb BUG_ON and double header subtraction in dgram_ioctl()
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().
--- net/ieee802154/socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ieee802154/socket.c +1 -1
@@ -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 ;
Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
Quoted 18 lines · Hui Peng
In
dgram_ioctl()(SIOCINQ), the queued skb at the head ofsk->sk_receive_queuehas already had its MAC header stripped byieee802154_subif_frame()prior todgram_deliver(), soskb->lenis already the exact payload length thatdgram_recvmsg()will return to userspace.However,
dgram_ioctl()computes*karg = skb->len - ieee802154_hdr_length(skb). Callingieee802154_hdr_length(skb)re-parses the payload bytes as an 802.15.4 MAC header and callspskb_may_pull(skb, ...)while holdingsk->sk_receive_queue.lock. When multipleSOCK_DGRAMsockets receive a cloned copy of the frame (skb_shared(skb)is true) and the payload is non-linear,pskb_may_pull()callspskb_expand_head(), which triggersBUG_ON(skb_shared(skb)). Even on unshared linear skbs, subtractingieee802154_hdr_length(skb)a second time underflows*kargto a negative value when the payload is shorter than the bogus parsed header length.
Quoted 5 lines
Set
*karg = skb->lendirectly indgram_ioctl().Fixes e1d001fa5b47 ("net: ioctl: Use kernel memory on protocol ioctl callbacks")Assisted-by LLMSigned-off-by Hui Peng <[email protected]>
Looks legitimate.
Thanks,
Miquèl