Commit 958a1e55 authored by Willem de Bruijn's avatar Willem de Bruijn Committed by Kamal Mostafa

macvtap: always pass ethernet header in linear

[ Upstream commit 8e2ad411 ]

The stack expects link layer headers in the skb linear section.
Macvtap can create skbs with llheader in frags in edge cases:
when (IFF_VNET_HDR is off or vnet_hdr.hdr_len < ETH_HLEN) and
prepad + len > PAGE_SIZE and vnet_hdr.flags has no or bad csum.

Add checks to ensure linear is always at least ETH_HLEN.
At this point, len is already ensured to be >= ETH_HLEN.

For backwards compatiblity, rounds up short vnet_hdr.hdr_len.
This differs from tap and packet, which return an error.

Fixes b9fb9ee0 ("macvtap: add GSO/csum offload support")
Signed-off-by: default avatarWillem de Bruijn <willemb@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarKamal Mostafa <kamal@canonical.com>
parent f6cb92d7
...@@ -710,6 +710,8 @@ static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m, ...@@ -710,6 +710,8 @@ static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m,
macvtap16_to_cpu(q, vnet_hdr.hdr_len) : GOODCOPY_LEN; macvtap16_to_cpu(q, vnet_hdr.hdr_len) : GOODCOPY_LEN;
if (copylen > good_linear) if (copylen > good_linear)
copylen = good_linear; copylen = good_linear;
else if (copylen < ETH_HLEN)
copylen = ETH_HLEN;
linear = copylen; linear = copylen;
i = *from; i = *from;
iov_iter_advance(&i, copylen); iov_iter_advance(&i, copylen);
...@@ -719,10 +721,11 @@ static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m, ...@@ -719,10 +721,11 @@ static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m,
if (!zerocopy) { if (!zerocopy) {
copylen = len; copylen = len;
if (macvtap16_to_cpu(q, vnet_hdr.hdr_len) > good_linear) linear = macvtap16_to_cpu(q, vnet_hdr.hdr_len);
if (linear > good_linear)
linear = good_linear; linear = good_linear;
else else if (linear < ETH_HLEN)
linear = macvtap16_to_cpu(q, vnet_hdr.hdr_len); linear = ETH_HLEN;
} }
skb = macvtap_alloc_skb(&q->sk, MACVTAP_RESERVE, copylen, skb = macvtap_alloc_skb(&q->sk, MACVTAP_RESERVE, copylen,
......
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