Skip to contentSkip to conversation

make install fails if any users are in local.users

DISCUSSION Ivan Gyurdiev 4 participants 10 messages Mar 15, 2005 – Apr 15, 2005 5 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw
Quoted 5 lines
Quoted 5 lines

genhomedircon reads your local.users file and creates the file_contexts.homedirs from it. If
you don't have a user phantom in local.users then file_contexts.homedirs will cause load_policy to fail.

It seems to me that the problem is that setfiles -c, calls sepol_set_policydb_from_file, which loads the policy, does not call sepol_genusers, and as a result fails when it sees the homedir contexts.

Also, sepol_genusers is undocumented, and the -c option of setfiles is also not documented in the man pages.

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

#6 lore raw
Quoted 9 lines · Ivan Gyurdiev
Quoted 4 lines
Quoted 4 lines

genhomedircon reads your local.users file and creates the file_contexts.homedirs from it. If
you don't have a user phantom in local.users then file_contexts.homedirs will cause load_policy to fail.

It seems to me that the problem is that setfiles -c, calls sepol_set_policydb_from_file, which loads the policy, does not call sepol_genusers, and as a result fails when it sees the homedir contexts.

Yes, this makes sense. I'll look into modifying setfiles to call sepol_genusers() as well.

Quoted 2 lines

Also, sepol_genusers is undocumented, and the -c option of setfiles is also not documented in the man pages.

Yes, I can fix this as well.

Signature · 8 lines
Stephen Smalley <[email protected]>
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.
#7 lore raw
Quoted 8 lines · Stephen Smalley
Quoted 4 lines · Ivan Gyurdiev

It seems to me that the problem is that setfiles -c, calls sepol_set_policydb_from_file, which loads the policy, does not call sepol_genusers, and as a result fails when it sees the homedir contexts.

Yes, this makes sense. I'll look into modifying setfiles to call sepol_genusers() as well.

Hmmm...looks like this will require an extension to libsepol as well, as setfiles was just passing the file to libsepol and not dealing with the binary policy image at all.

Signature · 8 lines
Stephen Smalley <[email protected]>
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
In reply to Ivan Gyurdiev
Quoted 9 lines · Ivan Gyurdiev
Quoted 4 lines
Quoted 4 lines

genhomedircon reads your local.users file and creates the file_contexts.homedirs from it. If
you don't have a user phantom in local.users then file_contexts.homedirs will cause load_policy to fail.

It seems to me that the problem is that setfiles -c, calls sepol_set_policydb_from_file, which loads the policy, does not call sepol_genusers, and as a result fails when it sees the homedir contexts.

Actually, I'm not certain what the desired behavior for setfiles -c should be in this case. That option was introduced by Colin so that contexts from the file contexts configuration could be checked against a binary policy to ensure that any errors (e.g. undefined types) would be caught upon policy build rather than not showing up until runtime usage of file_contexts (e.g. by rpm, setfiles/restorecon, udev, etc). Since that time, the file_contexts.local and file_contexts.homedir support was introduced to allow local customization of file contexts and users without requiring policy sources. One question is whether setfiles -c should only validate the base file_contexts configuration (which no longer contains the home directory entries at all). If so, then we need to provide an interface to set which files are processed by matchpathcon_init(3). This seems appropriate to me, but would mean that e.g. a bug in genhomedircon that yields a corrupted file_contexts.homedir won't be noticed at policy build time. file_contexts.local definitely doesn't seem appropriate for validation upon policy build, as it is purely for local customizations.

Signature · 8 lines
Stephen Smalley <[email protected]>
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.
#9 lore raw
Quoted 3 lines · Stephen Smalley

One question is whether setfiles -c
should only validate the base file_contexts configuration (which no longer contains the home directory entries at all).

I don't see a good alternative, really. The home directory stuff is entirely dynamic and outside policy build.

Perhaps though genhomedircon itself could run setfiles -c though on e.g. file_contexts.homedir.tmp before renaming it to file_contexts.homedir.

--
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 7 lines · Colin Walters
Quoted 3 lines · Stephen Smalley

One question is whether setfiles -c
should only validate the base file_contexts configuration (which no longer contains the home directory entries at all).

I don't see a good alternative, really. The home directory stuff is entirely dynamic and outside policy build.

Ok, then the attached patches for libselinux and policycoreutils should disable processing of file_contexts.local and file_contexts.homedirs by setfiles -c.

Quoted 2 lines

Perhaps though genhomedircon itself could run setfiles -c though on e.g. file_contexts.homedir.tmp before renaming it to file_contexts.homedir.

Yes, that is a good idea, and even with the attached patches, it should be possible to explicitly pass file_contexts.homedir.tmp to setfiles -c, so I'd encourage Dan to make that change to genhomedircon.

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

Index: libselinux/ChangeLog
===================================================================
RCS file: /nfshome/pal/CVS/selinux-usr/libselinux/ChangeLog,v retrieving revision 1.115

ChangeLog +8 -0
diff -u -p -r1.115 ChangeLog
@@ -1,3 +1,11 @@
+1.23.1 2005-03-16
+	* Added set_matchpathcon_flags() function for setting flags
+	  controlling operation of matchpathcon.  MATCHPATHCON_BASEONLY
+	  means only process the base file_contexts file, not 
+	  file_contexts.homedirs or file_contexts.local, and is for use by
+	  setfiles -c.
+	* Updated matchpathcon.3 man page.
+
 1.22 2005-03-09
 	* Updated version for release.
 

Index: libselinux/VERSION
===================================================================
RCS file: /nfshome/pal/CVS/selinux-usr/libselinux/VERSION,v retrieving revision 1.35

VERSION +1 -1
diff -u -p -r1.35 VERSION
@@ -1 +1 @@
-1.22
+1.23.1

Index: libselinux/libselinux.spec
===================================================================
RCS file: /nfshome/pal/CVS/selinux-usr/libselinux/libselinux.spec,v retrieving revision 1.52

libselinux.spec +1 -1
diff -u -p -r1.52 libselinux.spec
@@ -1,6 +1,6 @@
 Summary: SELinux library and simple utilities
 Name: libselinux
-Version: 1.22
+Version: 1.23.1
 Release: 1
 License: Public domain (uncopyrighted)
 Group: System Environment/Libraries

Index: libselinux/include/selinux/selinux.h
===================================================================
RCS file: /nfshome/pal/CVS/selinux-usr/libselinux/include/selinux/selinux.h,v retrieving revision 1.36

include/selinux/selinux.h +8 -2
diff -u -p -r1.36 selinux.h
@@ -196,12 +196,18 @@ extern void set_matchpathcon_invalidcon(
 						 unsigned lineno, 
 						 char *context));
 
+/* Set flags controlling operation of matchpathcon_init or matchpathcon. */
+#define MATCHPATHCON_BASEONLY 1 /* Only process the base file_contexts file. */
+extern void set_matchpathcon_flags(unsigned int flags);
+
 /* Load the file contexts configuration specified by 'path'
    into memory for use by subsequent matchpathcon calls.  
    If 'path' is NULL, then load the active file contexts configuration,
    i.e. the path returned by selinux_file_context_path().
-   Also checks for a 'path'.local file and loads additional 
-   specifications from it if present. */
+   Unless the MATCHPATHCON_BASEONLY flag has been set, this
+   function also checks for a 'path'.homedirs file and 
+   a 'path'.local file and loads additional specifications 
+   from them if present. */
 extern int matchpathcon_init(const char *path);
 
 /* Match the specified pathname and mode against the file contexts

Index: libselinux/man/man3/matchpathcon.3
===================================================================
RCS file: /nfshome/pal/CVS/selinux-usr/libselinux/man/man3/matchpathcon.3,v retrieving revision 1.2

man/man3/matchpathcon.3 +92 -11

118 lines not on this page · raw message

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

src/matchpathcon.c +20 -11
diff -u -p -r1.22 matchpathcon.c
@@ -48,6 +48,13 @@ void set_matchpathcon_invalidcon(int (*f
 	myinvalidcon = f;
 }
 
+static unsigned int myflags;
+
+void set_matchpathcon_flags(unsigned int flags)
+{
+	myflags = flags;
+}
+
 /*
  * A file security context specification.
  */
@@ -517,8 +524,8 @@ static int process_line( const char *pat
 int matchpathcon_init(const char *path)
 {
 	FILE *fp;
-	FILE *localfp;
-	FILE *homedirfp;
+	FILE *localfp = NULL;
+	FILE *homedirfp = NULL;
 	char local_path[PATH_MAX + 1];
 	char homedir_path[PATH_MAX + 1];
 	char *line_buf = NULL;
@@ -534,15 +541,17 @@ int matchpathcon_init(const char *path)
 		return -1;
 	__fsetlocking(fp, FSETLOCKING_BYCALLER);
 
-	snprintf(homedir_path, sizeof(homedir_path), "%s.homedirs", path);
-	homedirfp = fopen(homedir_path, "r");
-	if (homedirfp != NULL)
-		__fsetlocking(homedirfp, FSETLOCKING_BYCALLER);
-
-	snprintf(local_path, sizeof(local_path), "%s.local", path);
-	localfp = fopen(local_path, "r");
-	if (localfp != NULL)
-		__fsetlocking(localfp, FSETLOCKING_BYCALLER);
+	if ((myflags & MATCHPATHCON_BASEONLY) == 0) {
+		snprintf(homedir_path, sizeof(homedir_path), "%s.homedirs", path);
+		homedirfp = fopen(homedir_path, "r");
+		if (homedirfp != NULL)
+			__fsetlocking(homedirfp, FSETLOCKING_BYCALLER);
+
+		snprintf(local_path, sizeof(local_path), "%s.local", path);
+		localfp = fopen(local_path, "r");
+		if (localfp != NULL)
+			__fsetlocking(localfp, FSETLOCKING_BYCALLER);
+	}
 
 	/* 
 	 * Perform two passes over the specification file.

Index: policycoreutils/ChangeLog
===================================================================
RCS file: /nfshome/pal/CVS/selinux-usr/policycoreutils/ChangeLog,v retrieving revision 1.105

ChangeLog +4 -0
diff -u -p -r1.105 ChangeLog
@@ -1,3 +1,7 @@
+1.23.2 2005-03-16
+	* Changed setfiles -c to call set_matchpathcon_flags(3) to
+	  turn off processing of .homedirs and .local.
+
 1.23.1 2005-03-14
 	* Merged rewrite of genhomedircon by Eric Paris.
 	* Changed fixfiles to relabel jfs since it now supports security xattrs

Index: policycoreutils/VERSION
===================================================================
RCS file: /nfshome/pal/CVS/selinux-usr/policycoreutils/VERSION,v retrieving revision 1.45

VERSION +1 -1
diff -u -p -r1.45 VERSION
@@ -1 +1 @@
-1.23.1
+1.23.2

Index: policycoreutils/policycoreutils.spec
===================================================================
RCS file: /nfshome/pal/CVS/selinux-usr/policycoreutils/policycoreutils.spec,v retrieving revision 1.68

policycoreutils.spec +3 -3
diff -u -p -r1.68 policycoreutils.spec
@@ -1,14 +1,14 @@
 Summary: SELinux policy core utilities.
 Name: policycoreutils
-Version: 1.23.1
+Version: 1.23.2
 Release: 1
 License: GPL
 Group: System Environment/Base
 Source: http://www.nsa.gov/selinux/archives/%{name}-%{version}.tgz
 
 Prefix: %{_prefix}
-BuildRequires: libselinux-devel >= 1.21.10 libsepol-devel >= 1.3.7
-Requires: libselinux >= 1.21.10 libsepol >= 1.3.7
+BuildRequires: libselinux-devel >= 1.23.1 libsepol-devel >= 1.3.7
+Requires: libselinux >= 1.23.1 libsepol >= 1.3.7
 
 BuildRoot: %{_tmppath}/%{name}-buildroot
 

Index: policycoreutils/setfiles/setfiles.c
===================================================================
RCS file: /nfshome/pal/CVS/selinux-usr/policycoreutils/setfiles/setfiles.c,v retrieving revision 1.33

setfiles/setfiles.c +4 -0
diff -u -p -r1.33 setfiles.c
@@ -431,6 +431,10 @@ int main(int argc, char **argv)
 				exit(1);
 			}
 			fclose(policystream);
+
+			/* Only process the specified file_contexts file, not
+			   any .homedirs or .local files. */
+			set_matchpathcon_flags(MATCHPATHCON_BASEONLY);
 			
 			break;
 		}
#11 lore raw
Quoted 13 lines · Stephen Smalley
Quoted 7 lines · Colin Walters
Quoted 3 lines · Stephen Smalley

One question is whether setfiles -c
should only validate the base file_contexts configuration (which no longer contains the home directory entries at all).

I don't see a good alternative, really. The home directory stuff is entirely dynamic and outside policy build.

Ok, then the attached patches for libselinux and policycoreutils should disable processing of file_contexts.local and file_contexts.homedirs by setfiles -c.

Quoted 7 lines
Quoted 2 lines

Perhaps though genhomedircon itself could run setfiles -c though on e.g. file_contexts.homedir.tmp before renaming it to file_contexts.homedir.

Yes, that is a good idea, and even with the attached patches, it should be possible to explicitly pass file_contexts.homedir.tmp to setfiles -c, so I'd encourage Dan to make that change to genhomedircon.

Attached is my latest genhomedircon which will actually check it against setfiles -c before writing to file_contexts.homedir. I am also attaching the diff against Red Hat latest. It will leave a broken file_contexts.homedir.tmp if it didn't work. So you can hopefully get more info about what went wrong. Comments?

Eric

root/genhomedircon-setfiles renamed from usr/sbin/genhomedircon +24 -1
@@ -291,11 +291,22 @@ class selinuxConfig:
 		self.selinuxdir=selinuxdir +"/"
 		self.contextdir="/contexts"
 		self.filecontextdir=self.contextdir+"/files"
+		self.policydir="/policy"
 		self.usepwd=usepwd
 
 	def getFileContextDir(self):
 		return self.selinuxdir+self.type+self.filecontextdir
 
+	def getBinaryPolicy(self):
+		return self.selinuxdir+self.type+self.policydir+"/policy."+self.getPolicyVersion()
+		
+	def getPolicyVersion(self):
+		rc=commands.getstatusoutput("cat /selinux/policyvers")
+		if rc[0] == 0:
+			return rc[1]
+		else:
+			return "18"
+		
 	def getFileContextFile(self):
 		return self.getFileContextDir()+"/file_contexts"
 	
@@ -437,9 +448,21 @@ class selinuxConfig:
 
 	def write(self):
 		try:
-			fd = open(self.getFileContextDir()+"/file_contexts.homedirs", "w")
+			fd = open(self.getFileContextDir()+"/file_contexts.homedirs.tmp", "w")
 			fd.write(self.genoutput())
 			fd.close()
+			rc = commands.getstatusoutput('setfiles -c %s %s' % ((self.getBinaryPolicy()), (self.getFileContextDir()+"/file_contexts.homedirs.tmp")))
+			if rc[0] == 0:
+				rc = commands.getstatusoutput('mv -f %s %s' % ((self.getFileContextDir()+"/file_contexts.homedirs.tmp"),(self.getFileContextDir()+"/file_contexts.homedirs")))
+				if rc[0] != 0:
+					sys.stderr.write("Unable to move file_contexts.homedirs.tmp to file_context.homedirs\n")
+					sys.stderr.write("Output was %s\n" % rc[1])
+					sys.stderr.flush()
+			else:
+				sys.stderr.write("Invalid values in the new file_contexts.homedirs.   File not created.  Bad file in file_contexts.homedirs.tmp\n")
+				sys.stderr.write("Output was %s\n" % rc[1])
+				sys.stderr.flush()
+				
 		except IOError, error:
 			sys.stderr.write("%s: %s\n" % ( sys.argv[0], error ))
 
#12 lore raw
Quoted 5 lines · Eric Paris

Attached is my latest genhomedircon which will actually check it against setfiles -c before writing to file_contexts.homedir. I am also attaching the diff against Red Hat latest. It will leave a broken file_contexts.homedir.tmp if it didn't work. So you can hopefully get more info about what went wrong. Comments?

Thanks, merged with the minor diff below to fully specify the path to setfiles.

Index: policycoreutils/scripts/genhomedircon
===================================================================
RCS file: /nfshome/pal/CVS/selinux-usr/policycoreutils/scripts/genhomedircon,v retrieving revision 1.21

scripts/genhomedircon +1 -1
diff -u -r1.21 genhomedircon
@@ -451,7 +451,7 @@
 			fd = open(self.getFileContextDir()+"/file_contexts.homedirs.tmp", "w")
 			fd.write(self.genoutput())
 			fd.close()
-			rc = commands.getstatusoutput('setfiles -c %s %s' % ((self.getBinaryPolicy()), (self.getFileContextDir()+"/file_contexts.homedirs.tmp")))
+			rc = commands.getstatusoutput('/usr/sbin/setfiles -c %s %s' % ((self.getBinaryPolicy()), (self.getFileContextDir()+"/file_contexts.homedirs.tmp")))
 			if rc[0] == 0:
 				rc = commands.getstatusoutput('mv -f %s %s' % ((self.getFileContextDir()+"/file_contexts.homedirs.tmp"),(self.getFileContextDir()+"/file_contexts.homedirs")))
 				if rc[0] != 0:
Signature · 8 lines
Stephen Smalley <[email protected]>
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.
#13 lore raw
In reply to Stephen Smalley
Quoted 4 lines
Quoted 4 lines

Perhaps though genhomedircon itself could run setfiles -c though on e.g. file_contexts.homedir.tmp before renaming it to file_contexts.homedir.

Can you clarify how this is different from the Makefile running setfiles -c? I thought this was working for a while, but it seems not - it's broken again:

Loading Policy ...
/usr/sbin/load_policy /etc/selinux/strict/policy/policy.19
touch tmp/load
Building file contexts files...
Validating file contexts files ...
/usr/sbin/setfiles -q -c /etc/selinux/strict/policy/policy.19 file_contexts/file_contexts
install -m 644 tmp/system.users /etc/selinux/strict/users/system.users install -m 644
tmp/customizable_types /etc/selinux/strict/contexts/customizable_types Installing file contexts files...
install -m 644
file_contexts/homedir_template /etc/selinux/strict/contexts/files/homedir_template install -m 644
file_contexts/file_contexts /etc/selinux/strict/contexts/files/file_contexts
Invalid values in the new file_contexts.homedirs. File not created.
Bad file in file_contexts.homedirs.tmp
Output
was /etc/selinux/strict/contexts/files/file_contexts.homedirs.tmp: line 62 has invalid context phantom:object_r:staff_home_dir_t

==============

Also, every error in the .tmp file causes it not to install, and I think it gets overwritten upon upgrade of the binary policy package to one without my local user customizations - I don't think the previous file is preserved. Then I run into trouble when I run restorecon on various things in /home, and it starts relabeling everything with the wrong role, since it has no knowledge of my users.

Signature · 8 lines
Ivan Gyurdiev <[email protected]>
Cornell University


--
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.
#14 lore raw
Quoted 7 lines · Ivan Gyurdiev
Quoted 3 lines
Quoted 3 lines

Perhaps though genhomedircon itself could run setfiles -c though on e.g. file_contexts.homedir.tmp before renaming it to file_contexts.homedir.

Can you clarify how this is different from the Makefile running setfiles -c? I thought this was working for a while, but it seems not - it's broken again:

It isn't different - mistake on my part. Already reported to the list, and the genhomedircon change was reverted in the latest policycoreutils.

Signature · 8 lines
Stephen Smalley <[email protected]>
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.