Skip to contentSkip to conversation

security: selinux: allow changing labels for cgroupfs

PATCH Applied Antonio Murdaca 4 participants 4 messages Feb 2, 2017 – Feb 8, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 security: selinux: allow changing labels for cgroupfs

This patch allows changing labels for cgroup mounts. Previously, running chcon on cgroupfs would throw an "Operation not supported". This patch specifically whitelist cgroupfs.

The patch could also allow containers to write only to the systemd cgroup for instance, while the other cgroups are kept with cgroup_t label.

---
Changes in v2:
- whitelist cgroup2 fs type

 security/selinux/hooks.c | 2 ++
 1 file changed, 2 insertions(+)
security/selinux/hooks.c +2 -0
index 3b955c6..2789f0a 100644
@@ -480,6 +480,8 @@ static int selinux_is_sblabel_mnt(struct super_block *sb)
 		sbsec->behavior == SECURITY_FS_USE_NATIVE ||
 		/* Special handling. Genfs but also in-core setxattr handler */
 		!strcmp(sb->s_type->name, "sysfs") ||
+		!strcmp(sb->s_type->name, "cgroup") ||
+		!strcmp(sb->s_type->name, "cgroup2") ||
 		!strcmp(sb->s_type->name, "pstore") ||
 		!strcmp(sb->s_type->name, "debugfs") ||
 		!strcmp(sb->s_type->name, "tracefs") ||
Signature · 1 line
2.9.3
#1 lore raw

We need this patch set to tighten security inside of containers to only allow certain directories in the cgroup file system to be used by the containers. In order to make this work, SELinux policy also needs to be modified.

Quoted 28 lines · Antonio Murdaca

This patch allows changing labels for cgroup mounts. Previously, running chcon on cgroupfs would throw an "Operation not supported". This patch specifically whitelist cgroupfs.

The patch could also allow containers to write only to the systemd cgroup for instance, while the other cgroups are kept with cgroup_t label.

---
Changes in v2:
- whitelist cgroup2 fs type

 security/selinux/hooks.c | 2 ++
 1 file changed, 2 insertions(+)
security/selinux/hooks.c +2 -0
index 3b955c6..2789f0a 100644
@@ -480,6 +480,8 @@ static int selinux_is_sblabel_mnt(struct super_block *sb)
 		sbsec->behavior == SECURITY_FS_USE_NATIVE ||
 		/* Special handling. Genfs but also in-core setxattr handler */
 		!strcmp(sb->s_type->name, "sysfs") ||
+		!strcmp(sb->s_type->name, "cgroup") ||
+		!strcmp(sb->s_type->name, "cgroup2") ||
 		!strcmp(sb->s_type->name, "pstore") ||
 		!strcmp(sb->s_type->name, "debugfs") ||
 		!strcmp(sb->s_type->name, "tracefs") ||
Acked-by on v2 1/1
#2 lore raw
In reply to Antonio Murdaca
Quoted 11 lines · Antonio Murdaca

This patch allows changing labels for cgroup mounts. Previously, running
chcon on cgroupfs would throw an "Operation not supported". This patch
specifically whitelist cgroupfs.

The patch could also allow containers to write only to the systemd cgroup
for instance, while the other cgroups are kept with cgroup_t label.

Quoted 22 lines

---
Changes in v2:
  - whitelist cgroup2 fs type

 security/selinux/hooks.c | 2 ++

 1 file changed, 2 insertions(+)
security/selinux/hooks.c +0 -0
index 3b955c6..2789f0a 100644
@@ -480,6 +480,8 @@ static int selinux_is_sblabel_mnt(struct
 super_block *sb)

  sbsec->behavior == SECURITY_FS_USE_NATIVE || /* Special handling. Genfs but also in-core setxattr handler */
  !strcmp(sb->s_type->name, "sysfs") ||

security/selinux/hooks.c +2 -0
+		!strcmp(sb->s_type->name, "cgroup") ||
+		!strcmp(sb->s_type->name, "cgroup2") ||
 		!strcmp(sb->s_type->name, "pstore") ||
 		!strcmp(sb->s_type->name, "debugfs") ||
 		!strcmp(sb->s_type->name, "tracefs") ||
maintainer Applied
#3 lore raw
In reply to Antonio Murdaca
Quoted 7 lines · Antonio Murdaca

This patch allows changing labels for cgroup mounts. Previously, running chcon on cgroupfs would throw an "Operation not supported". This patch specifically whitelist cgroupfs.

The patch could also allow containers to write only to the systemd cgroup for instance, while the other cgroups are kept with cgroup_t label.

Quoted 7 lines

---
Changes in v2:
- whitelist cgroup2 fs type

 security/selinux/hooks.c | 2 ++
 1 file changed, 2 insertions(+)

Merged into selinux/next, thanks.

Quoted 15 lines
security/selinux/hooks.c +2 -1
index 3b955c6..2789f0a 100644
@@ -480,6 +480,8 @@ static int selinux_is_sblabel_mnt(struct super_block *sb)
                sbsec->behavior == SECURITY_FS_USE_NATIVE ||
                /* Special handling. Genfs but also in-core setxattr handler */
                !strcmp(sb->s_type->name, "sysfs") ||
+               !strcmp(sb->s_type->name, "cgroup") ||
+               !strcmp(sb->s_type->name, "cgroup2") ||
                !strcmp(sb->s_type->name, "pstore") ||
                !strcmp(sb->s_type->name, "debugfs") ||
                !strcmp(sb->s_type->name, "tracefs") ||
--

2.9.3

Signature · 7 lines
paul moore
www.paul-moore.com
_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected]
To get help, send an email containing "help" to [email protected]