From: Peter Lieven Date: Mon, 16 Jan 2017 15:17:12 +0000 (+0100) Subject: block/iscsi: avoid data corruption with cache=writeback X-Git-Tag: v2.8.1~54 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3fb4b3c371a9c080e7f53d22e6a2202d9982a7c4;p=thirdparty%2Fqemu.git block/iscsi: avoid data corruption with cache=writeback nb_cls_shrunk in iscsi_allocmap_update can become -1 if the request starts and ends within the same cluster. This results in passing -1 to bitmap_set and bitmap_clear and they don't handle negative values properly. In the end this leads to data corruption. Fixes: e1123a3b40a1a9a625a29c8ed4debb7e206ea690 Cc: qemu-stable@nongnu.org Signed-off-by: Peter Lieven Message-Id: <1484579832-18589-1-git-send-email-pl@kamp.de> Reviewed-by: Fam Zheng Signed-off-by: Paolo Bonzini (cherry picked from commit 1da45e0c4cf4719fa75898d019e0874b9b2bc774) Signed-off-by: Michael Roth --- diff --git a/block/iscsi.c b/block/iscsi.c index 0960929d576..a1ac8d93481 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -498,14 +498,18 @@ iscsi_allocmap_update(IscsiLun *iscsilun, int64_t sector_num, if (allocated) { bitmap_set(iscsilun->allocmap, cl_num_expanded, nb_cls_expanded); } else { - bitmap_clear(iscsilun->allocmap, cl_num_shrunk, nb_cls_shrunk); + if (nb_cls_shrunk > 0) { + bitmap_clear(iscsilun->allocmap, cl_num_shrunk, nb_cls_shrunk); + } } if (iscsilun->allocmap_valid == NULL) { return; } if (valid) { - bitmap_set(iscsilun->allocmap_valid, cl_num_shrunk, nb_cls_shrunk); + if (nb_cls_shrunk > 0) { + bitmap_set(iscsilun->allocmap_valid, cl_num_shrunk, nb_cls_shrunk); + } } else { bitmap_clear(iscsilun->allocmap_valid, cl_num_expanded, nb_cls_expanded);