Blame SOURCES/kvm-vmdk-Fix-integer-overflow-in-offset-calculation.patch

958e1b
From ed2a49b247a70b0e841296f5a63285390b842e06 Mon Sep 17 00:00:00 2001
958e1b
Message-Id: <ed2a49b247a70b0e841296f5a63285390b842e06.1418766606.git.jen@redhat.com>
958e1b
In-Reply-To: <6f81b4847eb68ebdf54a8f1a771e19d112d74152.1418766606.git.jen@redhat.com>
958e1b
References: <6f81b4847eb68ebdf54a8f1a771e19d112d74152.1418766606.git.jen@redhat.com>
958e1b
From: Fam Zheng <famz@redhat.com>
958e1b
Date: Thu, 4 Dec 2014 00:05:24 -0600
958e1b
Subject: [CHANGE 30/31] vmdk: Fix integer overflow in offset calculation
958e1b
To: rhvirt-patches@redhat.com,
958e1b
    jen@redhat.com
958e1b
958e1b
RH-Author: Fam Zheng <famz@redhat.com>
958e1b
Message-id: <1417651524-18041-31-git-send-email-famz@redhat.com>
958e1b
Patchwork-id: 62703
958e1b
O-Subject: [RHEL-7.1 qemu-kvm PATCH v5 30/30] vmdk: Fix integer overflow in offset calculation
958e1b
Bugzilla: 1002493
958e1b
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
958e1b
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
958e1b
RH-Acked-by: Max Reitz <mreitz@redhat.com>
958e1b
958e1b
This fixes the bug introduced by commit c6ac36e (vmdk: Optimize cluster
958e1b
allocation).
958e1b
958e1b
$ ~/build/master/qemu-io /stor/vm/arch.vmdk -c 'write 2G 1k'
958e1b
write failed: Invalid argument
958e1b
958e1b
Reported-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
958e1b
Reviewed-by: Max Reitz <mreitz@redhat.com>
958e1b
Signed-off-by: Fam Zheng <famz@redhat.com>
958e1b
Message-id: 1411437381-11234-1-git-send-email-famz@redhat.com
958e1b
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
958e1b
(cherry picked from commit d1319b077a4bd980ca1b8a167b02b519330dd26b)
958e1b
Signed-off-by: Fam Zheng <famz@redhat.com>
958e1b
Signed-off-by: Jeff E. Nelson <jen@redhat.com>
958e1b
958e1b
Conflicts:
958e1b
	tests/qemu-iotests/group
958e1b
958e1b
Signed-off-by: Jeff E. Nelson <jen@redhat.com>
958e1b
---
958e1b
 block/vmdk.c               |  2 +-
958e1b
 tests/qemu-iotests/105     | 70 ++++++++++++++++++++++++++++++++++++++++++++++
958e1b
 tests/qemu-iotests/105.out | 21 ++++++++++++++
958e1b
 tests/qemu-iotests/group   |  1 +
958e1b
 4 files changed, 93 insertions(+), 1 deletion(-)
958e1b
 create mode 100755 tests/qemu-iotests/105
958e1b
 create mode 100644 tests/qemu-iotests/105.out
958e1b
958e1b
diff --git a/block/vmdk.c b/block/vmdk.c
958e1b
index 0593a1a..cfcaa84 100644
958e1b
--- a/block/vmdk.c
958e1b
+++ b/block/vmdk.c
958e1b
@@ -1116,7 +1116,7 @@ static int get_cluster_offset(BlockDriverState *bs,
958e1b
     uint32_t min_count, *l2_table;
958e1b
     bool zeroed = false;
958e1b
     int64_t ret;
958e1b
-    int32_t cluster_sector;
958e1b
+    int64_t cluster_sector;
958e1b
 
958e1b
     if (m_data) {
958e1b
         m_data->valid = 0;
958e1b
diff --git a/tests/qemu-iotests/105 b/tests/qemu-iotests/105
958e1b
new file mode 100755
958e1b
index 0000000..9bae49e
958e1b
--- /dev/null
958e1b
+++ b/tests/qemu-iotests/105
958e1b
@@ -0,0 +1,70 @@
958e1b
+#!/bin/bash
958e1b
+#
958e1b
+# Create, read, write big image
958e1b
+#
958e1b
+# Copyright (C) 2014 Red Hat, Inc.
958e1b
+#
958e1b
+# This program is free software; you can redistribute it and/or modify
958e1b
+# it under the terms of the GNU General Public License as published by
958e1b
+# the Free Software Foundation; either version 2 of the License, or
958e1b
+# (at your option) any later version.
958e1b
+#
958e1b
+# This program is distributed in the hope that it will be useful,
958e1b
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
958e1b
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
958e1b
+# GNU General Public License for more details.
958e1b
+#
958e1b
+# You should have received a copy of the GNU General Public License
958e1b
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
958e1b
+#
958e1b
+
958e1b
+# creator
958e1b
+owner=famz@redhat.com
958e1b
+
958e1b
+seq=`basename $0`
958e1b
+echo "QA output created by $seq"
958e1b
+
958e1b
+here=`pwd`
958e1b
+tmp=/tmp/$$
958e1b
+status=1	# failure is the default!
958e1b
+
958e1b
+_cleanup()
958e1b
+{
958e1b
+	_cleanup_test_img
958e1b
+}
958e1b
+trap "_cleanup; exit \$status" 0 1 2 3 15
958e1b
+
958e1b
+# get standard environment, filters and checks
958e1b
+. ./common.rc
958e1b
+. ./common.filter
958e1b
+
958e1b
+_supported_fmt qcow2 vmdk vhdx qed
958e1b
+_supported_proto generic
958e1b
+_supported_os Linux
958e1b
+_unsupported_imgopts "subformat=twoGbMaxExtentFlat" \
958e1b
+                     "subformat=twoGbMaxExtentSparse"
958e1b
+
958e1b
+echo
958e1b
+echo "creating large image"
958e1b
+_make_test_img 16T
958e1b
+
958e1b
+echo
958e1b
+echo "small read"
958e1b
+$QEMU_IO -c "read 1024 4096" "$TEST_IMG" | _filter_qemu_io
958e1b
+
958e1b
+echo
958e1b
+echo "small write"
958e1b
+$QEMU_IO -c "write 8192 4096" "$TEST_IMG" | _filter_qemu_io
958e1b
+
958e1b
+echo
958e1b
+echo "small read at high offset"
958e1b
+$QEMU_IO -c "read 14T 4096" "$TEST_IMG" | _filter_qemu_io
958e1b
+
958e1b
+echo
958e1b
+echo "small write at high offset"
958e1b
+$QEMU_IO -c "write 14T 4096" "$TEST_IMG" | _filter_qemu_io
958e1b
+
958e1b
+# success, all done
958e1b
+echo "*** done"
958e1b
+rm -f $seq.full
958e1b
+status=0
958e1b
diff --git a/tests/qemu-iotests/105.out b/tests/qemu-iotests/105.out
958e1b
new file mode 100644
958e1b
index 0000000..13ffcb5
958e1b
--- /dev/null
958e1b
+++ b/tests/qemu-iotests/105.out
958e1b
@@ -0,0 +1,21 @@
958e1b
+QA output created by 105
958e1b
+
958e1b
+creating large image
958e1b
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=17592186044416
958e1b
+
958e1b
+small read
958e1b
+read 4096/4096 bytes at offset 1024
958e1b
+4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
958e1b
+
958e1b
+small write
958e1b
+wrote 4096/4096 bytes at offset 8192
958e1b
+4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
958e1b
+
958e1b
+small read at high offset
958e1b
+read 4096/4096 bytes at offset 15393162788864
958e1b
+4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
958e1b
+
958e1b
+small write at high offset
958e1b
+wrote 4096/4096 bytes at offset 15393162788864
958e1b
+4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
958e1b
+*** done
958e1b
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
958e1b
index 572438e..cd8384a 100644
958e1b
--- a/tests/qemu-iotests/group
958e1b
+++ b/tests/qemu-iotests/group
958e1b
@@ -85,3 +85,4 @@
958e1b
 087 rw auto quick
958e1b
 088 rw auto
958e1b
 092 rw auto quick
958e1b
+105 rw auto quick
958e1b
-- 
958e1b
2.1.0
958e1b