mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: Yongji Xie <xieyongji@bytedance.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	Jakub Kicinski <kuba@kernel.org>,
	virtualization <virtualization@lists.linux-foundation.org>,
	netdev@vger.kernel.org,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3] virtio-net: Add validation for used length
Date: Mon, 31 May 2021 15:51:18 +0800	[thread overview]
Message-ID: <4ff90e78-0c7a-def6-ef84-367bcce4cea5@redhat.com> (raw)
In-Reply-To: <CACycT3uo-J3MYdEo0TscENewp3Xnjce8yFLtt6JkK8uZrvsMjg@mail.gmail.com>


在 2021/5/31 下午3:19, Yongji Xie 写道:
> On Mon, May 31, 2021 at 2:49 PM Jason Wang <jasowang@redhat.com> wrote:
>>
>> 在 2021/5/28 下午8:11, Xie Yongji 写道:
>>> This adds validation for used length (might come
>>> from an untrusted device) to avoid data corruption
>>> or loss.
>>>
>>> Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
>>> ---
>>>    drivers/net/virtio_net.c | 28 +++++++++++++++++++++-------
>>>    1 file changed, 21 insertions(+), 7 deletions(-)
>>>
>>> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
>>> index 073fec4c0df1..01f15b65824c 100644
>>> --- a/drivers/net/virtio_net.c
>>> +++ b/drivers/net/virtio_net.c
>>> @@ -732,6 +732,17 @@ static struct sk_buff *receive_small(struct net_device *dev,
>>>
>>>        rcu_read_lock();
>>>        xdp_prog = rcu_dereference(rq->xdp_prog);
>>> +     if (unlikely(len > GOOD_PACKET_LEN)) {
>>> +             pr_debug("%s: rx error: len %u exceeds max size %d\n",
>>> +                      dev->name, len, GOOD_PACKET_LEN);
>>> +             dev->stats.rx_length_errors++;
>>> +             if (xdp_prog)
>>> +                     goto err_xdp;
>>> +
>>> +             rcu_read_unlock();
>>> +             put_page(page);
>>> +             return NULL;
>>> +     }
>>>        if (xdp_prog) {
>>>                struct virtio_net_hdr_mrg_rxbuf *hdr = buf + header_offset;
>>>                struct xdp_frame *xdpf;
>>> @@ -888,6 +899,16 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
>>>
>>>        rcu_read_lock();
>>>        xdp_prog = rcu_dereference(rq->xdp_prog);
>>> +     if (unlikely(len > truesize)) {
>>> +             pr_debug("%s: rx error: len %u exceeds truesize %lu\n",
>>> +                      dev->name, len, (unsigned long)ctx);
>>> +             dev->stats.rx_length_errors++;
>>> +             if (xdp_prog)
>>> +                     goto err_xdp;
>>> +
>>> +             rcu_read_unlock();
>>> +             goto err_skb;
>>> +     }
>>
>> Patch looks correct but I'd rather not bother XDP here. It would be
>> better if we just do the check before rcu_read_lock() and use err_skb
>> directly() to avoid RCU/XDP stuffs.
>>
> If so, we will miss the statistics of xdp_drops. Is it OK?


It should be ok, we still had drops and it was dropped before dealing 
with XDP.

The motivation is to have simple codes.

Thanks


>
> Thanks,
> Yongji
>


  reply	other threads:[~2021-05-31  7:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-28 12:11 Xie Yongji
2021-05-31  6:49 ` Jason Wang
2021-05-31  7:19   ` Yongji Xie
2021-05-31  7:51     ` Jason Wang [this message]
2021-05-31  8:23       ` Yongji Xie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4ff90e78-0c7a-def6-ef84-367bcce4cea5@redhat.com \
    --to=jasowang@redhat.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=xieyongji@bytedance.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®