Skip to contentSkip to conversation

xfrm: fix missing headroom check in xfrm_dev_direct_output

PATCH Superseded Günther Muller 3 participants 6 messages May 17 – May 20

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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.

---
 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
maintainer
#1 lore raw
Quoted 9 lines · Günther Muller

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.

As this is a fix, please add a 'Fixes:' tag to the commit message.

Thanks!

#2 lore raw

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

In reply to Günther Muller

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
#3 lore raw
Quoted 4 lines · Günther Muller

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.

Could you please provide the steps required to reproduce the issue?

Quoted 6 lines

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")

Extra blank line.

Quoted 25 lines
---
 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
maintainer
#4 lore raw
Quoted 7 lines · Leon Romanovsky
Quoted 4 lines · Günther Muller

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.

Could you please provide the steps required to reproduce the issue?

Please answer Leons question.

Thanks!

maintainer
#5 lore raw
In reply to Günther Muller
Quoted 20 lines · Günther Muller

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 +0 -0
index cc35c2fcbb..35f974d209 100644

net/xfrm/xfrm_output.c static int xfrm_dev_direct_output(struct sock *sk, struct xfrm_state *x, · line 654

Quoted 7 lines
net/xfrm/xfrm_output.c +3 -1
@@ -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;

You leak skb here. Also, we should bump a statistic counter when droping the packet.