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

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