Skip to contentSkip to conversation

new PAM and policy to match

PATCH Russell Coker 2 participants 5 messages Nov 9, 2003 – Nov 18, 2003 SELinux security module

lore
Share & tools
lore
#0 lore raw

I have updated my web site with new policy that greatly restricts access to /etc/shadow, this relies on a modified version of PAM that has a more capable unix_chkpwd implementation with a new program unix_verify to check for expired accounts.

It's still a bit experimental at the moment and there is no clear upgrade path from an existing SE Linux system (IE an upgrade while in enforcing mode is likely to break things).

I hav attached the main PAM patch that I am using, the policy is in the usual place.

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
Linux-PAM/modules/pam_unix/Makefile +14 -5
@@ -36,13 +36,14 @@
 endif
 
 CHKPWD=unix_chkpwd
+VERIFY=unix_verify
 
-EXTRAS += -DCHKPWD_HELPER=\"$(SUPLEMENTED)/$(CHKPWD)\"
+EXTRAS += -DCHKPWD_HELPER=\"$(SUPLEMENTED)/$(CHKPWD)\" -DVERIFY_HELPER=\"$(SUPLEMENTED)/$(VERIFY)\"
 
 ########################################################################
 
-CFLAGS += $(USE_CRACKLIB) $(USE_LCKPWDF) $(NEED_LCKPWDF) $(EXTRAS)
-LDLIBS = $(EXTRALS)
+CFLAGS += $(USE_CRACKLIB) $(USE_LCKPWDF) $(NEED_LCKPWDF) $(EXTRAS) -DWITH_SELINUX
+LDLIBS = $(EXTRALS) -lselinux
 
 ifdef USE_CRACKLIB
 CRACKLIB = -lcrack
@@ -69,7 +70,7 @@
 
 ########################### don't edit below #######################
 
-all: dirs info $(PLUS) $(LIBSHARED) $(LIBSTATIC) $(CHKPWD) register
+all: dirs info $(PLUS) $(LIBSHARED) $(LIBSTATIC) $(CHKPWD) $(VERIFY) register
 
 dynamic/%.o : %.c
 	$(CC) $(CFLAGS) $(DYNAMIC) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
@@ -125,6 +126,12 @@
 unix_chkpwd.o: unix_chkpwd.c
 	$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
 
+$(VERIFY): unix_verify.o
+	$(CC) -o $(VERIFY) $^ $(LDLIBS)
+
+unix_verify.o: unix_verify.c
+	$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
+
 md5_good.o: md5.c
 	$(CC) $(CFLAGS) $(CPPFLAGS) -DHIGHFIRST -D'MD5Name(x)=Good##x' \
 		$(TARGET_ARCH) -c $< -o $@
@@ -150,15 +157,17 @@
 endif
 	$(MKDIR) $(FAKEROOT)$(SUPLEMENTED)
 	install -m 4555 $(CHKPWD) $(FAKEROOT)$(SUPLEMENTED)
+	install -m 4555 $(VERIFY) $(FAKEROOT)$(SUPLEMENTED)
 
 remove:
 	rm -f $(FAKEROOT)$(SECUREDIR)/$(LIBSHARED)
 	for x in pam_unix_auth pam_unix_acct pam_unix_passwd pam_unix_session;\
 		do rm -f $(FAKEROOT)$(SECUREDIR)/$$x.so ; done
 	rm -f $(FAKEROOT)$(SUPLEMENTED)/$(CHKPWD)
+	rm -f $(FAKEROOT)$(SUPLEMENTED)/$(VERIFY)
 
 clean:
-	rm -f $(LIBOBJD) $(LIBOBJS) $(CHKPWD) *.o *.so core
+	rm -f $(LIBOBJD) $(LIBOBJS) $(CHKPWD) $(VERIFY) *.o *.so core
 	rm -f *~ *.a *.out *.bak
 	rm -rf dynamic static
 
Linux-PAM/modules/pam_unix/lckpwdf.-c +26 -1
@@ -26,6 +26,9 @@
 
 #include <fcntl.h>
 #include <signal.h>
+#ifdef WITH_SELINUX
+#include <selinux/selinux.h>
+#endif
 
 #define LOCKFILE "/etc/.pwd.lock"
 #define TIMEOUT 15
@@ -64,7 +67,29 @@
 	if (lockfd != -1)
 		return -1;
 
-	lockfd = open(LOCKFILE, O_CREAT | O_WRONLY, 0600);
+#ifdef WITH_SELINUX
+	if(is_selinux_enabled())
+	{
+		lockfd = open(LOCKFILE, O_WRONLY);
+		if(lockfd == -1 && errno == ENOENT)
+		{
+			security_context_t create_context;
+			int rc;
+
+			if(getfilecon("/etc/passwd", &create_context))
+				return -1;
+			rc = setfscreatecon(create_context);
+			freecon(create_context);
+			if(rc)
+				return -1;
+			lockfd = open(LOCKFILE, O_CREAT | O_WRONLY, 0600);
+			if(setfscreatecon(NULL))
+				return -1;
+		}
+	}
+	else
+#endif
+		lockfd = open(LOCKFILE, O_CREAT | O_WRONLY, 0600);
 	if (lockfd == -1)
 		return -1;
 	if (set_close_on_exec(lockfd) == -1)
Linux-PAM/modules/pam_unix/pam_unix_acct.c +3 -0
@@ -97,6 +97,8 @@
 		return PAM_USER_UNKNOWN;
 	}
 
+	return _unix_run_verify_binary(pamh, ctrl, uname, pwent->pw_uid);
+#if 0
 	if (!strcmp( pwent->pw_passwd, "*NP*" )) { /* NIS+ */
 		uid_t save_euid, save_uid;
 
@@ -187,6 +189,7 @@
 	D(("all done"));
 
 	return PAM_SUCCESS;
+#endif
 }
 
 
Linux-PAM/modules/pam_unix/pam_unix_passwd.c +77 -5

131 lines not on this page · raw message

Linux-PAM/modules/pam_unix/support.c +87 -19

136 lines not on this page · raw message

Linux-PAM/modules/pam_unix/unix_chkpwd.c +18 -26

85 lines not on this page · raw message

Linux-PAM/modules/pam_unix/unix_verify.c +252 -0

252 lines not on this page · raw message

#1 lore raw
Quoted 4 lines · Russell Coker

I have updated my web site with new policy that greatly restricts access to /etc/shadow, this relies on a modified version of PAM that has a more capable unix_chkpwd implementation with a new program unix_verify to check for expired accounts.

I have attached a new pam patch which fixes a problem in the code that calls unix_verify. Previously it would not correctly verify an account with UID 0 if the calling code ran as non-root due to the fact that I had not updated the pam_unix.so code to match changes to unix_verify.

This meant that "su -" would fail (but logging in as root at the console would still work).

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
Linux-PAM/modules/pam_unix/Makefile +14 -5
@@ -36,13 +36,14 @@
 endif
 
 CHKPWD=unix_chkpwd
+VERIFY=unix_verify
 
-EXTRAS += -DCHKPWD_HELPER=\"$(SUPLEMENTED)/$(CHKPWD)\"
+EXTRAS += -DCHKPWD_HELPER=\"$(SUPLEMENTED)/$(CHKPWD)\" -DVERIFY_HELPER=\"$(SUPLEMENTED)/$(VERIFY)\"
 
 ########################################################################
 
-CFLAGS += $(USE_CRACKLIB) $(USE_LCKPWDF) $(NEED_LCKPWDF) $(EXTRAS)
-LDLIBS = $(EXTRALS)
+CFLAGS += $(USE_CRACKLIB) $(USE_LCKPWDF) $(NEED_LCKPWDF) $(EXTRAS) -DWITH_SELINUX
+LDLIBS = $(EXTRALS) -lselinux
 
 ifdef USE_CRACKLIB
 CRACKLIB = -lcrack
@@ -69,7 +70,7 @@
 
 ########################### don't edit below #######################
 
-all: dirs info $(PLUS) $(LIBSHARED) $(LIBSTATIC) $(CHKPWD) register
+all: dirs info $(PLUS) $(LIBSHARED) $(LIBSTATIC) $(CHKPWD) $(VERIFY) register
 
 dynamic/%.o : %.c
 	$(CC) $(CFLAGS) $(DYNAMIC) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
@@ -125,6 +126,12 @@
 unix_chkpwd.o: unix_chkpwd.c
 	$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
 
+$(VERIFY): unix_verify.o
+	$(CC) -o $(VERIFY) $^ $(LDLIBS)
+
+unix_verify.o: unix_verify.c
+	$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
+
 md5_good.o: md5.c
 	$(CC) $(CFLAGS) $(CPPFLAGS) -DHIGHFIRST -D'MD5Name(x)=Good##x' \
 		$(TARGET_ARCH) -c $< -o $@
@@ -150,15 +157,17 @@
 endif
 	$(MKDIR) $(FAKEROOT)$(SUPLEMENTED)
 	install -m 4555 $(CHKPWD) $(FAKEROOT)$(SUPLEMENTED)
+	install -m 4555 $(VERIFY) $(FAKEROOT)$(SUPLEMENTED)
 
 remove:
 	rm -f $(FAKEROOT)$(SECUREDIR)/$(LIBSHARED)
 	for x in pam_unix_auth pam_unix_acct pam_unix_passwd pam_unix_session;\
 		do rm -f $(FAKEROOT)$(SECUREDIR)/$$x.so ; done
 	rm -f $(FAKEROOT)$(SUPLEMENTED)/$(CHKPWD)
+	rm -f $(FAKEROOT)$(SUPLEMENTED)/$(VERIFY)
 
 clean:
-	rm -f $(LIBOBJD) $(LIBOBJS) $(CHKPWD) *.o *.so core
+	rm -f $(LIBOBJD) $(LIBOBJS) $(CHKPWD) $(VERIFY) *.o *.so core
 	rm -f *~ *.a *.out *.bak
 	rm -rf dynamic static
 
Linux-PAM/modules/pam_unix/lckpwdf.-c +26 -1
@@ -26,6 +26,9 @@
 
 #include <fcntl.h>
 #include <signal.h>
+#ifdef WITH_SELINUX
+#include <selinux/selinux.h>
+#endif
 
 #define LOCKFILE "/etc/.pwd.lock"
 #define TIMEOUT 15
@@ -64,7 +67,29 @@
 	if (lockfd != -1)
 		return -1;
 
-	lockfd = open(LOCKFILE, O_CREAT | O_WRONLY, 0600);
+#ifdef WITH_SELINUX
+	if(is_selinux_enabled())
+	{
+		lockfd = open(LOCKFILE, O_WRONLY);
+		if(lockfd == -1 && errno == ENOENT)
+		{
+			security_context_t create_context;
+			int rc;
+
+			if(getfilecon("/etc/passwd", &create_context))
+				return -1;
+			rc = setfscreatecon(create_context);
+			freecon(create_context);
+			if(rc)
+				return -1;
+			lockfd = open(LOCKFILE, O_CREAT | O_WRONLY, 0600);
+			if(setfscreatecon(NULL))
+				return -1;
+		}
+	}
+	else
+#endif
+		lockfd = open(LOCKFILE, O_CREAT | O_WRONLY, 0600);
 	if (lockfd == -1)
 		return -1;
 	if (set_close_on_exec(lockfd) == -1)
Linux-PAM/modules/pam_unix/pam_unix_acct.c +3 -0
@@ -97,6 +97,8 @@
 		return PAM_USER_UNKNOWN;
 	}
 
+	return _unix_run_verify_binary(pamh, ctrl, uname, pwent->pw_uid);
+#if 0
 	if (!strcmp( pwent->pw_passwd, "*NP*" )) { /* NIS+ */
 		uid_t save_euid, save_uid;
 
@@ -187,6 +189,7 @@
 	D(("all done"));
 
 	return PAM_SUCCESS;
+#endif
 }
 
 
Linux-PAM/modules/pam_unix/pam_unix_passwd.c +77 -5

131 lines not on this page · raw message

Linux-PAM/modules/pam_unix/support.c +87 -19

136 lines not on this page · raw message

Linux-PAM/modules/pam_unix/unix_chkpwd.c +18 -26

85 lines not on this page · raw message

Linux-PAM/modules/pam_unix/unix_verify.c +252 -0

252 lines not on this page · raw message

#2 lore raw

Specific details of the policy ERR

To save you some time, here's where the double def of the type are occuring:

misc/later.te: type run_init_conf_t, file_type, sysadmfile;
misc/later.te: allow userhelper_t run_init_conf_t:file rw_file_perms;

program/userhelper.te: type run_init_conf_t, file_type, sysadmfile;
program/userhelper.te: allow userhelper_t run_init_conf_t:file rw_file_perms;

Signature · 12 lines
------------------------------------------------------
   Dale Amon     [email protected]    +44-7802-188325
       International linux systems consultancy
     Hardware & software system design, security
    and networking, systems programming and Admin
	      "Have Laptop, Will Travel"
------------------------------------------------------

--
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 Russell Coker

Russ: We're getting there but I've finally got an selinux system using your packages that I can log into. That's the good news.

The problem areas are:

* I had to delete later.te.
* redhat-config-users.te had no matching tc file. I didn't need it anyway so I deleted it

With those mods I was able to build the policy file. After rolling in my image with rsync, I logged into the non-initrd choice and:

	tune2fs -j /dev/hda2	# set up ext2->ext3
	make load
	make relabel

which works. I can see the file contexts with ls. Then I reboot through the initrd version. This time, for the first time since I switched package repositories, I was able to login to the selinux enabled kernel.

Problem though... it is not giving a context or asking for a choice of initial contexts; and newrole doesn't recognize sysadm_r.

I'd guess there is/are still incorrect package version(s) being loaded out of
coker
walters
sid
but I'll be damned if I can figure out what and why.

Signature · 12 lines
------------------------------------------------------
   Dale Amon     [email protected]    +44-7802-188325
       International linux systems consultancy
     Hardware & software system design, security
    and networking, systems programming and Admin
	      "Have Laptop, Will Travel"
------------------------------------------------------

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

Russ: Any suggestions on which versions of which
packages I need to override?

Signature · 12 lines
------------------------------------------------------
   Dale Amon     [email protected]    +44-7802-188325
       International linux systems consultancy
     Hardware & software system design, security
    and networking, systems programming and Admin
	      "Have Laptop, Will Travel"
------------------------------------------------------

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