lkml.org 
[lkml]   [2011]   [May]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Date
    From
    Subject[PATCH 2/3] virtio_ring: check used_event offset
    Nothing's wrong with vring_size as is, but it's nice
    to check that the new field in the avail ring
    won't overlow into the used ring.

    Reported-by: Tom Lendacky <tahm@linux.vnet.ibm.com>
    Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
    ---
    include/linux/virtio_ring.h | 8 +++++++-
    1 files changed, 7 insertions(+), 1 deletions(-)

    diff --git a/include/linux/virtio_ring.h b/include/linux/virtio_ring.h
    index 2a3b0ea..089cbf2 100644
    --- a/include/linux/virtio_ring.h
    +++ b/include/linux/virtio_ring.h
    @@ -119,7 +119,13 @@ static inline void vring_init(struct vring *vr, unsigned int num, void *p,

    static inline unsigned vring_size(unsigned int num, unsigned long align)
    {
    - return ((sizeof(struct vring_desc) * num + sizeof(__u16) * (2 + num)
    +#ifdef __KERNEL__
    + /* Older versions did not have used_event field at the end of the
    + * avail ring. Used ring offset must be compatible with such devices. */
    + size_t s = sizeof(struct vring_desc) * num + sizeof(__u16) * (2 + num);
    + BUG_ON(ALIGN(s, align) != ALIGN(s + sizeof(__u16), align));
    +#endif
    + return ((sizeof(struct vring_desc) * num + sizeof(__u16) * (3 + num)
    + align - 1) & ~(align - 1))
    + sizeof(__u16) * 3 + sizeof(struct vring_used_elem) * num;
    }
    --
    1.7.5.53.gc233e


    \
     
     \ /
      Last update: 2011-05-05 17:13    [W:0.056 / U:30.264 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site