xfrm: fix missing headroom check in xfrm_dev_direct_output
Subsystems (3)
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
@@ -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
Steffen Klassert
maintainerQuoted 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()underflowsskb->databelowskb->head, causing silent memory corruption.Fix this by using
skb_cow_head()to dynamically expand headroom if needed, and switch to the checkedskb_push()variant.Signed-off-by Günther Muller <[email protected]>
As this is a fix, please add a 'Fixes:' tag to the commit message.
Thanks!
PATCH v2 1/1 xfrm: fix missing headroom check in xfrm_dev_direct_output
In reply to Günther MullerEnsure 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
@@ -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
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()underflowsskb->databelowskb->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 checkedskb_push()variant.Fixes 5eddd76ec2fd ("xfrm: fix tunnel mode TX datapath in packet offload mode")
Extra blank line.
Quoted 25 lines
Signed-off-by Günther Muller <[email protected]>--- net/xfrm/xfrm_output.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)net/xfrm/xfrm_output.c +4
-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; +skb_push (skb, skb->dev->hard_header_len);return dev_queue_xmit (skb); }Signature · 1 line
2.39.5
Steffen Klassert
maintainerQuoted 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()underflowsskb->databelowskb->head, causing silent memory corruption.Could you please provide the steps required to reproduce the issue?
Please answer Leons question.
Thanks!
Steffen Klassert
maintainerQuoted 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()underflowsskb->databelowskb->head, causing silent memory corruption.Fix this by using
skb_cow_head()to dynamically expand headroom if needed, and switch to the checkedskb_push()variant.Fixes 5eddd76ec2fd ("xfrm: fix tunnel mode TX datapath in packet offload mode")Signed-off-by Günther Muller <[email protected]>--- net/xfrm/xfrm_output.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)net/xfrm/xfrm_output.c +0
-0
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.