Skip to contentSkip to conversation

xfrm: fix missing headroom check in xfrm_dev_direct_output

PATCH New Günther Muller 1 participant 1 message May 18

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xfrm: fix missing headroom check in xfrm_dev_direct_output

Ensure the skb has enough headroom for the hardware offload device's hard_header_len. If the headroom is insufficient (e.g., when routing through certain virtual or tunnel devices), __skb_push() underflows skb->data below skb->head, causing silent memory corruption.

Fix this by using skb_cow_head() to dynamically expand headroom if needed, and switch to the checked skb_push() variant.

Fixes 5eddd76ec2fd ("xfrm: fix tunnel mode TX datapath in packet offload mode")
---
 net/xfrm/xfrm_output.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/xfrm/xfrm_output.c +4 -1
index cc35c2fcbb..35f974d209 100644
@@ -649,7 +649,10 @@ static int xfrm_dev_direct_output(struct sock *sk, struct xfrm_state *x,
 	 * to netdevice.
 	 */
 	skb->dev = x->xso.dev;
-	__skb_push(skb, skb->dev->hard_header_len);
+	err = skb_cow_head(skb, skb->dev->hard_header_len);
+	if (err)
+		return err;
+	skb_push(skb, skb->dev->hard_header_len);
 	return dev_queue_xmit(skb);
 }
 
Signature · 1 line
2.39.5