xattr/extended attributes not settable for file in /tmp while in $home on same mount works fine

3.2k views Asked by At

I am playing with extended file attributes under Linux/Fedora and I am currently stumbling a bit since I cannot add/change attributes for files in /tmp while in my home it is working fine - while both paths are on the same mount point, i.e.,

/dev/mapper/fedora-root on / type ext4 (rw,relatime,seclabel,data=ordered)

for example, I can successful add and retrieve a attribute for files in my home directory, e.g.,

> setfattr -n user.test.md5 -v 58d8e4cd0e60facf386838cbe8b11767 ~/foo.bar
> getfattr -n user.test.md5 ~/foo.bar 
  # file: foo.bar
  user.test.md5="58d8e4cd0e60facf386838cbe8b11767"

However, the same fails for the same file in /tmp.

> cp ~/foo.bar /tmp/foo.bar
> setfattr -n user.test.md5 -v 58d8e4cd0e60facf386838cbe8b11767 /tmp/foo.bar 
  setfattr: /tmp/foo.bar: Operation not supported

I assumed, that the support for extended attributes only depends on the filesystem mounted 'correctly' with xattr support. However, it seems also be directory(??) dependent and I wonder, what prevents me from setting extended attributes in /tmp and how I can change it? (It seems not to be SELinux related - at least I did not find anything in the audit logs.)

2

There are 2 answers

0
THX On BEST ANSWER

/tmp was not as I naively assumed mounted plainly but is mounted as tmpfs, that apparently does not support extended attributes

tmpfs on /tmp type tmpfs (rw,seclabel)

Thanks to twalberg!

0
Chin Tzung Cheng On

tmpfs can support extended attributes if you enable CONFIG_TMPFS_XATTR in the kernel config. As of version 5.9.3 this enables support only for the trusted.* and security.* namespaces, so your setfattr -n user.test.md5 command would still fail.