thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-virtio-blk-Treat-read-write-beyond-end-as-invalid.patch

9ae3a8
From 55767ddb818ef53eee50777bd276cbf7e7813bfb Mon Sep 17 00:00:00 2001
9ae3a8
From: Markus Armbruster <armbru@redhat.com>
9ae3a8
Date: Fri, 31 Oct 2014 16:29:54 +0100
9ae3a8
Subject: [PATCH 17/19] virtio-blk: Treat read/write beyond end as invalid
9ae3a8
9ae3a8
Message-id: <1414772996-17272-4-git-send-email-armbru@redhat.com>
9ae3a8
Patchwork-id: 62019
9ae3a8
O-Subject: [PATCH RHEL-7.1 qemu-kvm 3/5] virtio-blk: Treat read/write beyond end as invalid
9ae3a8
Bugzilla: 1085232
9ae3a8
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
RH-Acked-by: Fam Zheng <famz@redhat.com>
9ae3a8
9ae3a8
The block layer fails such reads and writes just fine.  However, they
9ae3a8
then get treated like valid operations that fail: the error action
9ae3a8
gets executed.  Unwanted; reporting the error to the guest is the only
9ae3a8
sensible action.
9ae3a8
9ae3a8
Reject them before passing them to the block layer.  This bypasses the
9ae3a8
error action and I/O accounting.
9ae3a8
9ae3a8
Signed-off-by: Markus Armbruster <armbru@redhat.com>
9ae3a8
Reviewed-by: Fam Zheng <famz@redhat.com>
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
(cherry picked from commit 3c2daac0b98952a858277878cb11294256b39e43)
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 hw/block/virtio-blk.c | 7 +++++++
9ae3a8
 1 file changed, 7 insertions(+)
9ae3a8
9ae3a8
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
9ae3a8
index ffb311c..4f6aa22 100644
9ae3a8
--- a/hw/block/virtio-blk.c
9ae3a8
+++ b/hw/block/virtio-blk.c
9ae3a8
@@ -284,12 +284,19 @@ static void virtio_blk_handle_flush(VirtIOBlockReq *req, MultiReqBuffer *mrb)
9ae3a8
 static bool virtio_blk_sect_range_ok(VirtIOBlock *dev,
9ae3a8
                                      uint64_t sector, size_t size)
9ae3a8
 {
9ae3a8
+    uint64_t nb_sectors = size >> BDRV_SECTOR_BITS;
9ae3a8
+    uint64_t total_sectors;
9ae3a8
+
9ae3a8
     if (sector & dev->sector_mask) {
9ae3a8
         return false;
9ae3a8
     }
9ae3a8
     if (size % dev->conf->logical_block_size) {
9ae3a8
         return false;
9ae3a8
     }
9ae3a8
+    bdrv_get_geometry(dev->bs, &total_sectors);
9ae3a8
+    if (sector > total_sectors || nb_sectors > total_sectors - sector) {
9ae3a8
+        return false;
9ae3a8
+    }
9ae3a8
     return true;
9ae3a8
 }
9ae3a8
 
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8