Skip to contentSkip to conversation

New Patch for Policycoreutils.

PATCH Daniel J Walsh 3 participants 4 messages Sep 26, 2006 – Sep 29, 2006 SELinux security module

lore
Share & tools
lore
#0 lore raw

I have updated the patch to remove some of the objectionable changes.

Includes Change submitted on the list for checking if policy loaded in avc.py

-i flag to tell restorecon to ignore missing files

-o now takes "-" to allow it to output file list to stdout

Check to make sure restorecon has at least one input file

Build restorecond with -fPIE

fixfiles use "-i" with restorecon, added new command verify to check all files and output only the files with wrong context

seobject needs to have oldserange initialized.

audit2allow/avc.py +9 -0
diff --exclude-from=exclude --exclude='*.po' -N -u -r nsapolicycoreutils/audit2allow/avc.py policycoreutils-1.30.29/audit2allow/avc.py
@@ -357,6 +357,15 @@
                                 break
                             else:
                                 dict.append(i)
+                                
+                    if not found:
+                        regexp = "audit\(\d+\.\d+:\d+\): policy loaded"
+                        m = re.match(regexp, line)
+                        if m !=None:
+                            found =1
+                            dict.append("load_policy")
+                            dict.append("granted")
+                        
                     if found:
                         self.translate(dict)
                         found = 0
restorecon/restorecon.8 +3 -0
diff --exclude-from=exclude --exclude='*.po' -N -u -r nsapolicycoreutils/restorecon/restorecon.8 policycoreutils-1.30.29/restorecon/restorecon.8
@@ -23,6 +23,9 @@
 
 .SH "OPTIONS"
 .TP 
+.B \-i
+ignore files that do not exist
+.TP 
 .B \-f infilename
 infilename contains a list of files to be processed by application. Use \- for stdin.
 .TP 
restorecon/restorecon.c +35 -12

126 lines not on this page · raw message

restorecond/Makefile +3 -3
diff --exclude-from=exclude --exclude='*.po' -N -u -r nsapolicycoreutils/restorecond/Makefile policycoreutils-1.30.29/restorecond/Makefile
@@ -5,14 +5,14 @@
 INITDIR = $(DESTDIR)/etc/rc.d/init.d
 SELINUXDIR = $(DESTDIR)/etc/selinux
 
-CFLAGS ?= -g -Werror -Wall -W
-override CFLAGS += -I$(PREFIX)/include -D_FILE_OFFSET_BITS=64
+CFLAGS ?= -g -Werror -Wall -W 
+override CFLAGS += -I$(PREFIX)/include -D_FILE_OFFSET_BITS=64 -fPIE
 LDLIBS += -lselinux -lsepol -L$(PREFIX)/lib
 
 all: restorecond
 
 restorecond:  restorecond.o utmpwatcher.o stringslist.o
-	$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
+	$(CC) -pie $(LDFLAGS) -o $@ $^ $(LDLIBS)
 
 install: all
 	[ -d $(MANDIR)/man8 ] || mkdir -p $(MANDIR)/man8
scripts/fixfiles +4 -3
diff --exclude-from=exclude --exclude='*.po' -N -u -r nsapolicycoreutils/scripts/fixfiles policycoreutils-1.30.29/scripts/fixfiles
@@ -117,8 +117,8 @@
     exit $?
 fi
 if [ ! -z "$RPMFILES" ]; then
-    for i in `echo $RPMFILES | sed 's/,/ /g'`; do
-	rpmlist $i | ${RESTORECON} ${OUTFILES} ${FORCEFLAG} -R $* -f - 2>&1 >> $LOGFILE
+    for i in `echo "$RPMFILES" | sed 's/,/ /g'`; do
+	rpmlist $i | ${RESTORECON} ${OUTFILES} ${FORCEFLAG} $* -i -f - 2>&1 >> $LOGFILE
     done
     exit $?
 fi
@@ -219,7 +219,7 @@
 # check if they specified both DIRS and RPMFILES
 #
 
-if [ ! -z $RPMFILES ]; then
+if [ ! -z "$RPMFILES" ]; then
     if [ $OPTIND -le $# ]; then
 	    usage
     fi
@@ -236,6 +236,7 @@
 case "$command" in
     restore) restore -p ;;
     check) restore -n -v ;;
+    verify) restore -n -o -;;
     relabel) relabel;;
     *)
     usage
scripts/fixfiles.8 +6 -3
diff --exclude-from=exclude --exclude='*.po' -N -u -r nsapolicycoreutils/scripts/fixfiles.8 policycoreutils-1.30.29/scripts/fixfiles.8
@@ -3,9 +3,9 @@
 fixfiles \- fix file security contexts.
 
 .SH "SYNOPSIS"
-.B fixfiles [-F] [ -R rpmpackagename[,rpmpackagename...] ] [ -C PREVIOUS_FILECONTEXT ] [-l logfile ] [-o outputfile ] { check | restore | [-F] relabel }"
+.B fixfiles [-F] [ -R rpmpackagename[,rpmpackagename...] ] [ -C PREVIOUS_FILECONTEXT ] [-l logfile ] [-o outputfile ] { check | restore | [-F] relabel | verify }"
 
-.B fixfiles [-F] [-l logfile ] [-o outputfile ] { check | restore|[-f] relabel } [[dir/file] ... ] 
+.B fixfiles [-F] [-l logfile ] [-o outputfile ] { check | restore|[-f] relabel | verify } [[dir/file] ... ] 
 
 .SH "DESCRIPTION"
 This manual page describes the
@@ -48,7 +48,7 @@
 One of:
 .TP 
 .B check
-show any incorrect file context labels but do not change them.
+print any incorrect file context labels, showing old and new context, but do not change them.
 .TP 
 .B restore
 change any incorrect file context labels.
@@ -56,6 +56,9 @@
 .B relabel
 Prompt for removal of contents of /tmp directory and then change any inccorect file context labels to match the install file_contexts file.
 .TP 
+.B verify
+List out files with incorrect file context labels, but do not change them.
+.TP 
 .B [[dir/file] ... ] 
 List of files or directories trees that you wish to check file context on.
 
semanage/seobject.py +1 -0
diff --exclude-from=exclude --exclude='*.po' -N -u -r nsapolicycoreutils/semanage/seobject.py policycoreutils-1.30.29/semanage/seobject.py
@@ -486,6 +487,7 @@
 
 	def modify(self, name, roles = [], selevel = "", serange = "", prefix = ""):
 		oldroles = ""
+		oldserange = ""
 		newroles = string.join(roles, ' ');
 		try:
 			if prefix == "" and len(roles) == 0  and serange == "" and selevel == "":
#1 lore raw
Quoted 14 lines · Daniel J Walsh

I have updated the patch to remove some of the objectionable changes.

diff --exclude-from=exclude --exclude='*.po' -N -u -r nsapolicycoreutils/restorecon/restorecon.c policycoreutils-1.30.29/restorecon/restorecon.c

restorecon/restorecon.c +1 -0
@@ -47,6 +48,7 @@
 static char *progname;
 static int errors = 0;
 static int recurse = 0;
+static int file_exist = 1;
 static int force = 0;
 #define STAT_BLOCK_SIZE 1
 static int pipe_fds[2] = { -1, -1 };

restorecon/restorecon.c line 67

Quoted 4 lines
restorecon/restorecon.c +1 -0
@@ -62,6 +64,7 @@
 static int add_exclude(const char *directory)
 {
 	struct stat sb;
+	int len=0;

size_t

restorecon/restorecon.c line 93

Quoted 11 lines
restorecon/restorecon.c +3 -1
 	if (directory == NULL || directory[0] != '/') {
 		fprintf(stderr, "Full path required for exclude: %s.\n",
 			directory);
@@ -85,12 +88,18 @@
 		return 1;
 	}
 
-	excludeArray[excludeCtr].directory = strdup(directory);
+	len = strlen(directory);
+	if (len > 1 &&  directory[len-1] == '/') {
+		excludeArray[excludeCtr].directory = calloc(1,len--);

calloc() can fail.

restorecon/restorecon.c line 264

Quoted 7 lines
restorecon/restorecon.c +2 -1
@@ -249,7 +260,8 @@
 						freecon(scontext);
 						return 1;
 					}
-				}
+				} 
+

Intentional? Make sure you apply make indent after changes.

Quoted 8 lines

diff --exclude-from=exclude --exclude='*.po' -N -u -r nsapolicycoreutils/restorecond/Makefile policycoreutils-1.30.29/restorecond/Makefile

restorecond/Makefile +0 -1
@@ -5,14 +5,14 @@
 INITDIR = $(DESTDIR)/etc/rc.d/init.d
 SELINUXDIR = $(DESTDIR)/etc/selinux
 
-CFLAGS ?= -g -Werror -Wall -W

restorecond/Makefile line 15

Quoted 10 lines
restorecond/Makefile +3 -2
-override CFLAGS += -I$(PREFIX)/include -D_FILE_OFFSET_BITS=64
+CFLAGS ?= -g -Werror -Wall -W 
+override CFLAGS += -I$(PREFIX)/include -D_FILE_OFFSET_BITS=64 -fPIE
 LDLIBS += -lselinux -lsepol -L$(PREFIX)/lib
 
 all: restorecond
 
 restorecond:  restorecond.o utmpwatcher.o stringslist.o
-	$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
+	$(CC) -pie $(LDFLAGS) -o $@ $^ $(LDLIBS)

Shouldn't the -pie go in LDFLAGS, and be overridable for distros that don't support pie?

Quoted 7 lines
restorecond/Makefile +0 -0
 install: all
 	[ -d $(MANDIR)/man8 ] || mkdir -p $(MANDIR)/man8

diff --exclude-from=exclude --exclude='*.po' -N -u -r nsapolicycoreutils/scripts/fixfiles policycoreutils-1.30.29/scripts/fixfiles

scripts/fixfiles line 121

Quoted 7 lines
scripts/fixfiles +2 -2
@@ -117,8 +117,8 @@
     exit $?
 fi
 if [ ! -z "$RPMFILES" ]; then
-    for i in `echo $RPMFILES | sed 's/,/ /g'`; do
-	rpmlist $i | ${RESTORECON} ${OUTFILES} ${FORCEFLAG} -R $* -f - 2>&1 >> $LOGFILE
+    for i in `echo "$RPMFILES" | sed 's/,/ /g'`; do
+	rpmlist $i | ${RESTORECON} ${OUTFILES} ${FORCEFLAG} $* -i -f - 2>&1 >> $LOGFILE

Did you mean to drop -R?

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.
#3 lore raw
In reply to Daniel J Walsh
Quoted 19 lines · Daniel J Walsh

I have updated the patch to remove some of the objectionable changes.

Includes Change submitted on the list for checking if policy loaded in avc.py

(quoted diff) +0 -2
-i flag to tell restorecon to ignore missing files
 
-o now takes "-" to allow it to output file list to stdout

Check to make sure restorecon has at least one input file

Build restorecond with -fPIE

fixfiles use "-i" with restorecon, added new command verify to check all files and output only the files with wrong context

seobject needs to have oldserange initialized.

------------------------------------------------------------------------

<snip>

Quoted 42 lines

diff --exclude-from=exclude --exclude='*.po' -N -u -r nsapolicycoreutils/restorecon/restorecon.c policycoreutils-1.30.29/restorecon/restorecon.c

restorecon/restorecon.c +10 -2
@@ -11,9 +11,10 @@
  * restorecon [-Rnv] pathname...
  * 
  * -e   Specify directory to exclude
+ * -i   Ignore error if file does not exist
  * -n	Do not change any file labels.
  * -v	Show changes in file labels.  
- * -o filename save list of files with incorrect context
+ * -o	filename save list of files with incorrect context
  * -F	Force reset of context to match file_context for customizable files
  *
  * pathname...	The file(s) to label 
@@ -47,6 +48,7 @@
 static char *progname;
 static int errors = 0;
 static int recurse = 0;
+static int file_exist = 1;
 static int force = 0;
 #define STAT_BLOCK_SIZE 1
 static int pipe_fds[2] = { -1, -1 };
@@ -62,6 +64,7 @@
 static int add_exclude(const char *directory)
 {
 	struct stat sb;
+	int len=0;
 	if (directory == NULL || directory[0] != '/') {
 		fprintf(stderr, "Full path required for exclude: %s.\n",
 			directory);
@@ -85,12 +88,18 @@
 		return 1;
 	}
 
-	excludeArray[excludeCtr].directory = strdup(directory);
+	len = strlen(directory);
+	if (len > 1 &&  directory[len-1] == '/') {
+		excludeArray[excludeCtr].directory = calloc(1,len--);
+		strncpy(excludeArray[excludeCtr].directory, directory, len);
+	} else
+		excludeArray[excludeCtr].directory = strdup(directory);

restorecon/restorecon.c line 105

Quoted 10 lines
restorecon/restorecon.c +2 -1
+
 	if (!excludeArray[excludeCtr].directory) {
 		fprintf(stderr, "Out of memory.\n");
 		return 1;
 	}
-	excludeArray[excludeCtr++].size = strlen(directory);
+	excludeArray[excludeCtr++].size = len;
 
 	return 0;
 }

The above will only strip off one trailing '/', a path such as "/tmp/stuf/////" will still end up as "/tmp/stuff////". There is also no need to do the calloc and strncpy - the strdup will do just fine because size refers only to the number of valid characters, not the actual size of the allocation. How 'bout something along these lines:

	len = strlen(directory);
	while (len > 1 && excludeArray[excludeCtr].directory[len - 1] == '/')
		len--;
	excludeArray[excludeCtr++].size = len;

Even if you wanted to go with the sized-to-fit allocation, I would recommend the while loop on the trailing slashes.

<snip>

Quoted 4 lines

diff --exclude-from=exclude --exclude='*.po' -N -u -r nsapolicycoreutils/scripts/fixfiles policycoreutils-1.30.29/scripts/fixfiles

scripts/fixfiles line 124

Quoted 10 lines
scripts/fixfiles +2 -2
@@ -117,8 +117,8 @@
     exit $?
 fi
 if [ ! -z "$RPMFILES" ]; then
-    for i in `echo $RPMFILES | sed 's/,/ /g'`; do
-	rpmlist $i | ${RESTORECON} ${OUTFILES} ${FORCEFLAG} -R $* -f - 2>&1 >> $LOGFILE
+    for i in `echo "$RPMFILES" | sed 's/,/ /g'`; do
+	rpmlist $i | ${RESTORECON} ${OUTFILES} ${FORCEFLAG} $* -i -f - 2>&1 >> $LOGFILE
     done
     exit $?
 fi

Was dropping -R intentional? I didn't see a reference to that in the description.

Signature · 6 lines
Darrel

--
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
In reply to Stephen Smalley
Quoted 70 lines · Stephen Smalley
Quoted 16 lines · Daniel J Walsh

I have updated the patch to remove some of the objectionable changes.

diff --exclude-from=exclude --exclude='*.po' -N -u -r nsapolicycoreutils/restorecon/restorecon.c policycoreutils-1.30.29/restorecon/restorecon.c

restorecon/restorecon.c +1 -0
@@ -47,6 +48,7 @@
 static char *progname;
 static int errors = 0;
 static int recurse = 0;
+static int file_exist = 1;
 static int force = 0;
 #define STAT_BLOCK_SIZE 1
 static int pipe_fds[2] = { -1, -1 };

restorecon/restorecon.c line 68

Quoted 5 lines
restorecon/restorecon.c +1 -0
@@ -62,6 +64,7 @@
 static int add_exclude(const char *directory)
 {
 	struct stat sb;
+	int len=0;
 

size_t

restorecon/restorecon.c line 94

Quoted 12 lines
restorecon/restorecon.c +0 -0
 	if (directory == NULL || directory[0] != '/') {
 		fprintf(stderr, "Full path required for exclude: %s.\n",
restorecon/restorecon.c +3 -1
 			directory);
@@ -85,12 +88,18 @@
 		return 1;
 	}
 
-	excludeArray[excludeCtr].directory = strdup(directory);
+	len = strlen(directory);
+	if (len > 1 &&  directory[len-1] == '/') {
+		excludeArray[excludeCtr].directory = calloc(1,len--);
 

calloc() can fail.

restorecon/restorecon.c line 265

Quoted 8 lines
restorecon/restorecon.c +2 -1
@@ -249,7 +260,8 @@
 						freecon(scontext);
 						return 1;
 					}
-				}
+				} 
+
 

Intentional? Make sure you apply make indent after changes.

Quoted 15 lines

diff --exclude-from=exclude --exclude='*.po' -N -u -r nsapolicycoreutils/restorecond/Makefile policycoreutils-1.30.29/restorecond/Makefile

restorecond/Makefile +2 -2
@@ -5,14 +5,14 @@
 INITDIR = $(DESTDIR)/etc/rc.d/init.d
 SELINUXDIR = $(DESTDIR)/etc/selinux
 
-CFLAGS ?= -g -Werror -Wall -W
-override CFLAGS += -I$(PREFIX)/include -D_FILE_OFFSET_BITS=64
+CFLAGS ?= -g -Werror -Wall -W 
+override CFLAGS += -I$(PREFIX)/include -D_FILE_OFFSET_BITS=64 -fPIE
 LDLIBS += -lselinux -lsepol -L$(PREFIX)/lib
 
 all: restorecond
 
Quoted 9 lines

restorecond/Makefile line 16

Quoted 4 lines
restorecond/Makefile +1 -1
 restorecond:  restorecond.o utmpwatcher.o stringslist.o
-	$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
+	$(CC) -pie $(LDFLAGS) -o $@ $^ $(LDLIBS)
 

Shouldn't the -pie go in LDFLAGS, and be overridable for distros that don't support pie?

Yes

Quoted 19 lines
Quoted 7 lines
restorecond/Makefile +0 -0
 install: all
 	[ -d $(MANDIR)/man8 ] || mkdir -p $(MANDIR)/man8

diff --exclude-from=exclude --exclude='*.po' -N -u -r nsapolicycoreutils/scripts/fixfiles policycoreutils-1.30.29/scripts/fixfiles

scripts/fixfiles line 122

Quoted 8 lines
scripts/fixfiles +2 -2
@@ -117,8 +117,8 @@
     exit $?
 fi
 if [ ! -z "$RPMFILES" ]; then
-    for i in `echo $RPMFILES | sed 's/,/ /g'`; do
-	rpmlist $i | ${RESTORECON} ${OUTFILES} ${FORCEFLAG} -R $* -f - 2>&1 >> $LOGFILE
+    for i in `echo "$RPMFILES" | sed 's/,/ /g'`; do
+	rpmlist $i | ${RESTORECON} ${OUTFILES} ${FORCEFLAG} $* -i -f - 2>&1 >> $LOGFILE
 

Did you mean to drop -R?

Yes

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