From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38575) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X6efi-0004ge-2s for qemu-devel@nongnu.org; Mon, 14 Jul 2014 07:44:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X6efa-0005Nz-1y for qemu-devel@nongnu.org; Mon, 14 Jul 2014 07:43:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42950) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X6efZ-0005Ng-Qn for qemu-devel@nongnu.org; Mon, 14 Jul 2014 07:43:45 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s6EBhjok018981 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 14 Jul 2014 07:43:45 -0400 From: Kevin Wolf Date: Mon, 14 Jul 2014 13:43:11 +0200 Message-Id: <1405338192-18850-22-git-send-email-kwolf@redhat.com> In-Reply-To: <1405338192-18850-1-git-send-email-kwolf@redhat.com> References: <1405338192-18850-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PULL v2 for-2.1 21/22] virtio-blk: Treat read/write beyond end as invalid List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com From: Markus Armbruster The block layer fails such reads and writes just fine. However, they then get treated like valid operations that fail: the error action gets executed. Unwanted; reporting the error to the guest is the only sensible action. Reject them before passing them to the block layer. This bypasses the error action and I/O accounting. Signed-off-by: Markus Armbruster Reviewed-by: Fam Zheng Signed-off-by: Kevin Wolf --- hw/block/virtio-blk.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index e6e6276..c241c50 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -291,12 +291,19 @@ static void virtio_blk_handle_flush(VirtIOBlockReq *req, MultiReqBuffer *mrb) static bool virtio_blk_sect_range_ok(VirtIOBlock *dev, uint64_t sector, size_t size) { + uint64_t nb_sectors = size >> BDRV_SECTOR_BITS; + uint64_t total_sectors; + if (sector & dev->sector_mask) { return false; } if (size % dev->conf->logical_block_size) { return false; } + bdrv_get_geometry(dev->bs, &total_sectors); + if (sector > total_sectors || nb_sectors > total_sectors - sector) { + return false; + } return true; } -- 1.8.3.1