Skip to content

Commit 3d0ad09

Browse files
bwhacksdavem330
authored andcommitted
drivers/net: Disable UFO through virtio
IPv6 does not allow fragmentation by routers, so there is no fragmentation ID in the fixed header. UFO for IPv6 requires the ID to be passed separately, but there is no provision for this in the virtio net protocol. Until recently our software implementation of UFO/IPv6 generated a new ID, but this was a bug. Now we will use ID=0 for any UFO/IPv6 packet passed through a tap, which is even worse. Unfortunately there is no distinction between UFO/IPv4 and v6 features, so disable UFO on taps and virtio_net completely until we have a proper solution. We cannot depend on VM managers respecting the tap feature flags, so keep accepting UFO packets but log a warning the first time we do this. Signed-off-by: Ben Hutchings <ben@decadent.org.uk> Fixes: 916e4cf ("ipv6: reuse ip6_frag_id from ip6_ufo_append_data") Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 39bb5e6 commit 3d0ad09

3 files changed

Lines changed: 30 additions & 26 deletions

File tree

‎drivers/net/macvtap.c‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static struct cdev macvtap_cdev;
6565
static const struct proto_ops macvtap_socket_ops;
6666

6767
#define TUN_OFFLOADS (NETIF_F_HW_CSUM | NETIF_F_TSO_ECN | NETIF_F_TSO | \
68-
NETIF_F_TSO6 | NETIF_F_UFO)
68+
NETIF_F_TSO6)
6969
#define RX_OFFLOADS (NETIF_F_GRO | NETIF_F_LRO)
7070
#define TAP_FEATURES (NETIF_F_GSO | NETIF_F_SG)
7171

@@ -569,6 +569,8 @@ static int macvtap_skb_from_vnet_hdr(struct sk_buff *skb,
569569
gso_type = SKB_GSO_TCPV6;
570570
break;
571571
case VIRTIO_NET_HDR_GSO_UDP:
572+
pr_warn_once("macvtap: %s: using disabled UFO feature; please fix this program\n",
573+
current->comm);
572574
gso_type = SKB_GSO_UDP;
573575
break;
574576
default:
@@ -614,8 +616,6 @@ static void macvtap_skb_to_vnet_hdr(const struct sk_buff *skb,
614616
vnet_hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
615617
else if (sinfo->gso_type & SKB_GSO_TCPV6)
616618
vnet_hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV6;
617-
else if (sinfo->gso_type & SKB_GSO_UDP)
618-
vnet_hdr->gso_type = VIRTIO_NET_HDR_GSO_UDP;
619619
else
620620
BUG();
621621
if (sinfo->gso_type & SKB_GSO_TCP_ECN)
@@ -950,9 +950,6 @@ static int set_offload(struct macvtap_queue *q, unsigned long arg)
950950
if (arg & TUN_F_TSO6)
951951
feature_mask |= NETIF_F_TSO6;
952952
}
953-
954-
if (arg & TUN_F_UFO)
955-
feature_mask |= NETIF_F_UFO;
956953
}
957954

958955
/* tun/tap driver inverts the usage for TSO offloads, where
@@ -963,7 +960,7 @@ static int set_offload(struct macvtap_queue *q, unsigned long arg)
963960
* When user space turns off TSO, we turn off GSO/LRO so that
964961
* user-space will not receive TSO frames.
965962
*/
966-
if (feature_mask & (NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_UFO))
963+
if (feature_mask & (NETIF_F_TSO | NETIF_F_TSO6))
967964
features |= RX_OFFLOADS;
968965
else
969966
features &= ~RX_OFFLOADS;
@@ -1064,7 +1061,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
10641061
case TUNSETOFFLOAD:
10651062
/* let the user check for future flags */
10661063
if (arg & ~(TUN_F_CSUM | TUN_F_TSO4 | TUN_F_TSO6 |
1067-
TUN_F_TSO_ECN | TUN_F_UFO))
1064+
TUN_F_TSO_ECN))
10681065
return -EINVAL;
10691066

10701067
rtnl_lock();

‎drivers/net/tun.c‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ struct tun_struct {
174174
struct net_device *dev;
175175
netdev_features_t set_features;
176176
#define TUN_USER_FEATURES (NETIF_F_HW_CSUM|NETIF_F_TSO_ECN|NETIF_F_TSO| \
177-
NETIF_F_TSO6|NETIF_F_UFO)
177+
NETIF_F_TSO6)
178178

179179
int vnet_hdr_sz;
180180
int sndbuf;
@@ -1149,8 +1149,18 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
11491149
skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
11501150
break;
11511151
case VIRTIO_NET_HDR_GSO_UDP:
1152+
{
1153+
static bool warned;
1154+
1155+
if (!warned) {
1156+
warned = true;
1157+
netdev_warn(tun->dev,
1158+
"%s: using disabled UFO feature; please fix this program\n",
1159+
current->comm);
1160+
}
11521161
skb_shinfo(skb)->gso_type = SKB_GSO_UDP;
11531162
break;
1163+
}
11541164
default:
11551165
tun->dev->stats.rx_frame_errors++;
11561166
kfree_skb(skb);
@@ -1251,8 +1261,6 @@ static ssize_t tun_put_user(struct tun_struct *tun,
12511261
gso.gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
12521262
else if (sinfo->gso_type & SKB_GSO_TCPV6)
12531263
gso.gso_type = VIRTIO_NET_HDR_GSO_TCPV6;
1254-
else if (sinfo->gso_type & SKB_GSO_UDP)
1255-
gso.gso_type = VIRTIO_NET_HDR_GSO_UDP;
12561264
else {
12571265
pr_err("unexpected GSO type: "
12581266
"0x%x, gso_size %d, hdr_len %d\n",
@@ -1762,11 +1770,6 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
17621770
features |= NETIF_F_TSO6;
17631771
arg &= ~(TUN_F_TSO4|TUN_F_TSO6);
17641772
}
1765-
1766-
if (arg & TUN_F_UFO) {
1767-
features |= NETIF_F_UFO;
1768-
arg &= ~TUN_F_UFO;
1769-
}
17701773
}
17711774

17721775
/* This gives the user a way to test for new features in future by

‎drivers/net/virtio_net.c‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,17 @@ static void receive_buf(struct receive_queue *rq, void *buf, unsigned int len)
491491
skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
492492
break;
493493
case VIRTIO_NET_HDR_GSO_UDP:
494+
{
495+
static bool warned;
496+
497+
if (!warned) {
498+
warned = true;
499+
netdev_warn(dev,
500+
"host using disabled UFO feature; please fix it\n");
501+
}
494502
skb_shinfo(skb)->gso_type = SKB_GSO_UDP;
495503
break;
504+
}
496505
case VIRTIO_NET_HDR_GSO_TCPV6:
497506
skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
498507
break;
@@ -881,8 +890,6 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb)
881890
hdr->hdr.gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
882891
else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
883892
hdr->hdr.gso_type = VIRTIO_NET_HDR_GSO_TCPV6;
884-
else if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP)
885-
hdr->hdr.gso_type = VIRTIO_NET_HDR_GSO_UDP;
886893
else
887894
BUG();
888895
if (skb_shinfo(skb)->gso_type & SKB_GSO_TCP_ECN)
@@ -1705,7 +1712,7 @@ static int virtnet_probe(struct virtio_device *vdev)
17051712
dev->features |= NETIF_F_HW_CSUM|NETIF_F_SG|NETIF_F_FRAGLIST;
17061713

17071714
if (virtio_has_feature(vdev, VIRTIO_NET_F_GSO)) {
1708-
dev->hw_features |= NETIF_F_TSO | NETIF_F_UFO
1715+
dev->hw_features |= NETIF_F_TSO
17091716
| NETIF_F_TSO_ECN | NETIF_F_TSO6;
17101717
}
17111718
/* Individual feature bits: what can host handle? */
@@ -1715,11 +1722,9 @@ static int virtnet_probe(struct virtio_device *vdev)
17151722
dev->hw_features |= NETIF_F_TSO6;
17161723
if (virtio_has_feature(vdev, VIRTIO_NET_F_HOST_ECN))
17171724
dev->hw_features |= NETIF_F_TSO_ECN;
1718-
if (virtio_has_feature(vdev, VIRTIO_NET_F_HOST_UFO))
1719-
dev->hw_features |= NETIF_F_UFO;
17201725

17211726
if (gso)
1722-
dev->features |= dev->hw_features & (NETIF_F_ALL_TSO|NETIF_F_UFO);
1727+
dev->features |= dev->hw_features & NETIF_F_ALL_TSO;
17231728
/* (!csum && gso) case will be fixed by register_netdev() */
17241729
}
17251730
if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_CSUM))
@@ -1757,8 +1762,7 @@ static int virtnet_probe(struct virtio_device *vdev)
17571762
/* If we can receive ANY GSO packets, we must allocate large ones. */
17581763
if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO4) ||
17591764
virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO6) ||
1760-
virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_ECN) ||
1761-
virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_UFO))
1765+
virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_ECN))
17621766
vi->big_packets = true;
17631767

17641768
if (virtio_has_feature(vdev, VIRTIO_NET_F_MRG_RXBUF))
@@ -1952,9 +1956,9 @@ static struct virtio_device_id id_table[] = {
19521956
static unsigned int features[] = {
19531957
VIRTIO_NET_F_CSUM, VIRTIO_NET_F_GUEST_CSUM,
19541958
VIRTIO_NET_F_GSO, VIRTIO_NET_F_MAC,
1955-
VIRTIO_NET_F_HOST_TSO4, VIRTIO_NET_F_HOST_UFO, VIRTIO_NET_F_HOST_TSO6,
1959+
VIRTIO_NET_F_HOST_TSO4, VIRTIO_NET_F_HOST_TSO6,
19561960
VIRTIO_NET_F_HOST_ECN, VIRTIO_NET_F_GUEST_TSO4, VIRTIO_NET_F_GUEST_TSO6,
1957-
VIRTIO_NET_F_GUEST_ECN, VIRTIO_NET_F_GUEST_UFO,
1961+
VIRTIO_NET_F_GUEST_ECN,
19581962
VIRTIO_NET_F_MRG_RXBUF, VIRTIO_NET_F_STATUS, VIRTIO_NET_F_CTRL_VQ,
19591963
VIRTIO_NET_F_CTRL_RX, VIRTIO_NET_F_CTRL_VLAN,
19601964
VIRTIO_NET_F_GUEST_ANNOUNCE, VIRTIO_NET_F_MQ,

0 commit comments

Comments
 (0)