Skip to contentSkip to conversation

libselinux mountpoint changing patch.

PATCH Daniel J Walsh 4 participants 13 messages May 3, 2011 – Aug 22, 2011 SELinux security module

lore
Share & tools
lore
#0 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The Fedora Distribution is looking to standardize kernel subsystem file systems to be mounted under /sys/fs. They would like us to move /selinux to /sys/fs/selinux. This patch changes libselinux in the following ways:

1. load_policy will first check if /sys/fs/selinux exists and mount the selinuxfs at this location, if it does not exists it will fall back to mounting the file system at /selinux (if it exists).

2. The init functions of selinux will now check if /sys/fs/selinux is mounted, if it is and has an SELinuxfs mounted on it, the code will then check if the selinuxfs is mounted rw, if it is, libselinux will set the mountpoint, if it is readonly, libselinux will return no mountpoint. If /sys/fs/selinux does not exists, the same check will be done for /selinux and finally for an entry in /proc/mounts.

NOTE: We added the check for RO, to allow tools like mock to be able to tell a chroot that SELinux is disabled while enforcing it outside the chroot.

# getenforce
Enabled
# mount -t selinuxfs -o remount,ro selinuxfs /var/chroot/selinux
# chroot /var/chroot
# getenforce
Disabled

3. In order to make this work, I needed to stop enabled from checking if /proc/filesystem for entries if selinux_mnt did not exist. Now enabeled checks if selinux_mnt has been discovered otherwise it will report selinux disabled.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAk3AFkAACgkQrlYvE4MpobNHEQCgqiU1yNXW/6hTX8VnzprqY/mY xvIAoKVSas1YPoAjVozqOiqnDjWC3Ixq
=TZcV
-----END PGP SIGNATURE-----

libselinux/src/enabled.c +0 -33
index b3c8c47..018c787 100644
@@ -11,10 +11,6 @@
 
 int is_selinux_enabled(void)
 {
-	char *buf=NULL;
-	FILE *fp;
-	ssize_t num;
-	size_t len;
 	int enabled = 0;
 	security_context_t con;
 
@@ -32,37 +28,8 @@ int is_selinux_enabled(void)
 				enabled = 0;
 			freecon(con);
 		}
-		return enabled;
         }
 
-	/* Drop back to detecting it the long way. */
-	fp = fopen("/proc/filesystems", "r");
-	if (!fp)
-		return -1;
-
-	__fsetlocking(fp, FSETLOCKING_BYCALLER);
-	while ((num = getline(&buf, &len, fp)) != -1) {
-		if (strstr(buf, "selinuxfs")) {
-			enabled = 1;
-			break;
-		}
-	}
-
-	if (num < 0)
-		goto out;
-
-	/* Since an selinux file system is available, we consider
-	 * selinux enabled. If getcon_raw fails, selinux is still
-	 * enabled. We only consider it disabled if no policy is loaded. */
-	if (getcon_raw(&con) == 0) {
-		if (!strcmp(con, "kernel"))
-			enabled = 0;
-		freecon(con);
-	}
-
-      out:
-	free(buf);
-	fclose(fp);
 	return enabled;
 }
 
libselinux/src/init.c +30 -14

74 lines not on this page · raw message

libselinux/src/load_policy.c +14 -4
index 83d2143..4078f69 100644
@@ -369,7 +369,17 @@ int selinux_init_load_policy(int *enforce)
 	 * Check for the existence of SELinux via selinuxfs, and 
 	 * mount it if present for use in the calls below.  
 	 */
-	if (mount("selinuxfs", SELINUXMNT, "selinuxfs", 0, 0) < 0 && errno != EBUSY) {
+	char *mntpoint = NULL;
+	if (mount("selinuxfs", SELINUXMNT, "selinuxfs", 0, 0) == 0 || errno == EBUSY) {
+		mntpoint = SELINUXMNT;
+	} else { 
+		/* check old mountpoint */
+		if (mount("selinuxfs", "/selinux", "selinuxfs", 0, 0) == 0 || errno == EBUSY) {
+			mntpoint = "/selinux";
+		}
+	} 
+
+	if (! mntpoint ) {
 		if (errno == ENODEV) {
 			/*
 			 * SELinux was disabled in the kernel, either
@@ -384,8 +394,8 @@ int selinux_init_load_policy(int *enforce)
 		}
                 
 		goto noload;
-	}
-	set_selinuxmnt(SELINUXMNT);
+	} 
+	set_selinuxmnt(mntpoint);
 
 	/*
 	 * Note:  The following code depends on having selinuxfs 
@@ -397,7 +407,7 @@ int selinux_init_load_policy(int *enforce)
 		rc = security_disable();
 		if (rc == 0) {
 			/* Successfully disabled, so umount selinuxfs too. */
-			umount(SELINUXMNT);
+			umount(selinux_mnt);
 			fini_selinuxmnt();
 		}
 		/*
libselinux/src/policy.h +1 -1
index 10e8712..76f968e 100644
@@ -13,7 +13,7 @@
 #define SELINUX_MAGIC 0xf97cff8c
 
 /* Preferred selinux mount location */
-#define SELINUXMNT "/selinux"
+#define SELINUXMNT "/sys/fs/selinux"
 
 /* selinuxfs mount point */
 extern char *selinux_mnt;
#1 lore raw
Quoted 18 lines · Daniel J Walsh

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The Fedora Distribution is looking to standardize kernel subsystem file systems to be mounted under /sys/fs. They would like us to move /selinux to /sys/fs/selinux. This patch changes libselinux in the following ways:

1. load_policy will first check if /sys/fs/selinux exists and mount the selinuxfs at this location, if it does not exists it will fall back to mounting the file system at /selinux (if it exists).

2. The init functions of selinux will now check if /sys/fs/selinux is mounted, if it is and has an SELinuxfs mounted on it, the code will then check if the selinuxfs is mounted rw, if it is, libselinux will set the mountpoint, if it is readonly, libselinux will return no mountpoint. If /sys/fs/selinux does not exists, the same check will be done for /selinux and finally for an entry in /proc/mounts.

Quoted 8 lines

NOTE: We added the check for RO, to allow tools like mock to be able to tell a chroot that SELinux is disabled while enforcing it outside the chroot.

# getenforce
Enabled
# mount -t selinuxfs -o remount,ro selinuxfs /var/chroot/selinux

Just to clarify, the right commands to use are:
mount --bind /selinux /var/chroot/selinux
mount -o remount,ro /var/chroot/selinux

Do not use:
mount -t selinuxfs -o ro selinuxfs /var/chroot/selinux
as this will in fact change the flags on /selinux as well. Surprise! Result of there only being a single instance (superblock) of selinuxfs, although you can have multiple vfsmounts of it.

Quoted 8 lines
# chroot /var/chroot
# getenforce
Disabled

3. In order to make this work, I needed to stop enabled from checking if /proc/filesystem for entries if selinux_mnt did not exist. Now enabeled checks if selinux_mnt has been discovered otherwise it will report selinux disabled.

Looks reasonable, minor comments below.

Can we really not get all the necessary information from a single call (as opposed to having to call both statfs() and statvfs())? Isn't statvfs() implemented on Linux by calling the statfs system call?

I'd suggest adding a #define OLDSELINUXMNT "/selinux" to policy.h and using OLDSELINUXMNT in init.c and load_policy.c rather than sprinkling
"/selinux" around multiple places. Wouldn't hurt to #define SELINUXFS
"selinuxfs" as well and replacing all occurrences in init.c and load_policy.c.

As check_mountpoint() sets selinux_mnt, I'd pick a more descriptive name. Actually, could you perhaps fold the logic into set_selinuxmnt()? That would mean the validation would happen when set_selinuxmnt() gets called by load_policy, which isn't strictly necessary but does no harm.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#2 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 47 lines · Stephen Smalley
Quoted 18 lines · Daniel J Walsh

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The Fedora Distribution is looking to standardize kernel subsystem file systems to be mounted under /sys/fs. They would like us to move /selinux to /sys/fs/selinux. This patch changes libselinux in the following ways:

1. load_policy will first check if /sys/fs/selinux exists and mount the selinuxfs at this location, if it does not exists it will fall back to mounting the file system at /selinux (if it exists).

2. The init functions of selinux will now check if /sys/fs/selinux is mounted, if it is and has an SELinuxfs mounted on it, the code will then check if the selinuxfs is mounted rw, if it is, libselinux will set the mountpoint, if it is readonly, libselinux will return no mountpoint. If /sys/fs/selinux does not exists, the same check will be done for /selinux and finally for an entry in /proc/mounts.

Quoted 8 lines

NOTE: We added the check for RO, to allow tools like mock to be able to tell a chroot that SELinux is disabled while enforcing it outside the chroot.

# getenforce
Enabled
# mount -t selinuxfs -o remount,ro selinuxfs /var/chroot/selinux

Just to clarify, the right commands to use are:
mount --bind /selinux /var/chroot/selinux
mount -o remount,ro /var/chroot/selinux

Do not use:
mount -t selinuxfs -o ro selinuxfs /var/chroot/selinux
as this will in fact change the flags on /selinux as well. Surprise! Result of there only being a single instance (superblock) of selinuxfs, although you can have multiple vfsmounts of it.

Quoted 8 lines
# chroot /var/chroot
# getenforce
Disabled

3. In order to make this work, I needed to stop enabled from checking if /proc/filesystem for entries if selinux_mnt did not exist. Now enabeled checks if selinux_mnt has been discovered otherwise it will report selinux disabled.

Quoted 6 lines

Looks reasonable, minor comments below.

Can we really not get all the necessary information from a single call (as opposed to having to call both statfs() and statvfs())? Isn't statvfs() implemented on Linux by calling the statfs system call?

Not that I can see.

Quoted 6 lines

I'd suggest adding a #define OLDSELINUXMNT "/selinux" to policy.h and using OLDSELINUXMNT in init.c and load_policy.c rather than sprinkling
"/selinux" around multiple places. Wouldn't hurt to #define SELINUXFS
"selinuxfs" as well and replacing all occurrences in init.c and load_policy.c.

Ok

Quoted 5 lines

As check_mountpoint() sets selinux_mnt, I'd pick a more descriptive name. Actually, could you perhaps fold the logic into set_selinuxmnt()? That would mean the validation would happen when set_selinuxmnt() gets called by load_policy, which isn't strictly necessary but does no harm.

Done

I have to change set_selinuxmnt to return an int now, though. Does this mean we would need an API version bump? Changing from void return to int?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAk3AJ28ACgkQrlYvE4MpobPMBwCghY08MsDjpufL/NPkFWfC7M6v 9kgAoI8Gi0Z0LROlxPYgtvcShmZkLEKb
=4NO/
-----END PGP SIGNATURE-----

libselinux/include/selinux/selinux.h +1 -1
index f110dcf..644d6d2 100644
@@ -513,7 +513,7 @@ extern int selinux_check_securetty_context(const security_context_t tty_context)
    Normally, this is determined automatically during libselinux 
    initialization, but this is not always possible, e.g. for /sbin/init
    which performs the initial mount of selinuxfs. */
-void set_selinuxmnt(char *mnt);
+int set_selinuxmnt(char *mnt);
 
 /* clear selinuxmnt variable and free allocated memory */
 void fini_selinuxmnt(void);
libselinux/src/enabled.c +0 -33
index b3c8c47..018c787 100644
@@ -11,10 +11,6 @@
 
 int is_selinux_enabled(void)
 {
-	char *buf=NULL;
-	FILE *fp;
-	ssize_t num;
-	size_t len;
 	int enabled = 0;
 	security_context_t con;
 
@@ -32,37 +28,8 @@ int is_selinux_enabled(void)
 				enabled = 0;
 			freecon(con);
 		}
-		return enabled;
         }
 
-	/* Drop back to detecting it the long way. */
-	fp = fopen("/proc/filesystems", "r");
-	if (!fp)
-		return -1;
-
-	__fsetlocking(fp, FSETLOCKING_BYCALLER);
-	while ((num = getline(&buf, &len, fp)) != -1) {
-		if (strstr(buf, "selinuxfs")) {
-			enabled = 1;
-			break;
-		}
-	}
-
-	if (num < 0)
-		goto out;
-
-	/* Since an selinux file system is available, we consider
-	 * selinux enabled. If getcon_raw fails, selinux is still
-	 * enabled. We only consider it disabled if no policy is loaded. */
-	if (getcon_raw(&con) == 0) {
-		if (!strcmp(con, "kernel"))
-			enabled = 0;
-		freecon(con);
-	}
-
-      out:
-	free(buf);
-	fclose(fp);
 	return enabled;
 }
 
libselinux/src/init.c +30 -18

91 lines not on this page · raw message

libselinux/src/load_policy.c +16 -3
index 83d2143..f6eae49 100644
@@ -369,7 +369,17 @@ int selinux_init_load_policy(int *enforce)
 	 * Check for the existence of SELinux via selinuxfs, and 
 	 * mount it if present for use in the calls below.  
 	 */
-	if (mount("selinuxfs", SELINUXMNT, "selinuxfs", 0, 0) < 0 && errno != EBUSY) {
+	char *mntpoint = NULL;
+	if (mount(SELINUXFS, SELINUXMNT, SELINUXFS, 0, 0) == 0 || errno == EBUSY) {
+		mntpoint = SELINUXMNT;
+	} else { 
+		/* check old mountpoint */
+		if (mount(SELINUXFS, OLDSELINUXMNT, SELINUXFS, 0, 0) == 0 || errno == EBUSY) {
+			mntpoint = OLDSELINUXMNT;
+		}
+	} 
+
+	if (! mntpoint ) {
 		if (errno == ENODEV) {
 			/*
 			 * SELinux was disabled in the kernel, either
@@ -384,8 +394,11 @@ int selinux_init_load_policy(int *enforce)
 		}
                 
 		goto noload;
+	} 
+	if (set_selinuxmnt(mntpoint) != 0) {
+		fprintf(stderr, "Mount failed for selinuxfs on %s:  %s\n", mntpoint, strerror(errno));
+		goto noload;
 	}
-	set_selinuxmnt(SELINUXMNT);
 
 	/*
 	 * Note:  The following code depends on having selinuxfs 
@@ -397,7 +410,7 @@ int selinux_init_load_policy(int *enforce)
 		rc = security_disable();
 		if (rc == 0) {
 			/* Successfully disabled, so umount selinuxfs too. */
-			umount(SELINUXMNT);
+			umount(selinux_mnt);
 			fini_selinuxmnt();
 		}
 		/*
libselinux/src/policy.h +5 -1
index 10e8712..bf270b5 100644
@@ -9,11 +9,15 @@
 /* Initial length guess for getting contexts. */
 #define INITCONTEXTLEN 255
 
+/* selinux file system type */
+#define SELINUXFS "selinuxfs"
+
 /* selinuxfs magic number */
 #define SELINUX_MAGIC 0xf97cff8c
 
 /* Preferred selinux mount location */
-#define SELINUXMNT "/selinux"
+#define SELINUXMNT "/sys/fs/selinux"
+#define OLDSELINUXMNT "/selinux"
 
 /* selinuxfs mount point */
 extern char *selinux_mnt;
#3 lore raw
Quoted 10 lines · Daniel J Walsh

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 5 lines · Stephen Smalley

As check_mountpoint() sets selinux_mnt, I'd pick a more descriptive name. Actually, could you perhaps fold the logic into set_selinuxmnt()? That would mean the validation would happen when set_selinuxmnt() gets called by load_policy, which isn't strictly necessary but does no harm.

Quoted 5 lines

Done

I have to change set_selinuxmnt to return an int now, though. Does this mean we would need an API version bump? Changing from void return to int?

Ah, I missed that. We don't want to change the ABI, so I guess you should leave set_selinuxmnt() alone and make this a new function.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#4 lore raw
In reply to Daniel J Walsh
libselinux/src/init.c +1 -1
index a948920..547f1eb 100644
@@ -79,7 +70,7 @@ static void init_selinuxmnt(void)
 		tmp = strchr(p, ' ');
 		if (!tmp)
 			goto out;
-		if (!strncmp(tmp + 1, "selinuxfs ", 10)) {
+		if (!strncmp(tmp + 1, SELINUXFS, 10)) {
 			*tmp = '\0';
 			break;
 		}

This isn't equivalent. I suppose you could do this:
+ if (!strncmp(tmp + 1, SELINUXFS" ", sizeof SELINUXFS)) {

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#5 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 17 lines · Stephen Smalley
libselinux/src/init.c +1 -1
index a948920..547f1eb 100644
@@ -79,7 +70,7 @@ static void init_selinuxmnt(void)
 		tmp = strchr(p, ' ');
 		if (!tmp)
 			goto out;
-		if (!strncmp(tmp + 1, "selinuxfs ", 10)) {
+		if (!strncmp(tmp + 1, SELINUXFS, 10)) {
 			*tmp = '\0';
 			break;
 		}

This isn't equivalent. I suppose you could do this:

libselinux/src/init.c

Quoted 1 line
libselinux/src/init.c +1 -0
+		if (!strncmp(tmp + 1, SELINUXFS" ", sizeof SELINUXFS)) {

Ok one more time...
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAk3ARBQACgkQrlYvE4MpobObeQCgwz+m8Ag8hzTWBuPGzXWXjcu6 xC0An3v6Kzia20ZfKwgV/Hq9sx6TfX7q
=akdW
-----END PGP SIGNATURE-----

libselinux/src/enabled.c +0 -33
index b3c8c47..018c787 100644
@@ -11,10 +11,6 @@
 
 int is_selinux_enabled(void)
 {
-	char *buf=NULL;
-	FILE *fp;
-	ssize_t num;
-	size_t len;
 	int enabled = 0;
 	security_context_t con;
 
@@ -32,37 +28,8 @@ int is_selinux_enabled(void)
 				enabled = 0;
 			freecon(con);
 		}
-		return enabled;
         }
 
-	/* Drop back to detecting it the long way. */
-	fp = fopen("/proc/filesystems", "r");
-	if (!fp)
-		return -1;
-
-	__fsetlocking(fp, FSETLOCKING_BYCALLER);
-	while ((num = getline(&buf, &len, fp)) != -1) {
-		if (strstr(buf, "selinuxfs")) {
-			enabled = 1;
-			break;
-		}
-	}
-
-	if (num < 0)
-		goto out;
-
-	/* Since an selinux file system is available, we consider
-	 * selinux enabled. If getcon_raw fails, selinux is still
-	 * enabled. We only consider it disabled if no policy is loaded. */
-	if (getcon_raw(&con) == 0) {
-		if (!strcmp(con, "kernel"))
-			enabled = 0;
-		freecon(con);
-	}
-
-      out:
-	free(buf);
-	fclose(fp);
 	return enabled;
 }
 
libselinux/src/init.c +38 -16

94 lines not on this page · raw message

libselinux/src/load_policy.c +13 -3
index 83d2143..0961912 100644
@@ -369,7 +369,17 @@ int selinux_init_load_policy(int *enforce)
 	 * Check for the existence of SELinux via selinuxfs, and 
 	 * mount it if present for use in the calls below.  
 	 */
-	if (mount("selinuxfs", SELINUXMNT, "selinuxfs", 0, 0) < 0 && errno != EBUSY) {
+	char *mntpoint = NULL;
+	if (mount(SELINUXFS, SELINUXMNT, SELINUXFS, 0, 0) == 0 || errno == EBUSY) {
+		mntpoint = SELINUXMNT;
+	} else { 
+		/* check old mountpoint */
+		if (mount(SELINUXFS, OLDSELINUXMNT, SELINUXFS, 0, 0) == 0 || errno == EBUSY) {
+			mntpoint = OLDSELINUXMNT;
+		}
+	} 
+
+	if (! mntpoint ) {
 		if (errno == ENODEV) {
 			/*
 			 * SELinux was disabled in the kernel, either
@@ -385,7 +395,7 @@ int selinux_init_load_policy(int *enforce)
                 
 		goto noload;
 	}
-	set_selinuxmnt(SELINUXMNT);
+	set_selinuxmnt(mntpoint);
 
 	/*
 	 * Note:  The following code depends on having selinuxfs 
@@ -397,7 +407,7 @@ int selinux_init_load_policy(int *enforce)
 		rc = security_disable();
 		if (rc == 0) {
 			/* Successfully disabled, so umount selinuxfs too. */
-			umount(SELINUXMNT);
+			umount(selinux_mnt);
 			fini_selinuxmnt();
 		}
 		/*
libselinux/src/policy.h +5 -1
index 10e8712..bf270b5 100644
@@ -9,11 +9,15 @@
 /* Initial length guess for getting contexts. */
 #define INITCONTEXTLEN 255
 
+/* selinux file system type */
+#define SELINUXFS "selinuxfs"
+
 /* selinuxfs magic number */
 #define SELINUX_MAGIC 0xf97cff8c
 
 /* Preferred selinux mount location */
-#define SELINUXMNT "/selinux"
+#define SELINUXMNT "/sys/fs/selinux"
+#define OLDSELINUXMNT "/selinux"
 
 /* selinuxfs mount point */
 extern char *selinux_mnt;
#6 lore raw
In reply to Stephen Smalley
Quoted 15 lines · Stephen Smalley
Quoted 8 lines · Daniel J Walsh

NOTE:  We added the check for RO, to allow tools like mock to be able to tell a chroot that SELinux is disabled while enforcing it outside the chroot.

# getenforce
Enabled
# mount -t selinuxfs -o remount,ro selinuxfs /var/chroot/selinux

Just to clarify, the right commands to use are:
mount --bind /selinux /var/chroot/selinux
mount -o remount,ro /var/chroot/selinux

Quoted 5 lines

Do not use:
mount -t selinuxfs -o ro selinuxfs /var/chroot/selinux
as this will in fact change the flags on /selinux as well.  Surprise! Result of there only being a single instance (superblock) of selinuxfs, although you can have multiple vfsmounts of it.

surprise, this doesn't work either!

# cat mount.F16 | grep selinux
mount --bind /selinux /mnt/F16/sys/fs/selinux/
mount -o remount,ro /mnt/F16/sys/fs/selinux/
# cat /proc/mounts | grep selinux
selinuxfs /selinux selinuxfs ro,relatime 0 0
selinuxfs /mnt/F16/sys/fs/selinux selinuxfs ro,relatime 0 0

crap.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#7 lore raw
Quoted 27 lines · Eric Paris
Quoted 15 lines · Stephen Smalley
Quoted 8 lines · Daniel J Walsh

NOTE: We added the check for RO, to allow tools like mock to be able to tell a chroot that SELinux is disabled while enforcing it outside the chroot.

# getenforce
Enabled
# mount -t selinuxfs -o remount,ro selinuxfs /var/chroot/selinux

Just to clarify, the right commands to use are:
mount --bind /selinux /var/chroot/selinux
mount -o remount,ro /var/chroot/selinux

Quoted 5 lines

Do not use:
mount -t selinuxfs -o ro selinuxfs /var/chroot/selinux
as this will in fact change the flags on /selinux as well. Surprise! Result of there only being a single instance (superblock) of selinuxfs, although you can have multiple vfsmounts of it.

surprise, this doesn't work either!

# cat mount.F16 | grep selinux
mount --bind /selinux /mnt/F16/sys/fs/selinux/
mount -o remount,ro /mnt/F16/sys/fs/selinux/
Quoted 5 lines
# cat /proc/mounts | grep selinux
selinuxfs /selinux selinuxfs ro,relatime 0 0
selinuxfs /mnt/F16/sys/fs/selinux selinuxfs ro,relatime 0 0

crap.

Hmmm...works for me on F14 (yeah, I know - ancient history).

# mkdir -p /var/chroot/selinux
# mount --bind /selinux /var/chroot/selinux
# mount -o remount,ro /var/chroot/selinux
# cat /proc/mounts | grep selinux
none /selinux selinuxfs rw,relatime 0 0
none /var/chroot/selinux selinuxfs ro,relatime 0 0
# echo 0 > /selinux/enforce
# echo 0 > /var/chroot/selinux/enforce 
bash: /var/chroot/selinux/enforce: Read-only file system

Did something change recently in the kernel or mount?

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#8 lore raw
Quoted 46 lines · Stephen Smalley
Quoted 27 lines · Eric Paris
Quoted 15 lines · Stephen Smalley
Quoted 8 lines · Daniel J Walsh

NOTE: We added the check for RO, to allow tools like mock to be able to tell a chroot that SELinux is disabled while enforcing it outside the chroot.

# getenforce
Enabled
# mount -t selinuxfs -o remount,ro selinuxfs /var/chroot/selinux

Just to clarify, the right commands to use are:
mount --bind /selinux /var/chroot/selinux
mount -o remount,ro /var/chroot/selinux

Quoted 5 lines

Do not use:
mount -t selinuxfs -o ro selinuxfs /var/chroot/selinux
as this will in fact change the flags on /selinux as well. Surprise! Result of there only being a single instance (superblock) of selinuxfs, although you can have multiple vfsmounts of it.

surprise, this doesn't work either!

# cat mount.F16 | grep selinux
mount --bind /selinux /mnt/F16/sys/fs/selinux/
mount -o remount,ro /mnt/F16/sys/fs/selinux/
Quoted 5 lines
# cat /proc/mounts | grep selinux
selinuxfs /selinux selinuxfs ro,relatime 0 0
selinuxfs /mnt/F16/sys/fs/selinux selinuxfs ro,relatime 0 0

crap.

Hmmm...works for me on F14 (yeah, I know - ancient history).

# mkdir -p /var/chroot/selinux
# mount --bind /selinux /var/chroot/selinux
# mount -o remount,ro /var/chroot/selinux
# cat /proc/mounts | grep selinux
none /selinux selinuxfs rw,relatime 0 0
none /var/chroot/selinux selinuxfs ro,relatime 0 0
# echo 0 > /selinux/enforce
# echo 0 > /var/chroot/selinux/enforce 
bash: /var/chroot/selinux/enforce: Read-only file system
Quoted 1 line

Did something change recently in the kernel or mount?

mount(8)

under F15 mount does:
mount("selinuxfs", "/mnt/F16/sys/fs/selinux", 0x7f613d1ce7b0, MS_RDONLY|MS_REMOUNT|MS_RELATIME, NULL) = 0

whereas under F14 mount does:
mount("/sleinux", "/var/chroot/selinux", 0x7ff5f154ea69, NS_MGC_VAL|MS_RDONLY|MS_REMOUNT|MS_BIND, NULL) = 0

under F15 I can get it to work if I use the command:

mount -o remount,ro,bind /var/chroot/selinux

now for me to hunt down who owns mount(8)

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#9 lore raw
Quoted 59 lines · Eric Paris
Quoted 46 lines · Stephen Smalley
Quoted 27 lines · Eric Paris
Quoted 15 lines · Stephen Smalley
Quoted 8 lines · Daniel J Walsh

NOTE: We added the check for RO, to allow tools like mock to be able to tell a chroot that SELinux is disabled while enforcing it outside the chroot.

# getenforce
Enabled
# mount -t selinuxfs -o remount,ro selinuxfs /var/chroot/selinux

Just to clarify, the right commands to use are:
mount --bind /selinux /var/chroot/selinux
mount -o remount,ro /var/chroot/selinux

Quoted 5 lines

Do not use:
mount -t selinuxfs -o ro selinuxfs /var/chroot/selinux
as this will in fact change the flags on /selinux as well. Surprise! Result of there only being a single instance (superblock) of selinuxfs, although you can have multiple vfsmounts of it.

surprise, this doesn't work either!

# cat mount.F16 | grep selinux
mount --bind /selinux /mnt/F16/sys/fs/selinux/
mount -o remount,ro /mnt/F16/sys/fs/selinux/
Quoted 5 lines
# cat /proc/mounts | grep selinux
selinuxfs /selinux selinuxfs ro,relatime 0 0
selinuxfs /mnt/F16/sys/fs/selinux selinuxfs ro,relatime 0 0

crap.

Hmmm...works for me on F14 (yeah, I know - ancient history).

# mkdir -p /var/chroot/selinux
# mount --bind /selinux /var/chroot/selinux
# mount -o remount,ro /var/chroot/selinux
# cat /proc/mounts | grep selinux
none /selinux selinuxfs rw,relatime 0 0
none /var/chroot/selinux selinuxfs ro,relatime 0 0
# echo 0 > /selinux/enforce
# echo 0 > /var/chroot/selinux/enforce 
bash: /var/chroot/selinux/enforce: Read-only file system
Quoted 1 line

Did something change recently in the kernel or mount?

mount(8)

under F15 mount does:
mount("selinuxfs", "/mnt/F16/sys/fs/selinux", 0x7f613d1ce7b0, MS_RDONLY|MS_REMOUNT|MS_RELATIME, NULL) = 0

whereas under F14 mount does:
mount("/sleinux", "/var/chroot/selinux", 0x7ff5f154ea69, NS_MGC_VAL|MS_RDONLY|MS_REMOUNT|MS_BIND, NULL) = 0

Quoted 5 lines

under F15 I can get it to work if I use the command:

mount -o remount,ro,bind /var/chroot/selinux

now for me to hunt down who owns mount(8)

Does F15 and later have /etc/mtab? The man page for mount(8) on F14 says that you have to explicitly pass bind on the remount if you lack an /etc/mtab on your system, as mount(8) figures out whether or not it was a bind mount originally from the /etc/mtab entry.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#10 lore raw
Quoted 62 lines · Stephen Smalley
Quoted 61 lines · Eric Paris
Quoted 46 lines · Stephen Smalley
Quoted 27 lines · Eric Paris
Quoted 15 lines · Stephen Smalley
Quoted 8 lines · Daniel J Walsh

NOTE: We added the check for RO, to allow tools like mock to be able to tell a chroot that SELinux is disabled while enforcing it outside the chroot.

# getenforce
Enabled
# mount -t selinuxfs -o remount,ro selinuxfs /var/chroot/selinux

Just to clarify, the right commands to use are:
mount --bind /selinux /var/chroot/selinux
mount -o remount,ro /var/chroot/selinux

Quoted 5 lines

Do not use:
mount -t selinuxfs -o ro selinuxfs /var/chroot/selinux
as this will in fact change the flags on /selinux as well. Surprise! Result of there only being a single instance (superblock) of selinuxfs, although you can have multiple vfsmounts of it.

surprise, this doesn't work either!

# cat mount.F16 | grep selinux
mount --bind /selinux /mnt/F16/sys/fs/selinux/
mount -o remount,ro /mnt/F16/sys/fs/selinux/
Quoted 5 lines
# cat /proc/mounts | grep selinux
selinuxfs /selinux selinuxfs ro,relatime 0 0
selinuxfs /mnt/F16/sys/fs/selinux selinuxfs ro,relatime 0 0

crap.

Hmmm...works for me on F14 (yeah, I know - ancient history).

# mkdir -p /var/chroot/selinux
# mount --bind /selinux /var/chroot/selinux
# mount -o remount,ro /var/chroot/selinux
# cat /proc/mounts | grep selinux
none /selinux selinuxfs rw,relatime 0 0
none /var/chroot/selinux selinuxfs ro,relatime 0 0
# echo 0 > /selinux/enforce
# echo 0 > /var/chroot/selinux/enforce 
bash: /var/chroot/selinux/enforce: Read-only file system
Quoted 1 line

Did something change recently in the kernel or mount?

mount(8)

under F15 mount does:
mount("selinuxfs", "/mnt/F16/sys/fs/selinux", 0x7f613d1ce7b0, MS_RDONLY|MS_REMOUNT|MS_RELATIME, NULL) = 0

whereas under F14 mount does:
mount("/sleinux", "/var/chroot/selinux", 0x7ff5f154ea69, NS_MGC_VAL|MS_RDONLY|MS_REMOUNT|MS_BIND, NULL) = 0

under F15 I can get it to work if I use the command:

Quoted 8 lines
Quoted 3 lines

mount -o remount,ro,bind /var/chroot/selinux

now for me to hunt down who owns mount(8)

Does F15 and later have /etc/mtab? The man page for mount(8) on F14 says that you have to explicitly pass bind on the remount if you lack an /etc/mtab on your system, as mount(8) figures out whether or not it was a bind mount originally from the /etc/mtab entry.

that's it:

# ls -l /etc/mtab
lrwxrwxrwx. 1 root root 12 Aug 19 09:21 /etc/mtab -> /proc/mounts

At least now we know. the right operations (which also work on F14)

mount --bind /selinux /var/chroot/selinux
mount -o remount,ro,bind /var/chroot/selinux

-Eric

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#11 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 81 lines · Eric Paris
Quoted 61 lines · Stephen Smalley
Quoted 60 lines · Eric Paris
Quoted 43 lines · Stephen Smalley
Quoted 26 lines · Eric Paris
Quoted 14 lines · Stephen Smalley
Quoted 7 lines · Daniel J Walsh

NOTE: We added the check for RO, to allow tools like mock to be able to tell a chroot that SELinux is disabled while enforcing it outside the chroot.

# getenforce Enabled # mount -t selinuxfs -o remount,ro
selinuxfs /var/chroot/selinux

Just to clarify, the right commands to use are: mount --bind /selinux /var/chroot/selinux mount -o remount,ro /var/chroot/selinux

Quoted 5 lines

Do not use: mount -t selinuxfs -o ro selinuxfs /var/chroot/selinux as this will in fact change the flags on /selinux as well. Surprise! Result of there only being a single instance (superblock) of selinuxfs, although you can have multiple vfsmounts of it.

surprise, this doesn't work either! # cat mount.F16 | grep selinux mount --bind /selinux /mnt/F16/sys/fs/selinux/ mount -o remount,ro /mnt/F16/sys/fs/selinux/

Quoted 5 lines
# cat /proc/mounts | grep selinux selinuxfs /selinux
selinuxfs ro,relatime 0 0 selinuxfs /mnt/F16/sys/fs/selinux
selinuxfs ro,relatime 0 0

crap.

Hmmm...works for me on F14 (yeah, I know - ancient history).

# mkdir -p /var/chroot/selinux # mount --bind /selinux
/var/chroot/selinux # mount -o remount,ro
/var/chroot/selinux # cat /proc/mounts | grep selinux none
/selinux selinuxfs rw,relatime 0 0 none /var/chroot/selinux
selinuxfs ro,relatime 0 0 # echo 0 > /selinux/enforce # echo
0 > /var/chroot/selinux/enforce bash:
/var/chroot/selinux/enforce: Read-only file system
Quoted 1 line

Did something change recently in the kernel or mount?

mount(8)

under F15 mount does: mount("selinuxfs",
"/mnt/F16/sys/fs/selinux", 0x7f613d1ce7b0,
MS_RDONLY|MS_REMOUNT|MS_RELATIME, NULL) = 0

whereas under F14 mount does: mount("/sleinux", "/var/chroot/selinux", 0x7ff5f154ea69, NS_MGC_VAL|MS_RDONLY|MS_REMOUNT|MS_BIND, NULL) = 0

under F15 I can get it to work if I use the command:

mount -o remount,ro,bind /var/chroot/selinux

Quoted 7 lines
Quoted 1 line

now for me to hunt down who owns mount(8)

Does F15 and later have /etc/mtab? The man page for mount(8) on F14 says that you have to explicitly pass bind on the remount if you lack an /etc/mtab on your system, as mount(8) figures out whether or not it was a bind mount originally from the /etc/mtab entry.

that's it:

# ls -l /etc/mtab lrwxrwxrwx. 1 root root 12 Aug 19 09:21 /etc/mtab
-> /proc/mounts

At least now we know. the right operations (which also work on F14)

mount --bind /selinux /var/chroot/selinux mount -o remount,ro,bind /var/chroot/selinux

Quoted 9 lines

-Eric

-- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

If only the kernel would record this info...

Why not just execute

# mount -t selinuxfs -o ro /selinux /var/chroot/selinux

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk5Sq6wACgkQrlYvE4MpobOOJQCfWgSnW/QS+qZcKyCAcWUF26Zn V+UAnA1dlxW4ZhmOJgKzP9wIoS3/pA2z
=FsRr
-----END PGP SIGNATURE-----

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#12 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 106 lines · Daniel J Walsh
Quoted 84 lines · Eric Paris
Quoted 64 lines · Stephen Smalley
Quoted 63 lines · Eric Paris
Quoted 46 lines · Stephen Smalley
Quoted 28 lines · Eric Paris
Quoted 15 lines · Stephen Smalley
Quoted 7 lines · Daniel J Walsh

NOTE: We added the check for RO, to allow tools like mock to be able to tell a chroot that SELinux is disabled while enforcing it outside the chroot.

# getenforce Enabled # mount -t selinuxfs -o
remount,ro selinuxfs /var/chroot/selinux

Just to clarify, the right commands to use are: mount --bind /selinux /var/chroot/selinux mount -o remount,ro /var/chroot/selinux

Quoted 5 lines

Do not use: mount -t selinuxfs -o ro selinuxfs /var/chroot/selinux as this will in fact change the flags on /selinux as well. Surprise! Result of there only being a single instance (superblock) of selinuxfs,
although you can have multiple vfsmounts of it.

surprise, this doesn't work either! # cat mount.F16 | grep selinux mount --bind /selinux /mnt/F16/sys/fs/selinux/ mount -o remount,ro /mnt/F16/sys/fs/selinux/

Quoted 5 lines
# cat /proc/mounts | grep selinux selinuxfs /selinux 
selinuxfs ro,relatime 0 0 selinuxfs
/mnt/F16/sys/fs/selinux selinuxfs ro,relatime 0 0

crap.

Hmmm...works for me on F14 (yeah, I know - ancient history).

# mkdir -p /var/chroot/selinux # mount --bind /selinux 
/var/chroot/selinux # mount -o remount,ro 
/var/chroot/selinux # cat /proc/mounts | grep selinux none 
/selinux selinuxfs rw,relatime 0 0 none
/var/chroot/selinux selinuxfs ro,relatime 0 0 # echo 0 >
/selinux/enforce # echo 0 > /var/chroot/selinux/enforce
bash: /var/chroot/selinux/enforce: Read-only file system
Quoted 1 line

Did something change recently in the kernel or mount?

mount(8)

under F15 mount does: mount("selinuxfs",
"/mnt/F16/sys/fs/selinux", 0x7f613d1ce7b0,
MS_RDONLY|MS_REMOUNT|MS_RELATIME, NULL) = 0

whereas under F14 mount does: mount("/sleinux", "/var/chroot/selinux", 0x7ff5f154ea69, NS_MGC_VAL|MS_RDONLY|MS_REMOUNT|MS_BIND, NULL) = 0

under F15 I can get it to work if I use the command:

mount -o remount,ro,bind /var/chroot/selinux

Quoted 7 lines
Quoted 1 line

now for me to hunt down who owns mount(8)

Does F15 and later have /etc/mtab? The man page for mount(8) on F14 says that you have to explicitly pass bind on the remount if you lack an /etc/mtab on your system, as mount(8) figures out whether or not it was a bind mount originally from the /etc/mtab entry.

that's it:

# ls -l /etc/mtab lrwxrwxrwx. 1 root root 12 Aug 19 09:21
/etc/mtab -> /proc/mounts

At least now we know. the right operations (which also work on F14)

mount --bind /selinux /var/chroot/selinux mount -o remount,ro,bind /var/chroot/selinux

Quoted 7 lines

-Eric

-- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

If only the kernel would record this info...

Why not just execute

# mount -t selinuxfs -o ro /selinux /var/chroot/selinux
Quoted 4 lines

-- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

Never mind that breaks.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk5SrFsACgkQrlYvE4MpobORUwCfU0dMWCt/v2DeMYNHeo/Ax5W8 PEMAn0BPiOA/6w5t/00dF+AWhCX8JyKi
=NiiC
-----END PGP SIGNATURE-----

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.