selinux: allow reading labels before policy is loaded
PATCH 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 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
security/selinux/hooks.c +5 -1
@@ -3334,7 +3334,11 @@ static int selinux_inode_getsecurity(struct inode *inode, const char *name, voidchar *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
Apologies, this should have had the subject line:
Quoted 1 line
[PATCH v3] selinux: allow reading labels before policy is loaded
I missed passing -v 3 to git format-patch.
Quoted 10 lines · Jonathan Lebon
This patch does for
getxattrwhat commit3e3e24b42043("selinux: allow labeling before policy is loaded") did forsetxattr; 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]
Quoted 8 lines
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
Signed-off-by Jonathan Lebon <[email protected]>
You might want to fix the comment style below, but otherwise,
Quoted 9 lines
--- security/selinux/hooks.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)security/selinux/hooks.c +0
-0
security/selinux/hooks.c static int selinux_inode_getsecurity(struct inode *inode, const char *name, void · line 3339
Quoted 7 lines
security/selinux/hooks.c +3
-1@@ -3334,7 +3334,11 @@ static int selinux_inode_getsecurity(struct inode *inode, const char *name, voidchar *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. +*/
coding-style says that multi-line comment style is to use a separate line for the opening /* unless in net/
Quoted 8 lines
security/selinux/hooks.c +2
-1+if (!selinux_initialized (&selinux_state) || +strcmp (name,XATTR_SELINUX_SUFFIX ))return -EOPNOTSUPP ;/* -- 2.25.4
Quoted 3 lines · Stephen Smalley
You might want to fix the comment style below, but otherwise,
Acked-by Stephen Smalley <[email protected]>
Fixed in v4!
Thank you and Ondrej for the reviews.