Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instead of using lgetxattr on a fd path (/proc/self/fd/<num>), directly use `fgetxattr`. It turns out that `lgetxattr` does not return a consistent result on all kernel version when used on a filedescriptor path. This is often not an issue. It would just mean that virt-handler would label a few devices in its namespces on every start, even if it would not have to. But on some operating systems (e.g. Centos8, but not Centos8 stream) we then fail on the not needed relabeling attempt. Before: lgetxattr sometimes returns weird resources on a file descroptor path: ``` Error: error relabeling file /proc/self/fd/7 from label system_u:system_r:spc_t:s0 to label system_u:object_r:container_file_t:s0. Reason: operation not supported [...] error relabeling file /proc/self/fd/7 from label system_u:system_r:spc_t:s0 to label system_u:object_r:container_file_t:s0. Reason: operation not supported ``` After: Successful detection of matching labels results in no action: ``` root@virt-handler-gk5vb:~# ./virt-chroot selinux relabel system_u:object_r:container_file_t:s0 /dev/net/tun ``` Mismatches are still detected as expected: ``` root@virt-handler-gk5vb:~# ./virt-chroot selinux relabel system_u:object_r:container_file_t:s1 /dev/net/tun Error: error relabeling file /proc/self/fd/7 from label system_u:object_r:container_file_t:s0 to label system_u:object_r:container_file_t:s1. Reason: operation not supported [...] error relabeling file /proc/self/fd/7 from label system_u:object_r:container_file_t:s0 to label system_u:object_r:container_file_t:s1. Reason: operation not supported ``` Signed-off-by: Roman Mohr <[email protected]>
- Loading branch information