Bug 1164708 - set-label can only set <=127 bytes for btrfs and <=126 bytes for ntfs filesystem which not meet the help message. Also for ntfs it should give a warning message when the length >128 bytes
Summary: set-label can only set <=127 bytes for btrfs and <=126 bytes for ntfs filesys...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libguestfs
Version: 7.1
Hardware: Unspecified
OS: Unspecified
low
low
Target Milestone: rc
: ---
Assignee: Richard W.M. Jones
QA Contact: Virtualization Bugs
URL:
Whiteboard:
Depends On: 1218766
Blocks: 1288337 1301891
TreeView+ depends on / blocked
 
Reported: 2014-11-17 08:26 UTC by Lingfei Kong
Modified: 2016-11-03 17:47 UTC (History)
7 users (show)

Fixed In Version: libguestfs-1.32.0-2.el7
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2016-11-03 17:47:18 UTC


Attachments (Terms of Use)
test-label.pl (1.28 KB, text/plain)
2014-11-17 09:21 UTC, Richard W.M. Jones
no flags Details


Links
System ID Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2016:2576 normal SHIPPED_LIVE Moderate: libguestfs and virt-p2v security, bug fix, and enhancement update 2016-11-03 12:06:51 UTC
Red Hat Bugzilla 1164729 None None None Never

Internal Links: 1164729

Description Lingfei Kong 2014-11-17 08:26:35 UTC
Description of problem:
For btrfs:
I can confirm that the label length for btrfs is less than 256 bytes both in libguestfs and linux system. Check 'help set-label' in guestfish and 'man mkfs.btrfs' in linux system. When i try to set a label who's length is 180 bytes, i can set the label successfully, but when i get the new label via 'vfs-label' i only got 127 bytes.

Also in 'help set-label' i can obtain that i can set 256 bytes for btrfs, obviously this is wrong, for btrfs the max bytes is 255:
><fs> help set-label
[...]
   btrfs
				The label is limited to 256 bytes and some characters are not
				allowed. Setting the label on a btrfs subvolume will set the label
				on its parent filesystem. The filesystem must not be mounted when
				trying to set the label.


For ntfs:
set-label for ntfs can only set <=126 bytes which is less than 128 bytes according to 'help set-label', also it should give a warning message when the length > 128 bytes. Perhaps the limited number is right but the help message is wrong.


Version-Release number of selected component (if applicable):
libguestfs-1.28.1-1.10.el7


How reproducible:
100%


Steps to Reproduce:
1. # str="2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d"
   # echo ${#str}
180

2. #guestfish -N fs:btrfs
><fs> set-label  /dev/sda1 2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d
><fs> vfs-label /dev/sda1
2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-

# str2="2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-"
# echo ${#str2}
127

3. Check 'help set-label' in guestfish

4. # str="2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d"
   # echo ${#str}
180

5. #guestfish -N fs:ntfs
><fs> set-label  /dev/sda1 2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d
><fs> vfs-label /dev/sda1
2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955f2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-

# str2="2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-816c-955f2c0b43d2c395734-c68b-4181-816c-955bf2c0b43d2c395734-c68b-4181-"
# echo ${#str2}
126

6. Check 'help set-label' in guestfish


Actual results:
At step 2, only get the first 127 bytes of the label name
At step 3, the limited number is 256 which is wrong
At step 5, only get the first 126 bytes of the label name


Expected results:
At step 2, i can get the right label name(180 bytes) when i run 'vfs-label /dev/sda1'
At step 3, the limited number should be 255
At step 5, can get the first 128 bytes of the label name when i run 'vfs-label /dev/sda1'

Additional info:

Comment 1 Richard W.M. Jones 2014-11-17 09:21:32 UTC
Created attachment 958200 [details]
test-label.pl

Attached is a useful script to test the behaviour of labels.

$ ./test-label.pl btrfs 0 256 ascii
0	ok
1	ok
2	ok
3	ok
4	ok
5	ok
[...]
125	ok
126	ok
127	ok
128	truncated to 127
129	truncated to 127
130	truncated to 127
131	truncated to 127
[...]
254	truncated to 127
255	truncated to 127
256	error setting label: set_label: ERROR: Label aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa is too long (max 255) at /tmp/test-label.pl line 36.


or:

$ ./test-label.pl btrfs 0 256 unicode

Comment 2 Richard W.M. Jones 2014-11-17 09:30:02 UTC
So using my script it looks as if the real limits are:

 - ext2/3/4: 16 bytes
 - btrfs: 127 bytes (this contradicts the btrfs documentation)
 - ntfs: behaviour is very strange, especially when using non-ASCII

I'm not sure that libguestfs should be checking limits at all.
It seems to invite trouble.  We should just pass labels through
to the underlying utilities and let them deal with error cases.

Comment 3 Lingfei Kong 2014-11-17 11:21:03 UTC
(In reply to Richard W.M. Jones from comment #2)
> So using my script it looks as if the real limits are:
> 
>  - ext2/3/4: 16 bytes
>  - btrfs: 127 bytes (this contradicts the btrfs documentation)
>  - ntfs: behaviour is very strange, especially when using non-ASCII
> 
> I'm not sure that libguestfs should be checking limits at all.
> It seems to invite trouble.  We should just pass labels through
> to the underlying utilities and let them deal with error cases.

I have encountered many cases that a software auto truncate a long name without give a warning message, anyway extX, btrfs, xfs,ntfs should have the same behavior(give or not give warning messages) when the label length > limited number.

Comment 4 Pino Toscano 2015-01-14 09:34:28 UTC
(In reply to Richard W.M. Jones from comment #2)
> So using my script it looks as if the real limits are:
> 
>  - btrfs: 127 bytes (this contradicts the btrfs documentation)

This does not seem a bug in btrfs, but rather in util-linux. If I change vfs_label to use `btrfs filesystem label` to get the label of a btrfs filesystem, I get the correct result, not truncated.

I'm going to post a patch to use `btrfs` to get the label of btrfs filesystems, if present; this should give the actual value.

I'll deal with util-linux later, as it seems libblkid cannot cope with file system labels longer than 127 characters.

Comment 5 Karel Zak 2015-01-14 10:02:50 UTC
Added to libblkid TODO, will be fixed later this year (I guess it's no urgent issue).

Comment 6 Pino Toscano 2015-01-14 15:25:28 UTC
(In reply to Pino Toscano from comment #4)
> I'm going to post a patch to use `btrfs` to get the label of btrfs
> filesystems, if present; this should give the actual value.

Patch posted:
  https://www.redhat.com/archives/libguestfs/2015-January/msg00037.html

Comment 7 Pino Toscano 2015-01-14 15:34:55 UTC
(In reply to Richard W.M. Jones from comment #2)
> So using my script it looks as if the real limits are:
> 
>  - ntfs: behaviour is very strange, especially when using non-ASCII

This is another issue in util-linux, as it seems (at least with util-linux 2.24.x) it does not decode the label (the volume name, actually) correctly.

If I change vfs_label to use `ntfslabel` for getting the label of ntfs filesystems, then I get the correct result, which is at most 128 unicode characters as stated in the man page. Unfortunately, even ntfslabel (at least as part of ntfsprogs/ntfs-3g 2014.2.15-1.fc20) silently truncates to the maximum, printing a warning and still exiting with 0...

Comment 8 Pino Toscano 2015-01-19 15:51:26 UTC
https://github.com/libguestfs/libguestfs/commit/6db3c100e7c18820ff9ecc22415940eb5fedc64e
this uses btrfs(1) for btrfs partitions

https://github.com/libguestfs/libguestfs/commit/8ad667f1983e98347f4d292c07f971d5362ff052
this uses ntfslabel(1) for ntfs partitions

Comment 12 Hu Zhang 2015-05-06 09:36:00 UTC
Not fixed completely.
Test with libguestfs-1.28.1-1.29.el7.

Step to verify:
1. For btrfs, the 'help set-label' in guestfish says that The label is limited to 256 bytes. Now from the result following, we can only set a label with 255 bytes. So need some modification here.
# ./test-label.pl btrfs 0 256 ascii
0       ok
1       ok
2       ok
...
253     ok
254     ok
255     ok
256     error setting label: set_label: ERROR: Label aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa is too long (max 255) at ./test-label.pl line 36.


2. For ntfs, works well now.
# ./test-label.pl ntfs 0 129 unicode
0       ok
1       ok
2       ok
...
127     ok
128     ok
129     truncated to 384

So, for btrfs, the limited number is 256 which is wrong.

Comment 14 Richard W.M. Jones 2015-07-08 21:15:40 UTC
Move to RHEL 7.3 since we don't have a working upstream fix yet.

Comment 16 Pino Toscano 2015-10-05 09:46:53 UTC
(In reply to Hu Zhang from comment #12)
> 1. For btrfs, the 'help set-label' in guestfish says that The label is
> limited to 256 bytes. Now from the result following, we can only set a label
> with 255 bytes. So need some modification here.

We don't do checks on btrfs labels, as luckly the btrfs tools (e.g. `btrfs filesystem label`) do proper checks on their own, issuing errors (unlike tools for most of the other filesystems for which we can set labels).

This is just a documentation issue for set-label, and I've just pushed
https://github.com/libguestfs/libguestfs/commit/1f47ba92f20b812c8fe2fd6359b648863a8bcac4
which is in libguestfs >= 1.31.11.

Comment 19 Xianghua Chen 2016-06-28 07:43:45 UTC
Verified with the packages:
libguestfs-1.32.5-6.el7.x86_64

Verify steps:
1. # ./test-label.pl ntfs 0 129 unicode
0       ok
1       ok
2       ok
...
127     ok
128     ok
129     truncated to 384

It's ok.

2. # guestfish
><fs> help set-label
   btrfs
        The label is limited to 255 bytes and some characters are not
        allowed. Setting the label on a btrfs subvolume will set the label
        on its parent filesystem. The filesystem must not be mounted when
        trying to set the label.

It has been changed to 255 from 256.

So verified.

Comment 21 errata-xmlrpc 2016-11-03 17:47:18 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, 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://rhn.redhat.com/errata/RHSA-2016-2576.html


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