Skip to content

Commit c8e2226

Browse files
jlebonpcmoore
authored andcommitted
selinux: allow reading labels before policy is loaded
This patch does for `getxattr` what commit 3e3e24b ("selinux: allow labeling before policy is loaded") did for `setxattr`; it allows querying the current SELinux label on disk before the policy is loaded. One of the motivations described in that commit message also drives this patch: for Fedora CoreOS (and eventually RHEL CoreOS), we want to be able to move the root filesystem for example, from xfs to ext4 on RAID, on first boot, at initrd time.[1] Because such an operation works at the filesystem level, we need to be able to read the SELinux labels first from the original root, and apply them to the files of the new root. The previous commit enabled the second part of this process; this commit enables the first part. [1] coreos/fedora-coreos-tracker#94 Acked-by: Stephen Smalley <[email protected]> Signed-off-by: Jonathan Lebon <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent b3a9e3b commit c8e2226

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

security/selinux/hooks.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3332,7 +3332,12 @@ static int selinux_inode_getsecurity(struct inode *inode, const char *name, void
33323332
char *context = NULL;
33333333
struct inode_security_struct *isec;
33343334

3335-
if (strcmp(name, XATTR_SELINUX_SUFFIX))
3335+
/*
3336+
* If we're not initialized yet, then we can't validate contexts, so
3337+
* just let vfs_getxattr fall back to using the on-disk xattr.
3338+
*/
3339+
if (!selinux_initialized(&selinux_state) ||
3340+
strcmp(name, XATTR_SELINUX_SUFFIX))
33363341
return -EOPNOTSUPP;
33373342

33383343
/*

0 commit comments

Comments
 (0)