Skip to content

Commit 96aa1b2

Browse files
wdebruijdavem330
authored andcommitted
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: 90e33d4 ("tun: enable napi_gro_frags() for TUN/TAP driver") Signed-off-by: Willem de Bruijn <[email protected]> Acked-by: Petar Penkov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 4e4f4ce commit 96aa1b2

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

drivers/net/tun.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,8 +1872,11 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
18721872
skb->dev = tun->dev;
18731873
break;
18741874
case IFF_TAP:
1875-
if (!frags)
1876-
skb->protocol = eth_type_trans(skb, tun->dev);
1875+
if (frags && !pskb_may_pull(skb, ETH_HLEN)) {
1876+
err = -ENOMEM;
1877+
goto drop;
1878+
}
1879+
skb->protocol = eth_type_trans(skb, tun->dev);
18771880
break;
18781881
}
18791882

@@ -1930,9 +1933,12 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
19301933
}
19311934

19321935
if (frags) {
1936+
u32 headlen;
1937+
19331938
/* Exercise flow dissector code path. */
1934-
u32 headlen = eth_get_headlen(tun->dev, skb->data,
1935-
skb_headlen(skb));
1939+
skb_push(skb, ETH_HLEN);
1940+
headlen = eth_get_headlen(tun->dev, skb->data,
1941+
skb_headlen(skb));
19361942

19371943
if (unlikely(headlen > skb_headlen(skb))) {
19381944
this_cpu_inc(tun->pcpu_stats->rx_dropped);

0 commit comments

Comments
 (0)