Skip to contentSkip to conversation

patch for libselinux1

PATCH Russell Coker 2 participants 4 messages Mar 23, 2004 – Mar 24, 2004 SELinux security module

lore
Share & tools
lore
#0 lore raw

If you do "mount selinuxfs /selinux -t selinuxfs" then things don't work, it sees the first "selinuxfs" in /proc/mounts and then takes the last string from the previous line as the mount point.

I have attached a patch.

It's not a significant issue for Fedora at the moment as no-one will be mounting /selinux by hand (I hope). But it's already become an issue for Debian (I've uploaded a fixed package to Debian already).

Signature · 4 lines
http://www.coker.com.au/selinux/   My NSA Security Enhanced Linux packages
http://www.coker.com.au/bonnie++/  Bonnie++ hard drive benchmark
http://www.coker.com.au/postal/    Postal SMTP/POP benchmark
http://www.coker.com.au/~russell/  My home page
src/init.c +19 -21
@@ -6,6 +6,7 @@
 #include <errno.h>
 #include <ctype.h>
 #include <asm/page.h>
+#include <stdio.h>
 
 char *selinux_mnt = NULL;
 
@@ -15,14 +16,14 @@
 {
 	char *buf, *p;
 	size_t size;
-	int fd;
+	FILE *fp;
 	ssize_t ret;
 
 	if (selinux_mnt)
 		return;
 
-	fd = open("/proc/mounts", O_RDONLY);
-	if (fd < 0)
+	fp = fopen("/proc/mounts", "r");
+	if (!fp)
 		return;
 
 	size = PAGE_SIZE;
@@ -32,30 +33,27 @@
 		
 	memset(buf, 0, size);
 
-	ret = read(fd, buf, size - 1);
-	if (ret < 0)
-		goto out2;
-
-	p = strstr(buf, "selinuxfs");
-	if (!p)
-		goto out2;
-
-	p--;
-	*p = 0;
-	p--;
-
-	while (p > buf && !isspace(*p))
-		p--;
-
-	if (isspace(*p))
-		p++;
+	while(fgets(buf, size - 1, fp))
+	{
+		char *tmp;
+		p = strchr(buf, ' ');
+		if(p)
+		{
+			p++;
+			tmp = strchr(p, ' ');
+		}
+		if(tmp && !strncmp(tmp + 1, "selinuxfs ", 10))
+		{
+			*tmp = '\0';
+		}
+	}
 
 	selinux_mnt = strdup(p);
 
 out2:
 	free(buf);
 out:
-	close(fd);
+	fclose(fp);
 	return;
 
 }
#1 lore raw
Quoted 9 lines · Russell Coker

If you do "mount selinuxfs /selinux -t selinuxfs" then things don't work, it sees the first "selinuxfs" in /proc/mounts and then takes the last string from the previous line as the mount point.

I have attached a patch.

It's not a significant issue for Fedora at the moment as no-one will be mounting /selinux by hand (I hope). But it's already become an issue for Debian (I've uploaded a fixed package to Debian already).

Your patch has a few bugs in it. How about this one instead?

Signature · 2 lines
Stephen Smalley <[email protected]>
National Security Agency

Index: libselinux/src/init.c
===================================================================
RCS file: /nfshome/pal/CVS/selinux-usr/libselinux/src/init.c,v retrieving revision 1.3

src/init.c +22 -21
diff -u -r1.3 init.c
@@ -6,6 +6,7 @@
 #include <errno.h>
 #include <ctype.h>
 #include <asm/page.h>
+#include <stdio.h>
 
 char *selinux_mnt = NULL;
 
@@ -13,16 +14,15 @@
 
 static void init_selinuxmnt(void)
 {
-	char *buf, *p;
+	char *buf, *bufp, *p;
 	size_t size;
-	int fd;
-	ssize_t ret;
+	FILE *fp;
 
 	if (selinux_mnt)
 		return;
 
-	fd = open("/proc/mounts", O_RDONLY);
-	if (fd < 0)
+	fp = fopen("/proc/mounts", "r");
+	if (!fp)
 		return;
 
 	size = PAGE_SIZE;
@@ -32,30 +32,31 @@
 		
 	memset(buf, 0, size);
 
-	ret = read(fd, buf, size - 1);
-	if (ret < 0)
-		goto out2;
+	while(( bufp = fgets(buf, size, fp)))
+	{
+		char *tmp;
+		p = strchr(buf, ' ');
+		if (!p)
+			goto out2;
+		p++;
+		tmp = strchr(p, ' ');
+		if (!tmp)
+			goto out2;
+		if(!strncmp(tmp + 1, "selinuxfs ", 10)) {
+			*tmp = '\0';
+			break;
+		}
+	}
 
-	p = strstr(buf, "selinuxfs");
-	if (!p)
+	if (!bufp)
 		goto out2;
 
-	p--;
-	*p = 0;
-	p--;
-
-	while (p > buf && !isspace(*p))
-		p--;
-
-	if (isspace(*p))
-		p++;
-
 	selinux_mnt = strdup(p);
 
 out2:
 	free(buf);
 out:
-	close(fd);
+	fclose(fp);
 	return;
 
 }
#2 lore raw
Quoted 5 lines · Stephen Smalley
Quoted 3 lines

It's not a significant issue for Fedora at the moment as no-one will be mounting /selinux by hand (I hope). But it's already become an issue for Debian (I've uploaded a fixed package to Debian already).

Your patch has a few bugs in it. How about this one instead?

Yes, your patch is much better. I've done a new upload to Debian with your patch.

Signature · 9 lines
http://www.coker.com.au/selinux/   My NSA Security Enhanced Linux packages
http://www.coker.com.au/bonnie++/  Bonnie++ hard drive benchmark
http://www.coker.com.au/postal/    Postal SMTP/POP benchmark
http://www.coker.com.au/~russell/  My home page

--
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.
#3 lore raw
Quoted 9 lines · Russell Coker
Quoted 5 lines · Stephen Smalley
Quoted 3 lines

It's not a significant issue for Fedora at the moment as no-one will be mounting /selinux by hand (I hope). But it's already become an issue for Debian (I've uploaded a fixed package to Debian already).

Your patch has a few bugs in it. How about this one instead?

Yes, your patch is much better. I've done a new upload to Debian with your patch.

Also the attached policy patch is needed as fopen() will stat the file.

Signature · 4 lines
http://www.coker.com.au/selinux/   My NSA Security Enhanced Linux packages
http://www.coker.com.au/bonnie++/  Bonnie++ hard drive benchmark
http://www.coker.com.au/postal/    Postal SMTP/POP benchmark
http://www.coker.com.au/~russell/  My home page
global_macros.te renamed from etc/selinux/macros/global_macros.te +3 -3
@@ -23,7 +23,7 @@
 allow $1 proc_t:dir search;
 allow $1 proc_t:{ file lnk_file } read;
 allow $1 self:dir search;
-allow $1 self:file { read write };
+allow $1 self:file { getattr read write };
 ')
 
 ##################################
@@ -37,7 +37,7 @@
 allow $1 proc_t:dir search;
 allow $1 proc_t:lnk_file read;
 allow $1 self:dir search;
-allow $1 self:file read;
+allow $1 self:file { getattr read };
 ')
 
 ##################################
@@ -71,7 +71,7 @@
 allow $1 proc_t:dir search;
 allow $1 proc_t:{ file lnk_file } read;
 allow $1 self:dir search;
-allow $1 self:file { read write };
+allow $1 self:file { getattr read write };
 ')
 
 #################################