mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-12 13:55:32 +00:00
net: in virtio_net_hdr only add VLAN_HLEN to csum_start if payload holds vlan
[ Upstream commitfd3a886258
] Tun, tap, virtio, packet and uml vector all use struct virtio_net_hdr to communicate packet metadata to userspace. For skbuffs with vlan, the first two return the packet as it may have existed on the wire, inserting the VLAN tag in the user buffer. Then virtio_net_hdr.csum_start needs to be adjusted by VLAN_HLEN bytes. Commitf09e2249c4
("macvtap: restore vlan header on user read") added this feature to macvtap. Commit3ce9b20f19
("macvtap: Fix csum_start when VLAN tags are present") then fixed up csum_start. Virtio, packet and uml do not insert the vlan header in the user buffer. When introducing virtio_net_hdr_from_skb to deduplicate filling in the virtio_net_hdr, the variant from macvtap which adds VLAN_HLEN was applied uniformly, breaking csum offset for packets with vlan on virtio and packet. Make insertion of VLAN_HLEN optional. Convert the callers to pass it when needed. Fixes:e858fae2b0
("virtio_net: use common code for virtio_net_hdr and skb GSO conversion") Fixes:1276f24eee
("packet: use common code for virtio_net_hdr and skb GSO conversion") Signed-off-by: Willem de Bruijn <willemb@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
2e5d316882
commit
5320e035d7
5 changed files with 14 additions and 12 deletions
|
@ -777,13 +777,16 @@ static ssize_t tap_put_user(struct tap_queue *q,
|
||||||
int total;
|
int total;
|
||||||
|
|
||||||
if (q->flags & IFF_VNET_HDR) {
|
if (q->flags & IFF_VNET_HDR) {
|
||||||
|
int vlan_hlen = skb_vlan_tag_present(skb) ? VLAN_HLEN : 0;
|
||||||
struct virtio_net_hdr vnet_hdr;
|
struct virtio_net_hdr vnet_hdr;
|
||||||
|
|
||||||
vnet_hdr_len = READ_ONCE(q->vnet_hdr_sz);
|
vnet_hdr_len = READ_ONCE(q->vnet_hdr_sz);
|
||||||
if (iov_iter_count(iter) < vnet_hdr_len)
|
if (iov_iter_count(iter) < vnet_hdr_len)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (virtio_net_hdr_from_skb(skb, &vnet_hdr,
|
if (virtio_net_hdr_from_skb(skb, &vnet_hdr,
|
||||||
tap_is_little_endian(q), true))
|
tap_is_little_endian(q), true,
|
||||||
|
vlan_hlen))
|
||||||
BUG();
|
BUG();
|
||||||
|
|
||||||
if (copy_to_iter(&vnet_hdr, sizeof(vnet_hdr), iter) !=
|
if (copy_to_iter(&vnet_hdr, sizeof(vnet_hdr), iter) !=
|
||||||
|
|
|
@ -1648,7 +1648,8 @@ static ssize_t tun_put_user(struct tun_struct *tun,
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (virtio_net_hdr_from_skb(skb, &gso,
|
if (virtio_net_hdr_from_skb(skb, &gso,
|
||||||
tun_is_little_endian(tun), true)) {
|
tun_is_little_endian(tun), true,
|
||||||
|
vlan_hlen)) {
|
||||||
struct skb_shared_info *sinfo = skb_shinfo(skb);
|
struct skb_shared_info *sinfo = skb_shinfo(skb);
|
||||||
pr_err("unexpected GSO type: "
|
pr_err("unexpected GSO type: "
|
||||||
"0x%x, gso_size %d, hdr_len %d\n",
|
"0x%x, gso_size %d, hdr_len %d\n",
|
||||||
|
|
|
@ -1237,7 +1237,8 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb)
|
||||||
hdr = skb_vnet_hdr(skb);
|
hdr = skb_vnet_hdr(skb);
|
||||||
|
|
||||||
if (virtio_net_hdr_from_skb(skb, &hdr->hdr,
|
if (virtio_net_hdr_from_skb(skb, &hdr->hdr,
|
||||||
virtio_is_little_endian(vi->vdev), false))
|
virtio_is_little_endian(vi->vdev), false,
|
||||||
|
0))
|
||||||
BUG();
|
BUG();
|
||||||
|
|
||||||
if (vi->mergeable_rx_bufs)
|
if (vi->mergeable_rx_bufs)
|
||||||
|
|
|
@ -58,7 +58,8 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb,
|
||||||
static inline int virtio_net_hdr_from_skb(const struct sk_buff *skb,
|
static inline int virtio_net_hdr_from_skb(const struct sk_buff *skb,
|
||||||
struct virtio_net_hdr *hdr,
|
struct virtio_net_hdr *hdr,
|
||||||
bool little_endian,
|
bool little_endian,
|
||||||
bool has_data_valid)
|
bool has_data_valid,
|
||||||
|
int vlan_hlen)
|
||||||
{
|
{
|
||||||
memset(hdr, 0, sizeof(*hdr)); /* no info leak */
|
memset(hdr, 0, sizeof(*hdr)); /* no info leak */
|
||||||
|
|
||||||
|
@ -83,12 +84,8 @@ static inline int virtio_net_hdr_from_skb(const struct sk_buff *skb,
|
||||||
|
|
||||||
if (skb->ip_summed == CHECKSUM_PARTIAL) {
|
if (skb->ip_summed == CHECKSUM_PARTIAL) {
|
||||||
hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
|
hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
|
||||||
if (skb_vlan_tag_present(skb))
|
hdr->csum_start = __cpu_to_virtio16(little_endian,
|
||||||
hdr->csum_start = __cpu_to_virtio16(little_endian,
|
skb_checksum_start_offset(skb) + vlan_hlen);
|
||||||
skb_checksum_start_offset(skb) + VLAN_HLEN);
|
|
||||||
else
|
|
||||||
hdr->csum_start = __cpu_to_virtio16(little_endian,
|
|
||||||
skb_checksum_start_offset(skb));
|
|
||||||
hdr->csum_offset = __cpu_to_virtio16(little_endian,
|
hdr->csum_offset = __cpu_to_virtio16(little_endian,
|
||||||
skb->csum_offset);
|
skb->csum_offset);
|
||||||
} else if (has_data_valid &&
|
} else if (has_data_valid &&
|
||||||
|
|
|
@ -2046,7 +2046,7 @@ static int packet_rcv_vnet(struct msghdr *msg, const struct sk_buff *skb,
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
*len -= sizeof(vnet_hdr);
|
*len -= sizeof(vnet_hdr);
|
||||||
|
|
||||||
if (virtio_net_hdr_from_skb(skb, &vnet_hdr, vio_le(), true))
|
if (virtio_net_hdr_from_skb(skb, &vnet_hdr, vio_le(), true, 0))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
return memcpy_to_msg(msg, (void *)&vnet_hdr, sizeof(vnet_hdr));
|
return memcpy_to_msg(msg, (void *)&vnet_hdr, sizeof(vnet_hdr));
|
||||||
|
@ -2313,7 +2313,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
|
||||||
if (do_vnet) {
|
if (do_vnet) {
|
||||||
if (virtio_net_hdr_from_skb(skb, h.raw + macoff -
|
if (virtio_net_hdr_from_skb(skb, h.raw + macoff -
|
||||||
sizeof(struct virtio_net_hdr),
|
sizeof(struct virtio_net_hdr),
|
||||||
vio_le(), true)) {
|
vio_le(), true, 0)) {
|
||||||
spin_lock(&sk->sk_receive_queue.lock);
|
spin_lock(&sk->sk_receive_queue.lock);
|
||||||
goto drop_n_account;
|
goto drop_n_account;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue