lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <CANn89i+Sh3UXyfVb+X2AuXL6swX-8mrK++yn7y11EUnWRSd5HA@mail.gmail.com>
Date:   Thu, 1 Apr 2021 07:06:14 +0200
From:   Eric Dumazet <edumazet@...gle.com>
To:     Xuan Zhuo <xuanzhuo@...ux.alibaba.com>
Cc:     Eric Dumazet <eric.dumazet@...il.com>,
        netdev <netdev@...r.kernel.org>,
        Alexander Duyck <alexanderduyck@...com>,
        Paolo Abeni <pabeni@...hat.com>,
        Greg Thelen <gthelen@...gle.com>,
        "David S . Miller" <davem@...emloft.net>,
        Jakub Kicinski <kuba@...nel.org>, su-lifan@...ux.alibaba.com,
        "dust.li" <dust.li@...ux.alibaba.com>,
        Jason Wang <jasowang@...hat.com>,
        "Michael S. Tsirkin" <mst@...hat.com>
Subject: Re: [PATCH net] net: avoid 32 x truesize under-estimation for tiny skbs

On Thu, Apr 1, 2021 at 5:40 AM Xuan Zhuo <xuanzhuo@...ux.alibaba.com> wrote:

>
> [  144.405067] eth1: bad gso: type: 1, size: 1452
> [  180.473565] skbuff: bad partial csum: csum=34/16 headroom=64 headlen=14
> [  180.474698] eth1: bad gso: type: 1, size: 1452
> [  180.519980] skbuff: bad partial csum: csum=34/16 headroom=64 headlen=14
> [  180.521076] eth1: bad gso: type: 1, size: 1452
> [  180.559409] skbuff: bad partial csum: csum=34/16 headroom=64 headlen=14
> [  180.560501] eth1: bad gso: type: 1, size: 1452
> [  180.576476] skbuff: bad partial csum: csum=34/16 headroom=64 headlen=14
> [  180.577562] eth1: bad gso: type: 1, size: 1452
> [  183.284265] skbuff: bad partial csum: csum=34/16 headroom=64 headlen=14
> [  183.285372] eth1: bad gso: type: 1, size: 1452
> [  216.831138] net_ratelimit: 2 callbacks suppressed
> [  216.832009] skbuff: bad partial csum: csum=34/16 headroom=64 headlen=14
> [  216.833103] eth1: bad gso: type: 1, size: 1452
> [  216.892180] skbuff: bad partial csum: csum=34/16 headroom=64 headlen=14
> [  216.893280] eth1: bad gso: type: 1, size: 1452
> [  216.949833] skbuff: bad partial csum: csum=34/16 headroom=64 headlen=14
> [  216.950922] eth1: bad gso: type: 1, size: 1452
> [  291.962999] skbuff: bad partial csum: csum=34/6 headroom=64 headlen=14
> [  291.964092] eth1: bad gso: type: 0, size: 0
> [  311.972597] skbuff: bad partial csum: csum=34/6 headroom=64 headlen=14
> [  311.973691] eth1: bad gso: type: 0, size: 0
>
> I got this display after the machine started, I think just copy eth may not be a
> good way.

This is great, thanks for testing.
This means virtio_net_hdr_to_skb() needs to be a little bit smarter to
pull needed bytes (not assuming 128 bytes were pre-pulled)

Can you try this ?
Thanks !

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index bb4ea9dbc16bcb19c5969fc8247478aa66c63fce..f5a3cecd18eada32694714ecb85c205af7108aae
100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -409,9 +409,13 @@ static struct sk_buff *page_to_skb(struct virtnet_info *vi,
        offset += hdr_padded_len;
        p += hdr_padded_len;

-       copy = len;
-       if (copy > skb_tailroom(skb))
-               copy = skb_tailroom(skb);
+       /* Copy all frame if it fits skb->head,
+        * otherwise we let GRO pull headers as needed.
+        */
+       if (len <= skb_tailroom(skb))
+               copy = len;
+       else
+               copy = min_t(int, len, ETH_HLEN + metasize);
        skb_put_data(skb, p, copy);

        if (metasize) {
diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
index 6b5fcfa1e5553576b0e853ae31a2df655c04204b..2ee8f3ba76a548d54e0b21321a67da958c9984a0
100644
--- a/include/linux/virtio_net.h
+++ b/include/linux/virtio_net.h
@@ -63,8 +63,12 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb,
        }

        if (hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
-               u16 start = __virtio16_to_cpu(little_endian, hdr->csum_start);
-               u16 off = __virtio16_to_cpu(little_endian, hdr->csum_offset);
+               u32 start = __virtio16_to_cpu(little_endian, hdr->csum_start);
+               u32 off = __virtio16_to_cpu(little_endian, hdr->csum_offset);
+               u32 needed = start + max_t(u32, thlen, off + sizeof(__sum16));
+
+               if (pskb_may_pull(skb, needed))
+                       return -EINVAL;

                if (!skb_partial_csum_set(skb, start, off))
                        return -EINVAL;
@@ -100,14 +104,14 @@ static inline int virtio_net_hdr_to_skb(struct
sk_buff *skb,
                        }

                        p_off = keys.control.thoff + thlen;
-                       if (p_off > skb_headlen(skb) ||
+                       if (pskb_may_pull(skb, p_off) ||
                            keys.basic.ip_proto != ip_proto)
                                return -EINVAL;

                        skb_set_transport_header(skb, keys.control.thoff);
                } else if (gso_type) {
                        p_off = thlen;
-                       if (p_off > skb_headlen(skb))
+                       if (pskb_may_pull(skb, p_off))
                                return -EINVAL;
                }
        }

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ