Re: Re: [RFC PATCH 17/17] virtio_ring: Add validation for used length

From: Yongji Xie
Date: Tue May 25 2021 - 01:08:49 EST


On Tue, May 25, 2021 at 9:31 AM Jason Wang <jasowang@xxxxxxxxxx> 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@xxxxxxxxxxxxx>
> >> ---
> >> 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