On Mon, Sep 5, 2022 at 8:52 PM Frederick Grose <fgrose(a)gmail.com> wrote:
I have a general scoping question on setting SELinux context on
files/directories during early boot.
I'm working on a feature in dracut to implement general stacking of filesystem
hierarchies via OverlayFS for the root filesystem within the dmsquash-live-root module.
How should I address the setting of context for new files, directories, or links needed
to assemble the components for the OverlayFS mount?
For example, when I
mkdir -m 0755 -p --context=system_u:object_r:root_t:s0 /run/somemountpoint
I get this warning in the journal:
mkdir: warning: ignoring --context; it requires an SELinux/SMACK-enabled kernel
If the SELinux code is not active at this early stage, what is to be done?
Tools that use libselinux to set labels will probably refuse to work
with SELinux policy not yet loaded, but if you have a recent enough
kernel (5.5+), it should be possible to set the extended attribute
manually - for example using setfattr:
mkdir -m 0755 -p /run/somemountpoint
setfattr -n security.selinux -v system_u:object_r:root_t:s0 /run/somemountpoint
Senior Software Engineer, Linux Security - SELinux kernel
Red Hat, Inc.