skb metadata is meant for passing information between XDP and TC. LWT programs cannot access the __sk_buff->data_meta pseudo-pointer. However, LWT_XMIT programs can call helpers that move packet data. One such helper is bpf_skb_change_head(), which uses skb_data_move() to move both packet data and metadata after skb_push(). skb_data_move() expects metadata to sit immediately before skb->data. This is the layout that commit 8989d328dfe7 ("net: Helper to move packet data and metadata after skb_push/pull") preserves for TC(X) programs when skb_push() or skb_pull() moves packet data. The IP output path can run LWT xmit before neighbour output has built the outgoing L2 header. For forwarded, or otherwise RX-originated, packets skb->data points at the network header while skb_mac_header() can still point at the old L2 header. If such an skb still carries XDP metadata, skb_data_move() sees metadata ending at skb_mac_header(), not immediately before skb->data, and warns. Drop skb metadata before calling into LWT xmit from the IPv4 and IPv6 output paths. Metadata is not part of the LWT BPF interface, and keeping it attached lets hidden RX metadata affect LWT skb mutation helpers. Fixes: 8989d328dfe7 ("net: Helper to move packet data and metadata after skb_push/pull") Signed-off-by: Jakub Sitnicki --- net/ipv4/ip_output.c | 2 ++ net/ipv6/ip6_output.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index e4790cc7b5c2..3295e043310f 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -220,6 +220,8 @@ static int ip_finish_output2(struct net *net, struct sock *sk, struct sk_buff *s return -ENOMEM; } + skb_metadata_clear(skb); + if (lwtunnel_xmit_redirect(dst->lwtstate)) { int res = lwtunnel_xmit(skb); diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 7e92909ab5be..734818463e07 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -111,6 +111,8 @@ static int ip6_finish_output2(struct net *net, struct sock *sk, struct sk_buff * } } + skb_metadata_clear(skb); + if (lwtunnel_xmit_redirect(dst->lwtstate)) { int res = lwtunnel_xmit(skb);