Skip to content

Commit 7fa2e79

Browse files
rhvgoyalpcmoore
authored andcommitted
selinux: Allow context mounts for unpriviliged overlayfs
Now overlayfs allow unpriviliged mounts. That is root inside a non-init user namespace can mount overlayfs. This is being added in 5.11 kernel. Giuseppe tried to mount overlayfs with option "context" and it failed with error -EACCESS. $ su test $ unshare -rm $ mkdir -p lower upper work merged $ mount -t overlay -o lowerdir=lower,workdir=work,upperdir=upper,userxattr,context='system_u:object_r:container_file_t:s0' none merged This fails with -EACCESS. It works if option "-o context" is not specified. Little debugging showed that selinux_set_mnt_opts() returns -EACCESS. So this patch adds "overlay" to the list, where it is fine to specific context from non init_user_ns. Reported-by: Giuseppe Scrivano <gscrivan@redhat.com> Signed-off-by: Vivek Goyal <vgoyal@redhat.com> [PM: trimmed the changelog from the description] Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent a38fd87 commit 7fa2e79

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

security/selinux/hooks.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,8 @@ static int selinux_set_mnt_opts(struct super_block *sb,
760760
if (sb->s_user_ns != &init_user_ns &&
761761
strcmp(sb->s_type->name, "tmpfs") &&
762762
strcmp(sb->s_type->name, "ramfs") &&
763-
strcmp(sb->s_type->name, "devpts")) {
763+
strcmp(sb->s_type->name, "devpts") &&
764+
strcmp(sb->s_type->name, "overlay")) {
764765
if (context_sid || fscontext_sid || rootcontext_sid ||
765766
defcontext_sid) {
766767
rc = -EACCES;

0 commit comments

Comments
 (0)