Commit 96aa1b22 authored by Willem de Bruijn's avatar Willem de Bruijn Committed by David S. Miller

tun: correct header offsets in napi frags mode

Tun in IFF_NAPI_FRAGS mode calls napi_gro_frags. Unlike netif_rx and
netif_gro_receive, this expects skb->data to point to the mac layer.

But skb_probe_transport_header, __skb_get_hash_symmetric, and
xdp_do_generic in tun_get_user need skb->data to point to the network
header. Flow dissection also needs skb->protocol set, so
eth_type_trans has to be called.

Ensure the link layer header lies in linear as eth_type_trans pulls
ETH_HLEN. Then take the same code paths for frags as for not frags.
Push the link layer header back just before calling napi_gro_frags.

By pulling up to ETH_HLEN from frag0 into linear, this disables the
frag0 optimization in the special case when IFF_NAPI_FRAGS is used
with zero length iov[0] (and thus empty skb->linear).

Fixes: 90e33d45 ("tun: enable napi_gro_frags() for TUN/TAP driver")
Signed-off-by: default avatarWillem de Bruijn <willemb@google.com>
Acked-by: default avatarPetar Penkov <ppenkov@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4e4f4ce6
...@@ -1872,8 +1872,11 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, ...@@ -1872,8 +1872,11 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
skb->dev = tun->dev; skb->dev = tun->dev;
break; break;
case IFF_TAP: case IFF_TAP:
if (!frags) if (frags && !pskb_may_pull(skb, ETH_HLEN)) {
skb->protocol = eth_type_trans(skb, tun->dev); err = -ENOMEM;
goto drop;
}
skb->protocol = eth_type_trans(skb, tun->dev);
break; break;
} }
...@@ -1930,9 +1933,12 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, ...@@ -1930,9 +1933,12 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
} }
if (frags) { if (frags) {
u32 headlen;
/* Exercise flow dissector code path. */ /* Exercise flow dissector code path. */
u32 headlen = eth_get_headlen(tun->dev, skb->data, skb_push(skb, ETH_HLEN);
skb_headlen(skb)); headlen = eth_get_headlen(tun->dev, skb->data,
skb_headlen(skb));
if (unlikely(headlen > skb_headlen(skb))) { if (unlikely(headlen > skb_headlen(skb))) {
this_cpu_inc(tun->pcpu_stats->rx_dropped); this_cpu_inc(tun->pcpu_stats->rx_dropped);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment