Skip to contentSkip to conversation

libselinux: mount selinuxfs noexec and nosuid

PATCH Applied Topi Miettinen 3 participants 3 messages Apr 28, 2020 – May 4, 2020 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 libselinux: mount selinuxfs noexec and nosuid

Mount selinuxfs with mount flags noexec and nosuid. It's not likely that this has any effect, but it's visually more pleasing.

Option nodev can't be used because of /sys/fs/selinux/null device, which is used by Android.

---
 libselinux/src/load_policy.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
libselinux/src/load_policy.c +2 -1
index fa1a3bf1..2aea826f 100644
@@ -279,7 +279,8 @@ int selinux_init_load_policy(int *enforce)
 	const char *mntpoint = NULL;
 	/* First make sure /sys is mounted */
 	if (mount("sysfs", "/sys", "sysfs", 0, 0) == 0 || errno == EBUSY) {
-		if (mount(SELINUXFS, SELINUXMNT, SELINUXFS, 0, 0) == 0 || errno == EBUSY) {
+		/* MS_NODEV can't be set because of /sys/fs/selinux/null device, used by Android */
+		if (mount(SELINUXFS, SELINUXMNT, SELINUXFS, MS_NOEXEC | MS_NOSUID, 0) == 0 || errno == EBUSY) {
 			mntpoint = SELINUXMNT;
 		} else {
 			/* check old mountpoint */
Signature · 1 line
2.26.2
#2 lore raw
In reply to Topi Miettinen
Quoted 8 lines · Topi Miettinen

Mount selinuxfs with mount flags noexec and nosuid. It's not likely that this has any effect, but it's visually more pleasing.

Option nodev can't be used because of /sys/fs/selinux/null device, which is used by Android.

Applied.

Quoted 18 lines
---
 libselinux/src/load_policy.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
libselinux/src/load_policy.c +2 -1
index fa1a3bf1..2aea826f 100644
@@ -279,7 +279,8 @@ int selinux_init_load_policy(int *enforce)
 	const char *mntpoint = NULL;
 	/* First make sure /sys is mounted */
 	if (mount("sysfs", "/sys", "sysfs", 0, 0) == 0 || errno == EBUSY) {
-		if (mount(SELINUXFS, SELINUXMNT, SELINUXFS, 0, 0) == 0 || errno == EBUSY) {
+		/* MS_NODEV can't be set because of /sys/fs/selinux/null device, used by Android */
+		if (mount(SELINUXFS, SELINUXMNT, SELINUXFS, MS_NOEXEC | MS_NOSUID, 0) == 0 || errno == EBUSY) {
 			mntpoint = SELINUXMNT;
 		} else {
 			/* check old mountpoint */