[v2v PATCH 0/2] lib/utils: get_disk_allocated: adopt the int64 element type for "entries"
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2027598 This small series (esp. the second patch) is necessary in virt-v2v, for putting the just-posted libnbd patch [Libguestfs] [libnbd PATCH] ocaml: map C's uint32_t to OCaml's int64 https://listman.redhat.com/archives/libguestfs/2022-January/msg00093.html Message-Id: <20220114133833.24835-1-lersek@redhat.com> to use. Thanks, Laszlo Laszlo Ersek (2): lib/utils: get_disk_allocated: assert that NBD block length is positive lib/utils: get_disk_allocated: adopt the int64 element type for "entries" lib/utils.ml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) base-commit: 4578887821d8c70190f5f8c3edf4779f1d502d06 -- 2.19.1.3.g30247aa5d201
It makes no sense for the NBD server to return a zero-length block, plus it used to be a bug in the libnbd OCaml bindings to wrap 32-bit block lengths with the MSB set around to negative (signed) 32-bit integers (which would then be widened to negative (signed) 64-bit integers). Any non-positive "len" value breaks the progression of "fetch_offset", potentially leading to an infinite loop. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2027598 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- lib/utils.ml | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/utils.ml b/lib/utils.ml index 4c43a4b5161d..f599b0e32450 100644 --- a/lib/utils.ml +++ b/lib/utils.ml @@ -197,6 +197,7 @@ let get_disk_allocated ~dir ~disknr = for i = 0 to Array.length entries / 2 - 1 do let len = Int64.of_int32 entries.(i * 2) and typ = entries.(i * 2 + 1) in + assert (len > 0_L); if Int32.logand typ 1_l = 0_l then allocated := !allocated +^ len; fetch_offset := !fetch_offset +^ len -- 2.19.1.3.g30247aa5d201
On Fri, Jan 14, 2022 at 02:50:47PM +0100, Laszlo Ersek wrote:
It makes no sense for the NBD server to return a zero-length block, plus it used to be a bug in the libnbd OCaml bindings to wrap 32-bit block lengths with the MSB set around to negative (signed) 32-bit integers (which would then be widened to negative (signed) 64-bit integers).
Any non-positive "len" value breaks the progression of "fetch_offset", potentially leading to an infinite loop.
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2027598 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- lib/utils.ml | 1 + 1 file changed, 1 insertion(+)
diff --git a/lib/utils.ml b/lib/utils.ml index 4c43a4b5161d..f599b0e32450 100644 --- a/lib/utils.ml +++ b/lib/utils.ml @@ -197,6 +197,7 @@ let get_disk_allocated ~dir ~disknr = for i = 0 to Array.length entries / 2 - 1 do let len = Int64.of_int32 entries.(i * 2) and typ = entries.(i * 2 + 1) in + assert (len > 0_L); if Int32.logand typ 1_l = 0_l then allocated := !allocated +^ len; fetch_offset := !fetch_offset +^ len -- 2.19.1.3.g30247aa5d201
I'm inclined to ACK, but it does leave us open to the possibility that virt-v2v will crash if an NBD server returned a zero length block. That would be sort of wrong, but could still happen in a semi-well-behaved custom nbdkit plugin which is returning other blocks and so still making process. Eric: any thoughts on this? Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
On Fri, Jan 14, 2022 at 02:06:33PM +0000, Richard W.M. Jones wrote:
On Fri, Jan 14, 2022 at 02:50:47PM +0100, Laszlo Ersek wrote:
It makes no sense for the NBD server to return a zero-length block, plus it used to be a bug in the libnbd OCaml bindings to wrap 32-bit block lengths with the MSB set around to negative (signed) 32-bit integers (which would then be widened to negative (signed) 64-bit integers).
Any non-positive "len" value breaks the progression of "fetch_offset", potentially leading to an infinite loop.
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2027598 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- lib/utils.ml | 1 + 1 file changed, 1 insertion(+)
diff --git a/lib/utils.ml b/lib/utils.ml index 4c43a4b5161d..f599b0e32450 100644 --- a/lib/utils.ml +++ b/lib/utils.ml @@ -197,6 +197,7 @@ let get_disk_allocated ~dir ~disknr = for i = 0 to Array.length entries / 2 - 1 do let len = Int64.of_int32 entries.(i * 2) and typ = entries.(i * 2 + 1) in + assert (len > 0_L); if Int32.logand typ 1_l = 0_l then allocated := !allocated +^ len; fetch_offset := !fetch_offset +^ len -- 2.19.1.3.g30247aa5d201
I'm inclined to ACK, but it does leave us open to the possibility that virt-v2v will crash if an NBD server returned a zero length block. That would be sort of wrong, but could still happen in a semi-well-behaved custom nbdkit plugin which is returning other blocks and so still making process. Eric: any thoughts on this?
The NBD protocol is clear that a block status result cannot be zero-length; such a server is buggy. While it does seem harsh that a MitM attacker could thus crash v2v by sending a server response that violates the protocol, that can only affect unencrypted connections (so it's no worse than any other MitM attack, and equally mitigated). I'm also inclined to ACK the patch. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
On 01/14/22 21:57, Eric Blake wrote:
On Fri, Jan 14, 2022 at 02:06:33PM +0000, Richard W.M. Jones wrote:
On Fri, Jan 14, 2022 at 02:50:47PM +0100, Laszlo Ersek wrote:
It makes no sense for the NBD server to return a zero-length block, plus it used to be a bug in the libnbd OCaml bindings to wrap 32-bit block lengths with the MSB set around to negative (signed) 32-bit integers (which would then be widened to negative (signed) 64-bit integers).
Any non-positive "len" value breaks the progression of "fetch_offset", potentially leading to an infinite loop.
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2027598 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- lib/utils.ml | 1 + 1 file changed, 1 insertion(+)
diff --git a/lib/utils.ml b/lib/utils.ml index 4c43a4b5161d..f599b0e32450 100644 --- a/lib/utils.ml +++ b/lib/utils.ml @@ -197,6 +197,7 @@ let get_disk_allocated ~dir ~disknr = for i = 0 to Array.length entries / 2 - 1 do let len = Int64.of_int32 entries.(i * 2) and typ = entries.(i * 2 + 1) in + assert (len > 0_L); if Int32.logand typ 1_l = 0_l then allocated := !allocated +^ len; fetch_offset := !fetch_offset +^ len -- 2.19.1.3.g30247aa5d201
I'm inclined to ACK, but it does leave us open to the possibility that virt-v2v will crash if an NBD server returned a zero length block. That would be sort of wrong, but could still happen in a semi-well-behaved custom nbdkit plugin which is returning other blocks and so still making process. Eric: any thoughts on this?
The NBD protocol is clear that a block status result cannot be zero-length; such a server is buggy. While it does seem harsh that a MitM attacker could thus crash v2v by sending a server response that violates the protocol, that can only affect unencrypted connections (so it's no worse than any other MitM attack, and equally mitigated). I'm also inclined to ACK the patch.
Thank you. Laszlo
On 01/14/22 15:06, Richard W.M. Jones wrote:
On Fri, Jan 14, 2022 at 02:50:47PM +0100, Laszlo Ersek wrote:
It makes no sense for the NBD server to return a zero-length block, plus it used to be a bug in the libnbd OCaml bindings to wrap 32-bit block lengths with the MSB set around to negative (signed) 32-bit integers (which would then be widened to negative (signed) 64-bit integers).
Any non-positive "len" value breaks the progression of "fetch_offset", potentially leading to an infinite loop.
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2027598 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- lib/utils.ml | 1 + 1 file changed, 1 insertion(+)
diff --git a/lib/utils.ml b/lib/utils.ml index 4c43a4b5161d..f599b0e32450 100644 --- a/lib/utils.ml +++ b/lib/utils.ml @@ -197,6 +197,7 @@ let get_disk_allocated ~dir ~disknr = for i = 0 to Array.length entries / 2 - 1 do let len = Int64.of_int32 entries.(i * 2) and typ = entries.(i * 2 + 1) in + assert (len > 0_L); if Int32.logand typ 1_l = 0_l then allocated := !allocated +^ len; fetch_offset := !fetch_offset +^ len -- 2.19.1.3.g30247aa5d201
I'm inclined to ACK, but it does leave us open to the possibility that virt-v2v will crash if an NBD server returned a zero length block. That would be sort of wrong, but could still happen in a semi-well-behaved custom nbdkit plugin which is returning other blocks and so still making process.
"Still making progress" is not an excuse I think; if the NBD server can insert *one* zero-length entry, it can then insert *infinitely* many. I don't think we should tolerate that. Thanks! Laszlo
Eric: any thoughts on this?
Rich.
Adapt our "Utils.get_disk_allocated" function to the changed signature of "NBD.block_status", coming from libnbd patch ocaml: map C's uint32_t to OCaml's int64 Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2027598 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- lib/utils.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/utils.ml b/lib/utils.ml index f599b0e32450..4c8998c28a3c 100644 --- a/lib/utils.ml +++ b/lib/utils.ml @@ -195,10 +195,10 @@ let get_disk_allocated ~dir ~disknr = (fun ctx offset entries err -> assert (ctx = alloc_ctx); for i = 0 to Array.length entries / 2 - 1 do - let len = Int64.of_int32 entries.(i * 2) + let len = entries.(i * 2) and typ = entries.(i * 2 + 1) in assert (len > 0_L); - if Int32.logand typ 1_l = 0_l then + if typ &^ 1_L = 0_L then allocated := !allocated +^ len; fetch_offset := !fetch_offset +^ len done; -- 2.19.1.3.g30247aa5d201
On Fri, Jan 14, 2022 at 02:50:48PM +0100, Laszlo Ersek wrote:
Adapt our "Utils.get_disk_allocated" function to the changed signature of "NBD.block_status", coming from libnbd patch
ocaml: map C's uint32_t to OCaml's int64
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2027598 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- lib/utils.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/utils.ml b/lib/utils.ml index f599b0e32450..4c8998c28a3c 100644 --- a/lib/utils.ml +++ b/lib/utils.ml @@ -195,10 +195,10 @@ let get_disk_allocated ~dir ~disknr = (fun ctx offset entries err -> assert (ctx = alloc_ctx); for i = 0 to Array.length entries / 2 - 1 do - let len = Int64.of_int32 entries.(i * 2) + let len = entries.(i * 2) and typ = entries.(i * 2 + 1) in assert (len > 0_L); - if Int32.logand typ 1_l = 0_l then + if typ &^ 1_L = 0_L then allocated := !allocated +^ len; fetch_offset := !fetch_offset +^ len done;
ACK - even makes the code better :-) Getting this into RHEL is going to be a pain, I will deal with the chain of builds once you've pushed this upstream. Thanks, Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/
On 01/14/22 15:07, Richard W.M. Jones wrote:
On Fri, Jan 14, 2022 at 02:50:48PM +0100, Laszlo Ersek wrote:
Adapt our "Utils.get_disk_allocated" function to the changed signature of "NBD.block_status", coming from libnbd patch
ocaml: map C's uint32_t to OCaml's int64
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2027598 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- lib/utils.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/utils.ml b/lib/utils.ml index f599b0e32450..4c8998c28a3c 100644 --- a/lib/utils.ml +++ b/lib/utils.ml @@ -195,10 +195,10 @@ let get_disk_allocated ~dir ~disknr = (fun ctx offset entries err -> assert (ctx = alloc_ctx); for i = 0 to Array.length entries / 2 - 1 do - let len = Int64.of_int32 entries.(i * 2) + let len = entries.(i * 2) and typ = entries.(i * 2 + 1) in assert (len > 0_L); - if Int32.logand typ 1_l = 0_l then + if typ &^ 1_L = 0_L then allocated := !allocated +^ len; fetch_offset := !fetch_offset +^ len done;
ACK - even makes the code better :-)
Yes, I liked the &^ operator too :)
Getting this into RHEL is going to be a pain, I will deal with the chain of builds once you've pushed this upstream.
Thanks -- I did the backports already (or should I say "some" backports, as they were not reviewed), please see the links in the BZs (private comments due to downstream branches and builds). Thanks! Laszlo
Thanks,
Rich.
On 01/14/22 15:07, Richard W.M. Jones wrote:
On Fri, Jan 14, 2022 at 02:50:48PM +0100, Laszlo Ersek wrote:
Adapt our "Utils.get_disk_allocated" function to the changed signature of "NBD.block_status", coming from libnbd patch
ocaml: map C's uint32_t to OCaml's int64
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2027598 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- lib/utils.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/utils.ml b/lib/utils.ml index f599b0e32450..4c8998c28a3c 100644 --- a/lib/utils.ml +++ b/lib/utils.ml @@ -195,10 +195,10 @@ let get_disk_allocated ~dir ~disknr = (fun ctx offset entries err -> assert (ctx = alloc_ctx); for i = 0 to Array.length entries / 2 - 1 do - let len = Int64.of_int32 entries.(i * 2) + let len = entries.(i * 2) and typ = entries.(i * 2 + 1) in assert (len > 0_L); - if Int32.logand typ 1_l = 0_l then + if typ &^ 1_L = 0_L then allocated := !allocated +^ len; fetch_offset := !fetch_offset +^ len done;
ACK - even makes the code better :-)
Getting this into RHEL is going to be a pain, I will deal with the chain of builds once you've pushed this upstream.
Thanks -- I'll take this as two ACKs from you for the series, and one ACK from Eric for patch#1. Cheers! Laszlo
On 01/14/22 14:50, Laszlo Ersek wrote:
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2027598
This small series (esp. the second patch) is necessary in virt-v2v, for putting the just-posted libnbd patch
[Libguestfs] [libnbd PATCH] ocaml: map C's uint32_t to OCaml's int64 https://listman.redhat.com/archives/libguestfs/2022-January/msg00093.html Message-Id: <20220114133833.24835-1-lersek@redhat.com>
to use.
Thanks, Laszlo
Laszlo Ersek (2): lib/utils: get_disk_allocated: assert that NBD block length is positive lib/utils: get_disk_allocated: adopt the int64 element type for "entries"
lib/utils.ml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
base-commit: 4578887821d8c70190f5f8c3edf4779f1d502d06
Commit range 4578887821d8..a2afed32d8b1. Thanks! Laszlo
participants (3)
-
Eric Blake -
Laszlo Ersek -
Richard W.M. Jones