Red Hat Bugzilla – Bug 1472709
setfiles now requires "-m" to restore contexts in some chroot environments
Last modified: 2018-02-07 16:06:34 EST
diskimage-builder builds a fedora image within a chroot environment on a host. This is happening on an ubuntu xenial system -- this is part of building images for use by the OpenStack CI environment. We have long had a final step before we create the final image of running "setfiles" within the chroot of the final image to restore contexts so that the image we are building boots quickly 
Unfortunately this stopped working with F26. The setfiles just does nothing at all
# setfiles -d /etc/selinux/targeted/contexts/files/file_contexts /
# echo $?
If I take the F25 setfiles binary and run it, it works. So that got me digging into git history, where I noticed the suspect change where F26 has started using selinux_restorecon .
Reading this change I noticed "-m"
... do not read /proc/mounts to obtain a list of non-seclabel mounts ...
and realised that we're in a chroot environment on a loopback disk on an ubuntu system, so this is probably not matching. So long story short, the "-m" fixed things for me
I get that what is happening with diskimage-builder is pretty uncommon usage, but it is pretty painful having setfiles having no error code or any output indication of what's going on at all without this flag, when it's been working for literally years. I had to first figure out how to break into our vms (because lack of selinux meant nothing could log in), figure out it was selinux at fault, then spend considerable time figuring out that the 'setfiles' was doing nothing now during the build, and then correlating this with git history ...
Maybe the cat is out of the bag; but it would be my suggestion that "-m" should be applied by default on setfiles to maintain the behavior with the prior versions. if anything, a flag should be inverted to turn it off.