Bug 2066773

Summary: The /tmp/v2v.XXXX directory has incorrect permisison if run v2v by root
Product: Red Hat Enterprise Linux 9 Reporter: Xiaodai Wang <xiaodwan>
Component: virt-v2vAssignee: Richard W.M. Jones <rjones>
Status: CLOSED ERRATA QA Contact: Xiaodai Wang <xiaodwan>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 9.1CC: juzhou, lersek, mxie, pgm-rhel-tools, rjones, tyan, tzheng, vwu
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: virt-v2v-2.0.7-1.el9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 2066775 (view as bug list) Environment:
Last Closed: 2022-11-15 09:56:05 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2066775    

Comment 1 Richard W.M. Jones 2022-03-22 13:24:02 UTC
This is another side effect of https://bugzilla.redhat.com/show_bug.cgi?id=1045069
When virt-v2v runs as root, libvirt runs qemu as a non-root user (eg. qemu:qemu).
This means that qemu cannot open /tmp/v2v.<RAND>/in0, with this error:

  [   1.0] Opening the source
  virt-v2v: error: libguestfs error: could not create appliance through 
  libvirt.

  Try running qemu directly without libvirt using this environment variable:
  export LIBGUESTFS_BACKEND=direct

  Original error from libvirt: internal error: process exited while 
  connecting to monitor: 2022-03-22T13:19:56.454788Z qemu-kvm: -blockdev 
  {"driver":"nbd","server":{"type":"unix","path":"/tmp/v2v.AuSBWm/in0"},"node-name":"libvirt-2-storage","cache":{"direct":false,"no-flush":true},"auto-read-only":true,"discard":"unmap"}: 
  Failed to connect to '/tmp/v2v.AuSBWm/in0': Permission denied [code=1 
  int1=-1]

(With LIBGUESTFS_BACKEND=direct it does work because we don't use libvirt).

To avoid this we have to set the directory with that socket to 0711:

https://github.com/libguestfs/virt-v2v/blob/b365a87b99a7630afc974667dbe23135e35ba4d0/v2v/v2v.ml#L48

This avoids the above error, but introduces the current one instead.

Comment 2 Richard W.M. Jones 2022-03-22 14:37:14 UTC
Patch posted:
https://listman.redhat.com/archives/libguestfs/2022-March/028449.html

Comment 3 Laszlo Ersek 2022-03-23 10:44:07 UTC
Additional cleanup after Rich's v3:

[v2v PATCH] nbdkit, qemuNBD: run_unix: formally require externally provided socket
Message-Id: <20220323104330.9667-1-lersek>
https://listman.redhat.com/archives/libguestfs/2022-March/028464.html

Comment 4 Laszlo Ersek 2022-03-23 12:44:16 UTC
Upstream commits:

     1  4e7f20684373 lib: Improve security of in/out sockets when running virt-v2v as root
     2  9788b06765af nbdkit, qemuNBD: run_unix: formally require externally provided socket

Comment 7 Xiaodai Wang 2022-03-24 11:18:14 UTC
Verified with virt-v2v-2.0.1-1.el9.x86_64.

1. Run v2v by root and check the permission of the /tmp/v2v.xxx directory.
# ll /tmp/v2v.LSsUhy
total 12
-rw-r--r--. 1 root root   0 Mar 24 06:37 copy
srwx------. 1 qemu root   0 Mar 24 06:35 in0
srwx------. 1 qemu root   0 Mar 24 06:37 out0
-rw-r--r--. 1 root root 471 Mar 24 06:37 out.params0.json
-rw-------. 1 root root 168 Mar 24 06:37 v2vprecheck.json
-rw-------. 1 root root 173 Mar 24 06:37 v2vtransfer.json

2. Access the file in that directory by non-root user.
$ ll -d /tmp/v2v.LSsUhy
drwx------. 2 qemu root 113 Mar 24 06:37 /tmp/v2v.LSsUhy
$ ll /tmp/v2v.LSsUhy/in0
ls: cannot access '/tmp/v2v.LSsUhy/in0': Permission denied

3. Run automation scripts to verify the basic function and make sure no regression. 

# avocado run --vt-type v2v convert_vm_to_ovirt.esx.vm.7_0.linux.latest8.arch_x86_64.raw_f.NFS.rhv_upload.rhv_direct.rhv_noverifypeer.preallocated.it_vddk convert_vm_to_ovirt.esx.vm.6_5.linux.latest8.arch_x86_64.raw_f.NFS.rhv_upload.rhv_direct.rhv_noverifypeer.preallocated.it_vddk
JOB ID     : af2d095bd50ec34f53b79fae4d08c2c4faa75bbf
JOB LOG    : /root/avocado/job-results/job-2022-03-24T06.35-af2d095/job.log
 (1/2) type_specific.io-github-autotest-libvirt.convert_vm_to_ovirt.esx.vm.7_0.linux.latest8.arch_x86_64.raw_f.NFS.rhv_upload.rhv_direct.rhv_noverifypeer.preallocated.it_vddk: STARTED
█ 100% [****************************************]
 (1/2) type_specific.io-github-autotest-libvirt.convert_vm_to_ovirt.esx.vm.7_0.linux.latest8.arch_x86_64.raw_f.NFS.rhv_upload.rhv_direct.rhv_noverifypeer.preallocated.it_vddk: PASS (306.28 s)
 (2/2) type_specific.io-github-autotest-libvirt.convert_vm_to_ovirt.esx.vm.6_5.linux.latest8.arch_x86_64.raw_f.NFS.rhv_upload.rhv_direct.rhv_noverifypeer.preallocated.it_vddk: STARTED
█ 100% [****************************************]
 (2/2) type_specific.io-github-autotest-libvirt.convert_vm_to_ovirt.esx.vm.6_5.linux.latest8.arch_x86_64.raw_f.NFS.rhv_upload.rhv_direct.rhv_noverifypeer.preallocated.it_vddk: PASS (2075.30 s)
RESULTS    : PASS 2 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
JOB TIME   : 2382.91 s

# avocado run --vt-type v2v convert_from_file.positive_test.linux.input_mode.ova.parse.SHA1_SHA256.output_mode.rhev.rhv_upload
JOB ID     : 082a05a6a536dbf4ab60ad5f1171dad2e6c82c9c
JOB LOG    : /root/avocado/job-results/job-2022-03-24T06.22-082a05a/job.log
 (1/1) type_specific.io-github-autotest-libvirt.convert_from_file.positive_test.linux.input_mode.ova.parse.SHA1_SHA256.output_mode.rhev.rhv_upload: STARTED
█ 100% [****************************************]
 (1/1) type_specific.io-github-autotest-libvirt.convert_from_file.positive_test.linux.input_mode.ova.parse.SHA1_SHA256.output_mode.rhev.rhv_upload: PASS (120.45 s)
RESULTS    : PASS 1 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
JOB TIME   : 122.41 s

Comment 8 Richard W.M. Jones 2022-03-24 17:32:33 UTC
*** Bug 2068136 has been marked as a duplicate of this bug. ***

Comment 11 errata-xmlrpc 2022-11-15 09:56:05 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Low: virt-v2v security, bug fix, and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2022:7968