Bug 1728545 - Ambiguous qemu-img info output when using slash or backslash in nbd exportname
Summary: Ambiguous qemu-img info output when using slash or backslash in nbd exportname
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux Advanced Virtualization
Classification: Red Hat
Component: qemu-kvm
Version: ---
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: rc
: ---
Assignee: Eric Blake
QA Contact: zixchen
URL:
Whiteboard:
Depends On:
Blocks: 1849893
TreeView+ depends on / blocked
 
Reported: 2019-07-10 07:01 UTC by Han Han
Modified: 2020-11-17 17:45 UTC (History)
8 users (show)

Fixed In Version: qemu-kvm-5.0.0-0.module+el8.3.0+6620+5d5e1420
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 1849893 (view as bug list)
Environment:
Last Closed: 2020-11-17 17:45:27 UTC
Type: Bug
Target Upstream Version:
Embargoed:
zixchen: needinfo-


Attachments (Terms of Use)

Description Han Han 2019-07-10 07:01:31 UTC
Description of problem:
As subject

Version-Release number of selected component (if applicable):
qemu-kvm-4.0.0-5.module+el8.1.0+3622+5812d9bf.x86_64


How reproducible:
100%

Steps to Reproduce:
1. Start a nbd server with export name as slash
# qemu-nbd /tmp/a -x '/' -t

2. Check the nbd disk by qemu-img with url as nbd:<ip>:<port>:exportname=<name>
# qemu-img info 'nbd:10.66.4.183:10809:exportname=/'
image: nbd://10.66.4.183:10809//
file format: raw
virtual size: 100M (104857600 bytes)
disk size: unavailable

3. Check the nbd disk with the url outputed by last command:
# qemu-img info 'nbd://10.66.4.183:10809//'
qemu-img: Could not open 'nbd://10.66.4.183:10809//': Requested export not available
server reported: export '' not present

So qemu-img parse the outputed url as exportname ''

4. Reproduce that with backslash
4.1
# qemu-nbd /tmp/a -x '\' -t

4.2
# qemu-img info 'nbd:10.66.4.183:10809:exportname=\'
image: nbd://10.66.4.183:10809/\
file format: raw
virtual size: 100M (104857600 bytes)
disk size: unavailable

4.3 
# qemu-img info 'nbd://10.66.4.183:10809/\'
qemu-img: Could not open 'nbd://10.66.4.183:10809/\': No valid URL specified


Actual results:
As above

Expected results:
The nbd url with nbd://<ip>/<exportname> could be correctly parsed. Or just output the nbd image as nbd:<ip>:<port>:exportname=<name> format.

Additional info:
Reproduced on rhel7.7(qemu-kvm-rhev-2.12.0-33.el7.x86_64), too.

Comment 2 Maxim Levitsky 2019-11-15 17:42:15 UTC
I analyzed this bug.

The root cause is that nbd driver has two parsers for the filename, the older one that uses 'nbd:' syntax,
and newer one that uses the 'nbd://' URI syntax, following RFC3986

So:

'\' (backslash) in the URI path, appears to be not valid URI

This is what I see in the spec:


path-abempty  = *( "/" segment )
segment       = *pchar
pchar         = unreserved / pct-encoded / sub-delims / ":" / "@"

unreserved  = ALPHA / DIGIT / "-" / "." / "_" / "~"
pct-encoded = "%" HEXDIG HEXDIG
sub-delims  = "!" / "$" / "&" / "'" / "(" / ")"
                  / "*" / "+" / "," / ";" / "="

However as you see you can encode backslash using percent encoded syntax and it does work
meaning that if I name an export '\', I can access it with 'nbd://localhost:10809/%5C'



'/' (forward slash).

The forward slash works fine as long as it is not leading forward slash.
That is when I name export 'foo/bar' I can access it just fine using the URI syntax.

However when the export starts with a slash, it doesn't work.
basically the parser eats all the slashes after the nbd://.

Looking at commit 1d7d2a9d2191c34bd1ad69b420db9b47faa3fb8c, which added that parsing,
it explicitly mentions that as a feature

"The URI syntax is consistent with the Gluster syntax.  Export names
are specified in the path, preceded by one or more (otherwise unused)
slashes.
"


I guess that it is not worth it to support export names starting with a slash anyway,
so I'll close that bug. 
If you think that there is real world case when this is needed, feel free to reopen.

Comment 3 Eric Blake 2020-02-12 14:21:41 UTC
See also this upstream patch:
https://lists.gnu.org/archive/html/qemu-devel/2020-02/msg03018.html

The NBD URI spec says one leading slash in the URI is stripped, but that it is still possible to provide export names with a leading slash, as in:

nbd://localhost:10809//name => export '/name'

so I'll reopen this so we can decide whether to backport that patch.

Comment 4 John Ferlan 2020-02-28 14:04:02 UTC
Fix PULLed upstream, qemu.git commit id '2485f22fe9211b2e80970f83199b320eee211319'

Setting this to POST using next QEMU upstream fixed in version and moving into RHEL AV 8.3.0 for validation.

Comment 5 zixchen 2020-06-22 09:13:14 UTC
Tested with qemu-kvm-5.0.0-0.module+el8.3.0+6620+5d5e1420.x86_64 RHEL AV 8.3.0, export names with a leading slash and backing slash not hit this issue.

Version:
kernel-4.18.0-215.el8.x86_64
qemu-kvm-5.0.0-0.module+el8.3.0+6620+5d5e1420.x86_64



I choose my local host as a nbd server.

Steps for exporting names with a leading slash:
1. qemu-nbd /home/test/rhel83-nbd.qcow2 -x '/' -t
2. qemu-img info 'nbd:localhost:10809:exportname=/'
3. qemu-img info 'nbd://localhost:10809//'

After Step2, 
image: nbd://localhost:10809//
file format: raw
virtual size: 20 GiB (21474836480 bytes)
disk size: unavailable

After Step3,
image: nbd://localhost:10809//
file format: raw
virtual size: 20 GiB (21474836480 bytes)
disk size: unavailable



I validated this issue when exporting with a backslash as well: 
Steps for exporting names with a leading slash:
1. qemu-nbd /home/test/rhel83-nbd.qcow2 -x '\' -t
2. qemu-img info 'nbd:localhost:10809:exportname=\'
3. qemu-img info 'nbd://localhost:10809/\'
4. qemu-img info 'nbd://localhost:10809/%5C'

After Step2, 
image: nbd://localhost:10809/\
file format: raw
virtual size: 20 GiB (21474836480 bytes)
disk size: unavailable

After Step3,
qemu-img: Could not open 'nbd://localhost:10809/\': No valid URL specified

After Step4,
image: nbd://localhost:10809/\
file format: raw
virtual size: 20 GiB (21474836480 bytes)
disk size: unavailable



Additional info:
In the slow train of RHEL 8.3.0 with qemu-kvm-4.2.0-28.module+el8.3.0+7105+0cc49779.x86_64, hit the issue with both leading slash '/'. 

Same test steps, but in the leading slash case after Step 3:
qemu-img: Could not open 'nbd://localhost:10809//': Requested export not available
server reported: export '' not present
 
Should a new issue be cloned to slow train RHEL8.3.0?

Comment 6 zixchen 2020-06-23 07:19:15 UTC
For RHEL 8.3.0 slow train, the new bug id: Bug 1849893

Comment 9 zixchen 2020-06-30 05:50:23 UTC
According to comment 5, change status to VERIFIED

Comment 12 errata-xmlrpc 2020-11-17 17:45:27 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 (virt:8.3 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/RHBA-2020:5137


Note You need to log in before you can comment on or make changes to this bug.