[PATCH] virt-v2v: Catch invalid initrd path
In some cases (specifically, SUSE grub2 environments) it is possible to fail to update the block entries in device.map. In turn, this causes an invalid path to be returned in perl-Bootloader code, which causes the conversion to fail with the following message: is_file_opts: is_file: is_file_stub: path must start with a / character This patch prevents the problem by adding device.map (for /boot/grub and /boot/grub2) to the list of configurations to remap, then adds a check to ensure invalid paths are not passed to is_file_opts. Note - This is for the existing (perl version) of virt-v2v. --- lib/Sys/VirtConvert/Converter/Linux.pm | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/Sys/VirtConvert/Converter/Linux.pm b/lib/Sys/VirtConvert/Converter/Linux.pm index e8463bc..b673120 100644 --- a/lib/Sys/VirtConvert/Converter/Linux.pm +++ b/lib/Sys/VirtConvert/Converter/Linux.pm @@ -56,7 +56,10 @@ sub get_initrd if (defined($initrd)) { # If the initrd starts with (hdX,X), remove it. $initrd =~ s/^\(hd.*\)//; - return $initrd if ($g->is_file_opts($initrd, followsymlinks=>1)); + # Catch invalid paths by ensuring first character is '/' + if ($initrd =~ /^\//) { + return $initrd if $g->is_file_opts($initrd, followsymlinks=>1); + } } } @@ -2672,13 +2675,13 @@ sub _remap_block_devices # Add standard configuration files to the checklist push (@checklist, '/files/etc/fstab/*/spec'); + push (@checklist, '/files/boot/*/device.map/*'. + '[label() != "#comment"]'); # Add grub or grub2 files to the checklist if (defined($grub->{grub_conf})) { push (@checklist, "/files$grub->{grub_conf}/*/kernel/root"); push (@checklist, "/files$grub->{grub_conf}/*/kernel/resume"); - push (@checklist, '/files/boot/grub/device.map/*'. - '[label() != "#comment"]'); } elsif (defined($grub->{cfg})) { push (@checklist, '/files/etc/sysconfig/grub/GRUB_CMDLINE_LINUX'); -- 1.8.4.5
On Thu, Apr 24, 2014 at 04:43:59PM -0600, Mike Latimer wrote:
In some cases (specifically, SUSE grub2 environments) it is possible to fail to update the block entries in device.map. In turn, this causes an invalid path to be returned in perl-Bootloader code, which causes the conversion to fail with the following message:
is_file_opts: is_file: is_file_stub: path must start with a / character
This patch prevents the problem by adding device.map (for /boot/grub and /boot/grub2) to the list of configurations to remap, then adds a check to ensure invalid paths are not passed to is_file_opts.
Note - This is for the existing (perl version) of virt-v2v.
Sorry for the late reply, but I've been buried in the v2v rewrite for the past few days. I will take this patch into account when I get back to the Linux conversion part. Thanks, Rich.
--- lib/Sys/VirtConvert/Converter/Linux.pm | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/lib/Sys/VirtConvert/Converter/Linux.pm b/lib/Sys/VirtConvert/Converter/Linux.pm index e8463bc..b673120 100644 --- a/lib/Sys/VirtConvert/Converter/Linux.pm +++ b/lib/Sys/VirtConvert/Converter/Linux.pm @@ -56,7 +56,10 @@ sub get_initrd if (defined($initrd)) { # If the initrd starts with (hdX,X), remove it. $initrd =~ s/^\(hd.*\)//; - return $initrd if ($g->is_file_opts($initrd, followsymlinks=>1)); + # Catch invalid paths by ensuring first character is '/' + if ($initrd =~ /^\//) { + return $initrd if $g->is_file_opts($initrd, followsymlinks=>1); + } } }
@@ -2672,13 +2675,13 @@ sub _remap_block_devices
# Add standard configuration files to the checklist push (@checklist, '/files/etc/fstab/*/spec'); + push (@checklist, '/files/boot/*/device.map/*'. + '[label() != "#comment"]');
# Add grub or grub2 files to the checklist if (defined($grub->{grub_conf})) { push (@checklist, "/files$grub->{grub_conf}/*/kernel/root"); push (@checklist, "/files$grub->{grub_conf}/*/kernel/resume"); - push (@checklist, '/files/boot/grub/device.map/*'. - '[label() != "#comment"]'); } elsif (defined($grub->{cfg})) { push (@checklist, '/files/etc/sysconfig/grub/GRUB_CMDLINE_LINUX'); -- 1.8.4.5
_______________________________________________ Libguestfs mailing list Libguestfs@redhat.com https://www.redhat.com/mailman/listinfo/libguestfs
-- 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 Friday, April 25, 2014 08:58:24 PM Richard W.M. Jones wrote:
Sorry for the late reply, but I've been buried in the v2v rewrite for the past few days. I will take this patch into account when I get back to the Linux conversion part.
No problem. Thanks for looking at it. Regarding the re-write, are you far enough long that patches to the perl version are no longer needed? Also, is virt-p2v on the rewrite list as well? Thanks again, Mike
On Mon, Apr 28, 2014 at 09:11:22AM -0600, Mike Latimer wrote:
On Friday, April 25, 2014 08:58:24 PM Richard W.M. Jones wrote:
Sorry for the late reply, but I've been buried in the v2v rewrite for the past few days. I will take this patch into account when I get back to the Linux conversion part.
No problem. Thanks for looking at it.
Regarding the re-write, are you far enough long that patches to the perl version are no longer needed?
Well .. you can send them but I won't apply them, and I'll have to adapt them to the new code base. I'm really hoping to have something posted and working, and perhaps integrated by the end of this week or sooner, and then we can all work on the new code.
Also, is virt-p2v on the rewrite list as well?
Yes, actually that's what I'm doing right now. virt-p2v is now in C. 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/
participants (2)
-
Mike Latimer -
Richard W.M. Jones