thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-nbd-client-Reject-inaccessible-tail-of-inconsistent-.patch

Pablo Greco e6a3ae
From e49b010d5f866b3ee7efbf40398f0a0832ce8801 Mon Sep 17 00:00:00 2001
Pablo Greco e6a3ae
From: Max Reitz <mreitz@redhat.com>
Pablo Greco e6a3ae
Date: Tue, 23 Jul 2019 14:45:43 +0100
Pablo Greco e6a3ae
Subject: [PATCH 05/14] nbd/client: Reject inaccessible tail of inconsistent
Pablo Greco e6a3ae
 server
Pablo Greco e6a3ae
Pablo Greco e6a3ae
RH-Author: Max Reitz <mreitz@redhat.com>
Pablo Greco e6a3ae
Message-id: <20190723144546.23701-5-mreitz@redhat.com>
Pablo Greco e6a3ae
Patchwork-id: 89649
Pablo Greco e6a3ae
O-Subject: [RHEL-8.1.0 qemu-kvm PATCH 4/7] nbd/client: Reject inaccessible tail of inconsistent server
Pablo Greco e6a3ae
Bugzilla: 1678979
Pablo Greco e6a3ae
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
Pablo Greco e6a3ae
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
Pablo Greco e6a3ae
RH-Acked-by: John Snow <jsnow@redhat.com>
Pablo Greco e6a3ae
Pablo Greco e6a3ae
From: Eric Blake <eblake@redhat.com>
Pablo Greco e6a3ae
Pablo Greco e6a3ae
The NBD spec suggests that a server should never advertise a size
Pablo Greco e6a3ae
inconsistent with its minimum block alignment, as that tail is
Pablo Greco e6a3ae
effectively inaccessible to a compliant client obeying those block
Pablo Greco e6a3ae
constraints. Since we have a habit of rounding up rather than
Pablo Greco e6a3ae
truncating, to avoid losing the last few bytes of user input, and we
Pablo Greco e6a3ae
cannot access the tail when the server advertises bogus block sizing,
Pablo Greco e6a3ae
abort the connection to alert the server to fix their bug.  And
Pablo Greco e6a3ae
rejecting such servers matches what we already did for a min_block
Pablo Greco e6a3ae
that was not a power of 2 or which was larger than max_block.
Pablo Greco e6a3ae
Pablo Greco e6a3ae
Does not impact either qemu (which always sends properly aligned
Pablo Greco e6a3ae
sizes) or nbdkit (which does not send minimum block requirements yet);
Pablo Greco e6a3ae
so this is mostly aimed at new NBD server implementations, and ensures
Pablo Greco e6a3ae
that the rest of our code can assume the size is aligned.
Pablo Greco e6a3ae
Pablo Greco e6a3ae
Signed-off-by: Eric Blake <eblake@redhat.com>
Pablo Greco e6a3ae
Message-Id: <20190330155704.24191-1-eblake@redhat.com>
Pablo Greco e6a3ae
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Pablo Greco e6a3ae
(cherry picked from commit 3add3ab78247fd347fd6f377a4b951022ac35d35)
Pablo Greco e6a3ae
Signed-off-by: Max Reitz <mreitz@redhat.com>
Pablo Greco e6a3ae
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
Pablo Greco e6a3ae
---
Pablo Greco e6a3ae
 nbd/client.c | 8 ++++++++
Pablo Greco e6a3ae
 1 file changed, 8 insertions(+)
Pablo Greco e6a3ae
Pablo Greco e6a3ae
diff --git a/nbd/client.c b/nbd/client.c
Pablo Greco e6a3ae
index 25603f2..c828faf 100644
Pablo Greco e6a3ae
--- a/nbd/client.c
Pablo Greco e6a3ae
+++ b/nbd/client.c
Pablo Greco e6a3ae
@@ -416,6 +416,14 @@ static int nbd_opt_go(QIOChannel *ioc, const char *wantname,
Pablo Greco e6a3ae
                 nbd_send_opt_abort(ioc);
Pablo Greco e6a3ae
                 return -1;
Pablo Greco e6a3ae
             }
Pablo Greco e6a3ae
+            if (info->min_block &&
Pablo Greco e6a3ae
+                !QEMU_IS_ALIGNED(info->size, info->min_block)) {
Pablo Greco e6a3ae
+                error_setg(errp, "export size %" PRIu64 "is not multiple of "
Pablo Greco e6a3ae
+                           "minimum block size %" PRIu32, info->size,
Pablo Greco e6a3ae
+                           info->min_block);
Pablo Greco e6a3ae
+                nbd_send_opt_abort(ioc);
Pablo Greco e6a3ae
+                return -1;
Pablo Greco e6a3ae
+            }
Pablo Greco e6a3ae
             be16_to_cpus(&info->flags);
Pablo Greco e6a3ae
             trace_nbd_receive_negotiate_size_flags(info->size, info->flags);
Pablo Greco e6a3ae
             break;
Pablo Greco e6a3ae
-- 
Pablo Greco e6a3ae
1.8.3.1
Pablo Greco e6a3ae