Skip to contentSkip to conversation

Mounting /sys within libselinux?

PATCH Sven Vermeulen 1 participant 1 message May 5, 2012 SELinux security module

lore
Share & tools
lore
#0 lore raw

Hi guys,

Since selinux_init_load_policy tries to mount the selinuxfs on /sys/fs/selinux, it of course fails when /sys is not available yet. It currently falls back to /selinux then, but what about just mounting /sys there?

Something akin to the following?

Wkr,
Sven Vermeulen

src/load_policy.c +10 -2
diff -ur libselinux-2.1.9.orig/src/load_policy.c libselinux-2.1.9/src/load_policy.c
@@ -370,8 +370,16 @@
 	 * mount it if present for use in the calls below.  
 	 */
 	char *mntpoint = NULL;
-	if (mount(SELINUXFS, SELINUXMNT, SELINUXFS, 0, 0) == 0 || errno == EBUSY) {
-		mntpoint = SELINUXMNT;
+	/* 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) {
+			mntpoint = SELINUXMNT;
+		} else {
+			/* check old mountpoint */
+			if (mount(SELINUXFS, OLDSELINUXMNT, SELINUXFS, 0, 0) == 0 || errno == EBUSY) {
+				mntpoint = OLDSELINUXMNT;
+			}
+		}
 	} else {
 		/* check old mountpoint */
 		if (mount(SELINUXFS, OLDSELINUXMNT, SELINUXFS, 0, 0) == 0 || errno == EBUSY) {

--
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.