From: Yongji Xie <xieyongji@bytedance.com>
To: Jason Wang <jasowang@redhat.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
amit@kernel.org, arei.gonglei@huawei.com, airlied@linux.ie,
kraxel@redhat.com, dan.j.williams@intel.com,
Johannes Berg <johannes@sipsolutions.net>,
Ohad Ben Cohen <ohad@wizery.com>,
bjorn.andersson@linaro.org, David Hildenbrand <david@redhat.com>,
vgoyal@redhat.com, miklos@szeredi.hu,
Stefano Garzarella <sgarzare@redhat.com>,
virtualization <virtualization@lists.linux-foundation.org>,
linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: Re: [RFC PATCH 17/17] virtio_ring: Add validation for used length
Date: Tue, 25 May 2021 13:08:29 +0800 [thread overview]
Message-ID: <CACycT3vzpYRpFsBxCo+huG+wGE5TtD_N3A7wZf-yc_+cCfjzyw@mail.gmail.com> (raw)
In-Reply-To: <3cda643a-1363-65bf-be84-f6dea6714477@redhat.com>
On Tue, May 25, 2021 at 9:31 AM Jason Wang <jasowang@redhat.com> wrote:
>
>
> 在 2021/5/18 上午7:39, Michael S. Tsirkin 写道:
> > On Mon, May 17, 2021 at 05:08:36PM +0800, Xie Yongji wrote:
> >> This adds validation for used length (might come
> >> from an untrusted device) when it will be used by
> >> virtio device driver.
> >>
> >> Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
> >> ---
> >> drivers/virtio/virtio_ring.c | 22 +++++++++++++++++++---
> >> 1 file changed, 19 insertions(+), 3 deletions(-)
> >>
> >> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> >> index d999a1d6d271..7d4845d06f21 100644
> >> --- a/drivers/virtio/virtio_ring.c
> >> +++ b/drivers/virtio/virtio_ring.c
> >> @@ -68,11 +68,13 @@
> >> struct vring_desc_state_split {
> >> void *data; /* Data for callback. */
> >> struct vring_desc *indir_desc; /* Indirect descriptor, if any. */
> >> + u32 in_len; /* Total length of writable buffer */
> >> };
> >>
> >> struct vring_desc_state_packed {
> >> void *data; /* Data for callback. */
> >> struct vring_packed_desc *indir_desc; /* Indirect descriptor, if any. */
> >> + u32 in_len; /* Total length of writable buffer */
> >> u16 num; /* Descriptor list length. */
> >> u16 last; /* The last desc state in a list. */
> >> };
> >
> > Hmm for packed it's aligned to 64 bit anyway, so we are not making it
> > any worse. But for split this pushes struct size up by 1/3 increasing
> > cache pressure.
>
>
> We can eliminate this by validating through virtio device driver instead
> of virtio core.
>
> E.g for virtio-net we know the rx buffer size so there's no need to
> store in twice in the core.
>
I see. I have sent the new fix just now.
Thanks,
Yongji
next prev parent reply other threads:[~2021-05-25 5:08 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-17 9:08 [RFC PATCH 00/17] Add validation for used length Xie Yongji
2021-05-17 9:08 ` [RFC PATCH 01/17] virtio_ring: Avoid reading unneeded " Xie Yongji
2021-05-17 9:11 ` Johannes Berg
2021-05-17 9:41 ` Yongji Xie
2021-05-17 9:08 ` [RFC PATCH 02/17] virtio-blk: Remove unused " Xie Yongji
2021-05-17 9:08 ` [RFC PATCH 03/17] virtio_console: " Xie Yongji
2021-05-17 9:08 ` [RFC PATCH 04/17] crypto: virtio - " Xie Yongji
2021-05-17 9:08 ` [RFC PATCH 05/17] drm/virtio: " Xie Yongji
2021-05-17 9:08 ` [RFC PATCH 06/17] caif_virtio: " Xie Yongji
2021-05-17 9:08 ` [RFC PATCH 07/17] virtio_net: " Xie Yongji
2021-05-17 9:08 ` [RFC PATCH 08/17] mac80211_hwsim: " Xie Yongji
2021-05-17 9:08 ` [RFC PATCH 09/17] virtio_pmem: " Xie Yongji
2021-05-17 9:08 ` [RFC PATCH 10/17] rpmsg: virtio: " Xie Yongji
2021-05-17 9:08 ` [RFC PATCH 11/17] virtio_scsi: " Xie Yongji
2021-05-17 9:08 ` [RFC PATCH 12/17] virtio_balloon: " Xie Yongji
2021-05-17 9:08 ` [RFC PATCH 13/17] virtio_input: " Xie Yongji
2021-05-17 9:08 ` [RFC PATCH 14/17] virtio_mem: " Xie Yongji
2021-05-17 9:08 ` [RFC PATCH 15/17] virtiofs: " Xie Yongji
2021-05-17 9:08 ` [RFC PATCH 16/17] vsock: " Xie Yongji
2021-05-17 9:08 ` [RFC PATCH 17/17] virtio_ring: Add validation for " Xie Yongji
2021-05-17 23:39 ` Michael S. Tsirkin
2021-05-25 1:31 ` Jason Wang
2021-05-25 5:08 ` Yongji Xie [this message]
2021-05-17 23:40 ` [RFC PATCH 00/17] " Michael S. Tsirkin
2021-05-18 8:29 ` Yongji Xie
2021-05-18 9:52 ` Michael S. Tsirkin
2021-05-18 12:28 ` 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=CACycT3vzpYRpFsBxCo+huG+wGE5TtD_N3A7wZf-yc_+cCfjzyw@mail.gmail.com \
--to=xieyongji@bytedance.com \
--cc=airlied@linux.ie \
--cc=amit@kernel.org \
--cc=arei.gonglei@huawei.com \
--cc=bjorn.andersson@linaro.org \
--cc=dan.j.williams@intel.com \
--cc=david@redhat.com \
--cc=jasowang@redhat.com \
--cc=johannes@sipsolutions.net \
--cc=kraxel@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=mst@redhat.com \
--cc=ohad@wizery.com \
--cc=sgarzare@redhat.com \
--cc=stefanha@redhat.com \
--cc=vgoyal@redhat.com \
--cc=virtualization@lists.linux-foundation.org \
/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;
as well as URLs for NNTP newsgroup(s).