Bug 582504 - guestfish lsetxattr subcommand can not work for symbol links
guestfish lsetxattr subcommand can not work for symbol links
Status: CLOSED NOTABUG
Product: Virtualization Tools
Classification: Community
Component: libguestfs (Show other bugs)
unspecified
All Linux
low Severity medium
: ---
: ---
Assigned To: Richard W.M. Jones
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2010-04-15 03:56 EDT by Pengzhen Cao
Modified: 2010-05-09 22:23 EDT (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2010-05-09 22:23:38 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Pengzhen Cao 2010-04-15 03:56:46 EDT
Description of problem:
lsetxattr subcommand does not work for symbol links

Version-Release number of selected component (if applicable):
libguestfs-1.0.85-1.fc12.3.x86_64
And also the lastest git version


How reproducible:
100%

Steps to Reproduce:
1.Run guestfish, add an img containing some symbol links(links using either relative or absolute paths)
2.mount with "mount-options user_xattr your_partition /"
3.run lsetxattr /your_symbol_link
  
Actual results:
libguestfs: error: lsetxattr: setxattr: Operation not permitted

Expected results:
lsetxattr should work for symbol links as this command is designed for symbol links and normal files

Additional info:
logs
>>>>>>>>>>
><fs> run
><fs> mount-options user_xattr /dev/vol_test/vol_file /
><fs> ll /
total 18
drwxr-xr-x  7 root root  1024 Apr 14 08:46 .
dr-xr-xr-x 20 root root     0 Apr 15 01:51 ..
drwxr-xr-x  2 root root  1024 Apr  1 08:59 aaa
drwxr-xr-x  2 root root  1024 Apr  1 10:03 du_test
drwxr-xr-x  3  500  500  1024 Apr 14 10:25 file_attributes
drwxr-xr-x  7 root root  1024 Apr  2 09:42 file_test
-rw-r--r--  1 root root    19 Apr  8 08:31 h.txt
drwx------  2 root root 12288 Apr  1 08:58 lost+found

><fs> ln-s /h.txt /h.txt.link
><fs> lsetxatt user.name "haha" 4 /h.txt
lsetxatt: unknown command
><fs> lsetxattr user.name "haha" 4 /h.txt
><fs> getxattrs /h.txt
[0] = {
  attrname: user.name
  attrval: haha
}
><fs> lsetxattr user.name "1234" 4 /h.txt.link
libguestfs: error: lsetxattr: setxattr: Operation not permitted
><fs> q
>>>>>>>>>>>
Comment 1 Richard W.M. Jones 2010-05-07 12:56:04 EDT
As far as I can tell, this is just a feature (or problem) of Linux.
lsetxattr returns EPERM when called on symlinks.

$ cat test.c 
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <attr/xattr.h>

int
main (int argc, char *argv[])
{
  if (lsetxattr (argv[1], "user.name", "haha", 4, XATTR_REPLACE) == -1) {
    perror (argv[1]);
    exit (1);
  }
  exit (0);
}
$ gcc -static -Wall test.c -o test

Upload 'test' to a fresh disk image, then open the disk
image in virt-rescue:

><rescue> mount -o user_xattr /dev/vda1 /sysroot/
><rescue> chmod +x /sysroot/test
><rescue> cd /sysroot/
><rescue> ls
lost+found  test
><rescue> touch file
><rescue> ln -s file symlink
><rescue> ls -l
total 721
-rw-r--r-- 1 root root      0 May  7 17:53 file
drwx------ 2 root root  12288 May  7 17:52 lost+found
lrwxrwxrwx 1 root root      4 May  7 17:53 symlink -> file
-rwxr-xr-x 1 root root 721583 May  7 17:52 test
><rescue> ./test file
><rescue> ./test symlink
symlink: Operation not permitted
Comment 2 Richard W.M. Jones 2010-05-07 13:00:09 EDT
So the reason, from the Linux source:

http://lxr.linux.no/linux+v2.6.33/fs/xattr.c#L54

  54        /* In user.* namespace, only regular files and directories can have
  55         * extended attributes. For sticky directories, only the owner and
  56         * privileged user can write attributes.
  57         */

It seems like you could set other attributes, eg. SELinux
or trusted.* on symlinks, but not user.*
Comment 3 Pengzhen Cao 2010-05-09 21:20:06 EDT
(In reply to comment #2)
> So the reason, from the Linux source:
> 
> http://lxr.linux.no/linux+v2.6.33/fs/xattr.c#L54
> 
>   54        /* In user.* namespace, only regular files and directories can have
>   55         * extended attributes. For sticky directories, only the owner and
>   56         * privileged user can write attributes.
>   57         */
> 
> It seems like you could set other attributes, eg. SELinux
> or trusted.* on symlinks, but not user.*    

hmm. yes the comments in xattr.c said clearly only regular file supported.
So we can close this bug as "not a bug"?
Comment 4 Pengzhen Cao 2010-05-09 22:23:38 EDT
close as not a bug per comment 2

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