Skip to content
  • Stefan Hajnoczi's avatar
    7bd04a04
    virtio-blk: undo destructive iov_discard_*() operations · 7bd04a04
    Stefan Hajnoczi authored
    
    
    Fuzzing discovered that virtqueue_unmap_sg() is being called on modified
    req->in/out_sg iovecs. This means dma_memory_map() and
    dma_memory_unmap() calls do not have matching memory addresses.
    
    Fuzzing discovered that non-RAM addresses trigger a bug:
    
      void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len,
                               bool is_write, hwaddr access_len)
      {
          if (buffer != bounce.buffer) {
              ^^^^^^^^^^^^^^^^^^^^^^^
    
    A modified iov->iov_base is no longer recognized as a bounce buffer and
    the wrong branch is taken.
    
    There are more potential bugs: dirty memory is not tracked correctly and
    MemoryRegion refcounts can be leaked.
    
    Use the new iov_discard_undo() API to restore elem->in/out_sg before
    virtqueue_push() is called.
    
    Fixes: 827805a2 ("virtio-blk: Convert VirtIOBlockReq.out to structrue")
    Reported-by: default avatarAlexander Bulekov <alxndr@bu.edu>
    Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
    Reviewed-by: default avatarLi Qiang <liq3ea@gmail.com>
    Buglink: https://bugs.launchpad.net/qemu/+bug/1890360
    Message-Id: <20200917094455.822379-3-stefanha@redhat.com>
    7bd04a04
    virtio-blk: undo destructive iov_discard_*() operations
    Stefan Hajnoczi authored
    
    
    Fuzzing discovered that virtqueue_unmap_sg() is being called on modified
    req->in/out_sg iovecs. This means dma_memory_map() and
    dma_memory_unmap() calls do not have matching memory addresses.
    
    Fuzzing discovered that non-RAM addresses trigger a bug:
    
      void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len,
                               bool is_write, hwaddr access_len)
      {
          if (buffer != bounce.buffer) {
              ^^^^^^^^^^^^^^^^^^^^^^^
    
    A modified iov->iov_base is no longer recognized as a bounce buffer and
    the wrong branch is taken.
    
    There are more potential bugs: dirty memory is not tracked correctly and
    MemoryRegion refcounts can be leaked.
    
    Use the new iov_discard_undo() API to restore elem->in/out_sg before
    virtqueue_push() is called.
    
    Fixes: 827805a2 ("virtio-blk: Convert VirtIOBlockReq.out to structrue")
    Reported-by: default avatarAlexander Bulekov <alxndr@bu.edu>
    Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
    Reviewed-by: default avatarLi Qiang <liq3ea@gmail.com>
    Buglink: https://bugs.launchpad.net/qemu/+bug/1890360
    Message-Id: <20200917094455.822379-3-stefanha@redhat.com>
Loading