Skip to contentSkip to conversation

Using kernel SID (kernel_t domain) in reparent_to_init

PATCH Stephen D. Smalley 3 participants 5 messages Mar 28, 2003 – Apr 22, 2003 SELinux security module

lore
Share & tools
lore
#0 lore raw

In recent discussions on this list
(http://marc.theaimsgroup.com/?l=selinux&m=104852427209286&w=2) and on the linux-security-module list
(http://marc.theaimsgroup.com/?l=linux-security-module&m=104861921931879&w=2),
it has come up that SELinux should be assigning the kernel SID (kernel_t domain) to kernel threads in reparent_to_init rather than the init SID, and that in 2.5, the kmod logic was been reworked to use keventd, which uses reparent_to_init, so the kmod SID (kmod_t domain) will be obsolete in 2.5. The attached patch for lsm-2.4 changes SELinux to use the kernel SID for both reparent_to_init and kmod for consistency. This will require corresponding updates to the policy to fold the kmod_t domain into kernel_t. This change also means that certain permissions currently granted to init_t can be moved into kernel_t.

--
Stephen Smalley, NSA

Index: lsm-2.4/security/selinux/hooks.c
===================================================================
RCS file: /cvsroot/selinux/nsa/lsm-2.4/security/selinux/hooks.c,v retrieving revision 1.28

security/selinux/hooks.c +2 -2
diff -u -r1.28 hooks.c
@@ -2474,7 +2474,7 @@
 
 	tsec = current->security;
 	tsec->osid = tsec->sid;
-	tsec->sid = SECINITSID_KMOD;
+	tsec->sid = SECINITSID_KERNEL;
 	return;
 }
 
@@ -2486,7 +2486,7 @@
 
 	tsec = p->security;
 	tsec->osid = tsec->sid;
-	tsec->sid = SECINITSID_INIT; 
+	tsec->sid = SECINITSID_KERNEL; 
 	return;
 }
 
#1 lore raw

usermod/group* patch

Attached is a patch which adds the usermod utility and the corresponding set of group utilities to the spasswd wrapper utility set. The patch changes the Makefile for .../selinux/utils/spasswd and adds a set of policy files (groupadd.te,fc) for the group utilities.

The .../selinux/utils/spasswd/Makefile patch creates s-wrappers for usermod, groupadd, groupdel, groupmod, and gpasswd. These are all similar to suseradd, suserdel, etc.

The groupadd.te,fc policy used the useradd.te policy as a base. Some rules and permissions were trimmed out and some dontaudit rules were added.

I generated the patch against the latest cvs version of selinux.

David

nsa/selinux/policy/domains/program/groupadd.te +60 -0
diff -ruN old/nsa/selinux/policy/domains/program/groupadd.te new/nsa/selinux/policy/domains/program/groupadd.te
@@ -0,0 +1,60 @@
+#DESC Groupadd - Manage system groups
+#
+# Authors:  David Caplan, [email protected]
+#	    (Based on useradd.te by Chris Vance <[email protected]>)
+#
+
+#################################
+#
+# Rules for the groupadd_t domain.
+#
+# groupadd_t is the domain of the groupadd/mod/del programs when
+# executed through the sgroupadd/mod/del wrapper.
+type groupadd_t, domain, privlog, auth, privowner;
+role sysadm_r types groupadd_t;
+
+general_domain_access(groupadd_t)
+uses_shlib(groupadd_t)
+
+type groupadd_exec_t, file_type, sysadmfile, exec_type;
+domain_auto_trans(sysadm_t, groupadd_exec_t, groupadd_t )
+
+# Use capabilities.
+# need more if users can run gpasswd
+allow groupadd_t groupadd_t:capability { dac_override };
+
+# Allow access to context for shadow file
+allow groupadd_t security_t:security { context_to_sid };
+
+# Inherit and use descriptors from login.
+allow groupadd_t privfd:fd use;
+
+# Execute /usr/sbin/{groupadd,groupdel,groupmod}, /usr/bin/gpasswd.
+allow groupadd_t { bin_t sbin_t }:dir r_dir_perms;
+can_exec(groupadd_t, { sbin_t bin_t })
+
+# Update /etc/shadow and /etc/passwd
+file_type_auto_trans(groupadd_t, etc_t, shadow_t)
+allow groupadd_t etc_t:file create_file_perms;
+
+allow groupadd_t { etc_t shadow_t }:file { relabelfrom relabelto };
+
+# some apps ask for these accesses, but seems to work regardless
+dontaudit groupadd_t initrc_var_run_t:file { write };
+dontaudit groupadd_t { var_run_t device_t var_t }:dir { search };
+
+# Access terminals.
+allow groupadd_t ttyfile:chr_file rw_file_perms;
+allow groupadd_t ptyfile:chr_file rw_file_perms;
+ifdef(`gnome-pty-helper.te', `allow groupadd_t gphdomain:fd use;')
+
+
+
+
+
+
+
+
+
+
+
nsa/selinux/policy/file_contexts/program/groupadd.fc +10 -0
diff -ruN old/nsa/selinux/policy/file_contexts/program/groupadd.fc new/nsa/selinux/policy/file_contexts/program/groupadd.fc
@@ -0,0 +1,10 @@
+# groupadd
+/usr/local/selinux/bin/sgroupadd	system_u:object_r:groupadd_exec_t
+/usr/local/selinux/bin/sgroupdel	system_u:object_r:groupadd_exec_t
+/usr/local/selinux/bin/sgroupmod	system_u:object_r:groupadd_exec_t
+/usr/local/selinux/bin/sgpasswd		system_u:object_r:groupadd_exec_t
+/usr/bin/sgroupmod		system_u:object_r:groupadd_exec_t
+/usr/bin/sgroupadd               system_u:object_r:groupadd_exec_t
+/usr/bin/sgroupdel               system_u:object_r:groupadd_exec_t
+/usr/bin/sgpasswd               system_u:object_r:groupadd_exec_t
+
nsa/selinux/policy/file_contexts/program/useradd.fc +2 -0
diff -ruN old/nsa/selinux/policy/file_contexts/program/useradd.fc new/nsa/selinux/policy/file_contexts/program/useradd.fc
@@ -1,5 +1,7 @@
 # useradd
 /usr/local/selinux/bin/suseradd	system_u:object_r:useradd_exec_t
 /usr/local/selinux/bin/suserdel	system_u:object_r:useradd_exec_t
+/usr/local/selinux/bin/susermod	system_u:object_r:useradd_exec_t
+/usr/bin/susermod		system_u:object_r:useradd_exec_t
 /usr/bin/suseradd               system_u:object_r:useradd_exec_t
 /usr/bin/suserdel               system_u:object_r:useradd_exec_t
nsa/selinux/utils/spasswd/Makefile +22 -1
diff -ruN old/nsa/selinux/utils/spasswd/Makefile new/nsa/selinux/utils/spasswd/Makefile
@@ -1,15 +1,21 @@
 PASSWD=/usr/bin/passwd
+GPASSWD=/usr/bin/gpasswd
 CHFN=/usr/bin/chfn
 CHSH=/usr/bin/chsh
 USERADD=/usr/sbin/useradd
 USERDEL=/usr/sbin/userdel
+USERMOD=/usr/sbin/usermod
+GROUPADD=/usr/sbin/groupadd
+GROUPDEL=/usr/sbin/groupdel
+GROUPMOD=/usr/sbin/groupmod
 VIPW=/usr/sbin/vipw
 
 CFLAGS += -Wall -g -I/usr/local/selinux/include
 LDFLAGS += -L/usr/local/selinux/lib
 LIBS += -lsecure
 
-PROGS = spasswd sadminpasswd suseradd suserdel svipw schfn schsh
+PROGS = spasswd sadminpasswd suseradd suserdel svipw schfn schsh sgpasswd susermod \
+	sgroupadd sgroupdel sgroupmod
 DESTDIR = /usr/local/selinux/bin
 
 all:  $(PROGS)
@@ -38,6 +44,21 @@
 schsh.o: spasswd.c
 	$(CC) $(CFLAGS) -DPASSWD=\"$(CHSH)\" -c -o $@ $<
 
+sgpasswd.o: spasswd.c
+	$(CC) $(CFLAGS) -DADMIN_USE  -DPASSWD=\"$(GPASSWD)\" -c -o $@ $<
+
+susermod.o: spasswd.c
+	$(CC) $(CFLAGS) -DADMIN_USE  -DPASSWD=\"$(USERMOD)\" -c -o $@ $<
+
+sgroupadd.o: spasswd.c
+	$(CC) $(CFLAGS) -DADMIN_USE  -DPASSWD=\"$(GROUPADD)\" -c -o $@ $<
+
+sgroupdel.o: spasswd.c
+	$(CC) $(CFLAGS) -DADMIN_USE  -DPASSWD=\"$(GROUPDEL)\" -c -o $@ $<
+
+sgroupmod.o: spasswd.c
+	$(CC) $(CFLAGS) -DADMIN_USE  -DPASSWD=\"$(GROUPMOD)\" -c -o $@ $<
+
 install: all
 	install -m 555 -o root -g root $(PROGS) $(DESTDIR)
 
#2 lore raw

kmod_t v. kernel_t

In reply to Stephen D. Smalley
Quoted 5 lines · Stephen Smalley

The attached patch for selinux/policy folds the kmod_t domain into kernel_t and removes every_domain from kernel_t. kmod.te can then be removed. These changes have also been committed to the sourceforge CVS tree.

Does this mean that kmod_t should/can be replaced by kernel_t everywhere? If so, vmware.te and hotplug.te need to be fixed -- at least in the policy on the sourceforge site.

David

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

Re: kmod_t v. kernel_t

Quoted 9 lines · david caplan
Quoted 4 lines · Stephen Smalley

The attached patch for selinux/policy folds the kmod_t domain into kernel_t and removes every_domain from kernel_t. kmod.te can then be removed. These changes have also been committed to the sourceforge CVS tree.

Does this mean that kmod_t should/can be replaced by kernel_t everywhere? If so, vmware.te and hotplug.te need to be fixed -- at least in the policy on the sourceforge site.

I removed them from my policy weeks ago. hotplug.te works fine with my changes. vmware.te probably won't work the way it is in my tree, as I don't use it and have not had any feedback from people who use it I don't know what needs to be done.

Signature · 10 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.
#4 lore raw

Re: kmod_t v. kernel_t

In reply to david caplan
Quoted 10 lines · david caplan
Quoted 5 lines · Stephen Smalley

The attached patch for selinux/policy folds the kmod_t domain into kernel_t and removes every_domain from kernel_t. kmod.te can then be removed. These changes have also been committed to the sourceforge CVS tree.

Does this mean that kmod_t should/can be replaced by kernel_t everywhere? If so, vmware.te and hotplug.te need to be fixed -- at least in the policy on the sourceforge site.

Yes, I've now fixed them in the sourceforge CVS tree.

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.