mac802154: rx: fix beacon/mac_cmd skb leak and short skb_trim underflow
Subsystems (3)
PATCH 1/1 mac802154: rx: fix beacon/mac_cmd skb leak and short skb_trim underflow
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.
--- net/mac802154/rx.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
net/mac802154/rx.c +7 -2
@@ -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);
Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
Miquel Raynal
maintainerQuoted 13 lines · Hui Peng
Fix two
sk_buffhandling bugs innet/mac802154/rx.c:1. In
ieee802154_subif_frame(), theskbpassed by__ieee802154_rx_handle_packet()is already a dedicatedskb_clone()owned byieee802154_subif_frame()(withskb->users == 1), and all normal return paths consume it without extra reference increments. However, theIEEE802154_FC_TYPE_BEACONandIEEE802154_FC_TYPE_MAC_CMDbranches callmac_pkt->skb = skb_get(skb)(incrementingskb->usersto2) and returnNET_RX_SUCCESS. When the worker later callskfree_skb(mac_pkt->skb),skb->usersonly drops from2to1, permanently leaking every received Beacon and MAC Commandsk_buff. Assignmac_pkt->skb = skbdirectly.
This is okay and should probably an independent fix.
Quoted 40 lines
2. In
ieee802154_rx(), whenIEEE802154_HW_RX_OMIT_CKSUMis set,skb_put(skb, 2)is called without ensuring 2 bytes of tailroom, and whenIEEE802154_HW_RX_OMIT_CKSUMis not set,__ieee802154_rx_handle_packet()callsskb_trim(skb, skb->len - 2)without verifyingskb->len >= 2. Ensure tailroom withpskb_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 LLMSigned-off-by Hui Peng <[email protected]>--- net/mac802154/rx.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)net/mac802154/rx.c +2
-2@@ -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);
net/mac802154/rx.c void ieee802154_rx(struct ieee802154_local *local, struct sk_buff *skb) · line 493
Quoted 7 lines
net/mac802154/rx.c +2
-0@@ -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 ));
This, why not.
net/mac802154/rx.c void ieee802154_rx(struct ieee802154_local *local, struct sk_buff *skb) · line 497
Quoted 4 lines
net/mac802154/rx.c +2
-0} +if (skb->len <2 ) + goto free_skb;
But this? This is a situation that cannot happen, right? Either the PHY adds the checksum, or it does not and we add it above.
net/mac802154/rx.c void ieee802154_rx(struct ieee802154_local *local, struct sk_buff *skb) · line 501
Quoted 4 lines
net/mac802154/rx.c +1
-0+rcu_read_lock ();ieee802154_monitors_rx (local, skb);
Miquèl