Skip to content

Commit 45fa29c

Browse files
Guillaume Naultkuba-moo
authored andcommitted
bareudp: Pull inner IP header in bareudp_udp_encap_recv().
Bareudp reads the inner IP header to get the ECN value. Therefore, it needs to ensure that it's part of the skb's linear data. This is similar to the vxlan and geneve fixes for that same problem: * commit f778941 ("vxlan: Pull inner IP header in vxlan_rcv().") * commit 1ca1ba4 ("geneve: make sure to pull inner header in geneve_rx()") Fixes: 571912c ("net: UDP tunnel encapsulation module for tunnelling different protocols like MPLS, IP, NSH etc.") Signed-off-by: Guillaume Nault <[email protected]> Reviewed-by: Willem de Bruijn <[email protected]> Link: https://patch.msgid.link/5205940067c40218a70fbb888080466b2fc288db.1726046181.git.gnault@redhat.com Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 5abfdfd commit 45fa29c

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

drivers/net/bareudp.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ static int bareudp_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
6868
__be16 proto;
6969
void *oiph;
7070
int err;
71+
int nh;
7172

7273
bareudp = rcu_dereference_sk_user_data(sk);
7374
if (!bareudp)
@@ -148,10 +149,25 @@ static int bareudp_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
148149
}
149150
skb_dst_set(skb, &tun_dst->dst);
150151
skb->dev = bareudp->dev;
151-
oiph = skb_network_header(skb);
152-
skb_reset_network_header(skb);
153152
skb_reset_mac_header(skb);
154153

154+
/* Save offset of outer header relative to skb->head,
155+
* because we are going to reset the network header to the inner header
156+
* and might change skb->head.
157+
*/
158+
nh = skb_network_header(skb) - skb->head;
159+
160+
skb_reset_network_header(skb);
161+
162+
if (!pskb_inet_may_pull(skb)) {
163+
DEV_STATS_INC(bareudp->dev, rx_length_errors);
164+
DEV_STATS_INC(bareudp->dev, rx_errors);
165+
goto drop;
166+
}
167+
168+
/* Get the outer header. */
169+
oiph = skb->head + nh;
170+
155171
if (!ipv6_mod_enabled() || family == AF_INET)
156172
err = IP_ECN_decapsulate(oiph, skb);
157173
else

0 commit comments

Comments
 (0)