Skip to contentSkip to conversation

selinux: allow reading labels before policy is loaded

PATCH In review Jonathan Lebon 2 participants 3 messages May 28, 2020 – Jun 24, 2020 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 selinux: allow reading labels before policy is loaded

This patch does for getxattr what commit 3e3e24b42043 ("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] https://github.com/coreos/fedora-coreos-tracker/issues/94

---
 security/selinux/hooks.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
security/selinux/hooks.c +6 -1
index 0b4e32161b7..25b3403711d 100644
@@ -3334,7 +3334,12 @@ static int selinux_inode_getsecurity(struct inode *inode, const char *name, void
 	char *context = NULL;
 	struct inode_security_struct *isec;
 
-	if (strcmp(name, XATTR_SELINUX_SUFFIX))
+	/*
+	 * If we're not initialized yet, then we can't validate contexts, so
+	 * just let vfs_getxattr fall back to using the on-disk xattr.
+	 */
+	if (!selinux_initialized(&selinux_state) ||
+	    strcmp(name, XATTR_SELINUX_SUFFIX))
 		return -EOPNOTSUPP;
 
 	/*
Signature · 1 line
2.25.4
maintainer
#1 lore raw
Quoted 15 lines · Jonathan Lebon

This patch does for getxattr what commit 3e3e24b42043 ("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.

Quoted 7 lines

[1] https://github.com/coreos/fedora-coreos-tracker/issues/94

---
 security/selinux/hooks.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Thanks. This looks reasonable to me, but since it was posted only a few days before the merge window was opened it needs to wait until after the merge window closes. I'll merge it into selinux/next then.

Quoted 20 lines
security/selinux/hooks.c +6 -2
index 0b4e32161b7..25b3403711d 100644
@@ -3334,7 +3334,12 @@ static int selinux_inode_getsecurity(struct inode *inode, const char *name, void
        char *context = NULL;
        struct inode_security_struct *isec;
 
-       if (strcmp(name, XATTR_SELINUX_SUFFIX))
+       /*
+        * If we're not initialized yet, then we can't validate contexts, so
+        * just let vfs_getxattr fall back to using the on-disk xattr.
+        */
+       if (!selinux_initialized(&selinux_state) ||
+           strcmp(name, XATTR_SELINUX_SUFFIX))
                return -EOPNOTSUPP;
 
        /*
--

2.25.4

Signature · 2 lines
paul moore
www.paul-moore.com
maintainer
#2 lore raw
Quoted 24 lines · Paul Moore
Quoted 15 lines · Jonathan Lebon

This patch does for getxattr what commit 3e3e24b42043 ("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.

Quoted 7 lines

[1] https://github.com/coreos/fedora-coreos-tracker/issues/94

---
 security/selinux/hooks.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
Quoted 3 lines

Thanks. This looks reasonable to me, but since it was posted only a few days before the merge window was opened it needs to wait until after the merge window closes. I'll merge it into selinux/next then.

I just merged this into selinux/next - thanks!

Signature · 2 lines
paul moore
www.paul-moore.com