Blame SOURCES/kvm-block-Fix-parameter-checking-in-bdrv_co_copy_range_i.patch

ae23c9
From 521c003737f893ff4a6c6e95b0d1555d28a86252 Mon Sep 17 00:00:00 2001
ae23c9
From: John Snow <jsnow@redhat.com>
ae23c9
Date: Tue, 24 Jul 2018 12:50:06 +0200
ae23c9
Subject: [PATCH 232/268] block: Fix parameter checking in
ae23c9
 bdrv_co_copy_range_internal
ae23c9
ae23c9
RH-Author: John Snow <jsnow@redhat.com>
ae23c9
Message-id: <20180718225511.14878-15-jsnow@redhat.com>
ae23c9
Patchwork-id: 81411
ae23c9
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 14/35] block: Fix parameter checking in bdrv_co_copy_range_internal
ae23c9
Bugzilla: 1207657
ae23c9
RH-Acked-by: Eric Blake <eblake@redhat.com>
ae23c9
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
ae23c9
RH-Acked-by: Fam Zheng <famz@redhat.com>
ae23c9
ae23c9
From: Fam Zheng <famz@redhat.com>
ae23c9
ae23c9
src may be NULL if BDRV_REQ_ZERO_WRITE flag is set, in this case only
ae23c9
check dst and dst->bs. This bug was introduced when moving in the
ae23c9
request tracking code from bdrv_co_copy_range, in 37aec7d75eb.
ae23c9
ae23c9
This especially fixes the possible segfault when initializing src_bs
ae23c9
with a NULL src.
ae23c9
ae23c9
Signed-off-by: Fam Zheng <famz@redhat.com>
ae23c9
Message-id: 20180703023758.14422-2-famz@redhat.com
ae23c9
Reviewed-by: Jeff Cody <jcody@redhat.com>
ae23c9
Signed-off-by: Jeff Cody <jcody@redhat.com>
ae23c9
(cherry picked from commit d4d3e5a0d53a57282955e8a3ed7acc1ca90552d9)
ae23c9
Signed-off-by: John Snow <jsnow@redhat.com>
ae23c9
---
ae23c9
 block/io.c | 28 +++++++++++++++-------------
ae23c9
 1 file changed, 15 insertions(+), 13 deletions(-)
ae23c9
ae23c9
diff --git a/block/io.c b/block/io.c
ae23c9
index 136a5d0..7981239 100644
ae23c9
--- a/block/io.c
ae23c9
+++ b/block/io.c
ae23c9
@@ -2848,17 +2848,11 @@ static int coroutine_fn bdrv_co_copy_range_internal(BdrvChild *src,
ae23c9
                                                     bool recurse_src)
ae23c9
 {
ae23c9
     BdrvTrackedRequest src_req, dst_req;
ae23c9
-    BlockDriverState *src_bs = src->bs;
ae23c9
-    BlockDriverState *dst_bs = dst->bs;
ae23c9
     int ret;
ae23c9
 
ae23c9
-    if (!src || !dst || !src->bs || !dst->bs) {
ae23c9
+    if (!dst || !dst->bs) {
ae23c9
         return -ENOMEDIUM;
ae23c9
     }
ae23c9
-    ret = bdrv_check_byte_request(src->bs, src_offset, bytes);
ae23c9
-    if (ret) {
ae23c9
-        return ret;
ae23c9
-    }
ae23c9
 
ae23c9
     ret = bdrv_check_byte_request(dst->bs, dst_offset, bytes);
ae23c9
     if (ret) {
ae23c9
@@ -2868,17 +2862,25 @@ static int coroutine_fn bdrv_co_copy_range_internal(BdrvChild *src,
ae23c9
         return bdrv_co_pwrite_zeroes(dst, dst_offset, bytes, flags);
ae23c9
     }
ae23c9
 
ae23c9
+    if (!src || !src->bs) {
ae23c9
+        return -ENOMEDIUM;
ae23c9
+    }
ae23c9
+    ret = bdrv_check_byte_request(src->bs, src_offset, bytes);
ae23c9
+    if (ret) {
ae23c9
+        return ret;
ae23c9
+    }
ae23c9
+    
ae23c9
     if (!src->bs->drv->bdrv_co_copy_range_from
ae23c9
         || !dst->bs->drv->bdrv_co_copy_range_to
ae23c9
         || src->bs->encrypted || dst->bs->encrypted) {
ae23c9
         return -ENOTSUP;
ae23c9
     }
ae23c9
 
ae23c9
-    bdrv_inc_in_flight(src_bs);
ae23c9
-    bdrv_inc_in_flight(dst_bs);
ae23c9
-    tracked_request_begin(&src_req, src_bs, src_offset,
ae23c9
+    bdrv_inc_in_flight(src->bs);
ae23c9
+    bdrv_inc_in_flight(dst->bs);
ae23c9
+    tracked_request_begin(&src_req, src->bs, src_offset,
ae23c9
                           bytes, BDRV_TRACKED_READ);
ae23c9
-    tracked_request_begin(&dst_req, dst_bs, dst_offset,
ae23c9
+    tracked_request_begin(&dst_req, dst->bs, dst_offset,
ae23c9
                           bytes, BDRV_TRACKED_WRITE);
ae23c9
 
ae23c9
     wait_serialising_requests(&src_req);
ae23c9
@@ -2896,8 +2898,8 @@ static int coroutine_fn bdrv_co_copy_range_internal(BdrvChild *src,
ae23c9
     }
ae23c9
     tracked_request_end(&src_req);
ae23c9
     tracked_request_end(&dst_req);
ae23c9
-    bdrv_dec_in_flight(src_bs);
ae23c9
-    bdrv_dec_in_flight(dst_bs);
ae23c9
+    bdrv_dec_in_flight(src->bs);
ae23c9
+    bdrv_dec_in_flight(dst->bs);
ae23c9
     return ret;
ae23c9
 }
ae23c9
 
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9