Skip to contentSkip to conversation

sereference: enable local login

PATCH In review Serge E. Hallyn 3 participants 6 messages Jan 11, 2006 – Jan 18, 2006 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sereference: enable local login

Following is a patch which allows me to log in locally on a gentoo system with the reference policy.

thanks,
-serge

policy/modules/system/userdomain.if +4 -0
Index: refpolicy/policy/modules/system/userdomain.if
===================================================================
@@ -33,6 +33,9 @@ template(`base_user_template',`
 	role $1_r types $1_t;
 	allow system_r $1_r;
 
+	allow $1_t local_login_t:process { sigchld };
+	files_read_etc_runtime_files($1_t);
+
 	# user pseudoterminal
 	type $1_devpts_t;
 	term_user_pty($1_t,$1_devpts_t)
@@ -66,6 +69,7 @@ template(`base_user_template',`
 
 	type $1_tty_device_t; 
 	term_tty($1_t,$1_tty_device_t)
+	fs_associate_tmpfs($1_tty_device_t)
 
 	##############################
 	#
policy/modules/system/authlogin.if +4 -0
Index: refpolicy/policy/modules/system/authlogin.if
===================================================================
@@ -115,6 +115,8 @@ template(`authlogin_per_userdomain_templ
 	allow $2 self:netlink_audit_socket { create_netlink_socket_perms nlmsg_relay };
 
 	dontaudit $2 shadow_t:file { getattr read };
+	typeattribute $2 can_read_shadow_passwords;
+	allow $2 shadow_t:file { getattr read };
 
 	# Transition from the user domain to this domain.
 	domain_auto_trans($2,chkpwd_exec_t,$1_chkpwd_t)
@@ -253,6 +255,8 @@ interface(`auth_domtrans_chk_passwd',`
 	allow system_chkpwd_t $1:process sigchld;
 
 	dontaudit $1 shadow_t:file { getattr read };
+	typeattribute $1 can_read_shadow_passwords;
+	allow $1 shadow_t:file { getattr read };
 
 	dev_read_rand($1)
 	dev_read_urand($1)
policy/modules/system/locallogin.te +15 -0
Index: refpolicy/policy/modules/system/locallogin.te
===================================================================
@@ -61,6 +61,21 @@ files_create_tmp_files(local_login_t, lo
 kernel_read_system_state(local_login_t)
 kernel_read_kernel_sysctl(local_login_t)
 
+corecmd_exec_sbin(local_login_t)
+libs_use_shared_libs(local_login_t)
+
+# not sure where better to put the initrc_t ones:
+# note that initrc_t is defined in mls.te!
+dev_rw_generic_file(initrc_t)
+dev_manage_dev_nodes(initrc_t)
+dev_manage_dev_nodes(init_t)
+dev_manage_dev_nodes(local_login_t)
+files_rw_etc_files(initrc_t)
+auth_rw_login_records(initrc_t)
+dev_setattr_all_chr_files(getty_t)
+udev_read_state(init_t)
+init_allow_unix_stream_connect(local_login_t)
+
 dev_setattr_mouse(local_login_t)
 dev_getattr_mouse(local_login_t)
 dev_getattr_power_management(local_login_t)
policy/modules/system/init.if +14 -0
Index: refpolicy/policy/modules/system/init.if
===================================================================
@@ -873,3 +873,17 @@ interface(`init_dontaudit_rw_script_pid'
 	dontaudit $1 initrc_var_run_t:file { getattr read write append };
 ')
 
+## <summary>
+##	Allow a domain to access init_t socket.  (?)
+## </summary>
+## <param name="domain">
+##	Domain allowed access.
+## </param>
+interface(`init_allow_unix_stream_connect',`
+	gen_require(`
+		type init_t;;
+	')
+
+	allow $1 init_t:unix_stream_socket { connectto accept };
+')
+
policy/modules/kernel/terminal.fc +2 -0
Index: refpolicy/policy/modules/kernel/terminal.fc
===================================================================
@@ -1,5 +1,6 @@
 
 /dev/.*tty[^/]*		-c	gen_context(system_u:object_r:tty_device_t,s0)
+/dev/.*tty[^/]*		-l	gen_context(system_u:object_r:tty_device_t,s0)
 /dev/[pt]ty[abcdepqrstuvwxyz][0-9a-f]	-c gen_context(system_u:object_r:bsdpty_device_t,s0)
 /dev/adb.*		-c	gen_context(system_u:object_r:tty_device_t,s0)
 /dev/capi.*		-c	gen_context(system_u:object_r:tty_device_t,s0)
@@ -14,6 +15,7 @@
 /dev/rfcomm[0-9]+	-c	gen_context(system_u:object_r:tty_device_t,s0)
 /dev/tty		-c	gen_context(system_u:object_r:devtty_t,s0)
 /dev/ttySG.*		-c	gen_context(system_u:object_r:tty_device_t,s0)
+/dev/tts/[0-9]		-c	gen_context(system_u:object_r:tty_device_t,s0)
 
 /dev/pty/.*		-c	gen_context(system_u:object_r:bsdpty_device_t,s0)
 

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

#1 lore raw
Quoted 2 lines · Serge E. Hallyn

Following is a patch which allows me to log in locally on a gentoo system with the reference policy.

Well ok, I lied, I do seem to also have to play games with a custom homedir_template, but I assume that's something that
will be eventually fixed independent of me? :)

-serge

--
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
Quoted 7 lines · Serge E. Hallyn
Quoted 2 lines · Serge E. Hallyn

Following is a patch which allows me to log in locally on a gentoo system with the reference policy.

Well ok, I lied, I do seem to also have to play games with a custom homedir_template, but I assume that's something that
will be eventually fixed independent of me? :)

If you're referring to genhomedircon not being able to determine the ROLE, then yes it will be fixed. Otherwise, you'll have to be more specific.

Signature · 9 lines
Chris PeBenito
Tresys Technology, LLC
(410) 290-1411 x150


--
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 Serge E. Hallyn
Quoted 18 lines · Serge E. Hallyn

Following is a patch which allows me to log in locally on a gentoo system with the reference policy.

Index: refpolicy/policy/modules/system/authlogin.if
===================================================================

policy/modules/system/authlogin.if +2 -0
@@ -115,6 +115,8 @@ template(`authlogin_per_userdomain_templ
 	allow $2 self:netlink_audit_socket { create_netlink_socket_perms
 nlmsg_relay };
 
 	dontaudit $2 shadow_t:file { getattr read };
+	typeattribute $2 can_read_shadow_passwords;
+	allow $2 shadow_t:file { getattr read };
 
 	# Transition from the user domain to this domain.
policy/modules/system/authlogin.if +0 -0
 	domain_auto_trans($2,chkpwd_exec_t,$1_chkpwd_t)

policy/modules/system/authlogin.if interface(`auth_domtrans_chk_passwd',` · line 262

Quoted 8 lines
policy/modules/system/authlogin.if +2 -0
@@ -253,6 +255,8 @@ interface(`auth_domtrans_chk_passwd',`
 	allow system_chkpwd_t $1:process sigchld;
 
 	dontaudit $1 shadow_t:file { getattr read };
+	typeattribute $1 can_read_shadow_passwords;
+	allow $1 shadow_t:file { getattr read };
 
 	dev_read_rand($1)
 	dev_read_urand($1)

This is bad. We don't want to allow such domains access to shadow_t, a significant aim of SE Linux is to restrict access to shadow_t. If your PAM system is correctly patched then it will try to access /etc/shadow directly and then run a helper program which is both SETUID and has a domain_auto_trans() to give it the access it needs.

Quoted 11 lines

Index: refpolicy/policy/modules/kernel/terminal.fc
===================================================================

policy/modules/kernel/terminal.fc +1 -0
@@ -1,5 +1,6 @@
 
 /dev/.*tty[^/]*		-c	gen_context(system_u:object_r:tty_device_t,s0)
+/dev/.*tty[^/]*		-l	gen_context(system_u:object_r:tty_device_t,s0)
 /dev/[pt]ty[abcdepqrstuvwxyz][0-9a-f]	-c
 gen_context(system_u:object_r:bsdpty_device_t,s0)
 /dev/adb.*		-c	gen_context(system_u:object_r:tty_device_t,s0)
Quoted 1 line

/dev/capi.* -c gen_context(system_u:object_r:tty_device_t,s0)

Best to leave the symlinks as type device_t. I don't think that there's any benefit in having different types for different symlinks, and it just means that more access has to be granted. It can take ages to fix all domains that access certain device nodes and this alone is a good reason to minimise changes.

policy/modules/kernel/terminal.fc line 20

Quoted 7 lines
policy/modules/kernel/terminal.fc +1 -0
@@ -14,6 +15,7 @@
 /dev/rfcomm[0-9]+	-c	gen_context(system_u:object_r:tty_device_t,s0)
 /dev/tty		-c	gen_context(system_u:object_r:devtty_t,s0)
 /dev/ttySG.*		-c	gen_context(system_u:object_r:tty_device_t,s0)
+/dev/tts/[0-9]		-c	gen_context(system_u:object_r:tty_device_t,s0)
 
 /dev/pty/.*		-c	gen_context(system_u:object_r:bsdpty_device_t,s0)

Is Gentoo still using devfs device names? If so you might want to make it work for more than 10 serial ports.

Also Gentoo specific changes should have ifdef(`distro_gentoo' around them.

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.
#4 lore raw
Quoted 25 lines · Russell Coker
Quoted 24 lines · Serge E. Hallyn

Following is a patch which allows me to log in locally on a gentoo system with the reference policy.

Index: refpolicy/policy/modules/system/authlogin.if
===================================================================

policy/modules/system/authlogin.if +2 -0
@@ -115,6 +115,8 @@ template(`authlogin_per_userdomain_templ
 	allow $2 self:netlink_audit_socket { create_netlink_socket_perms
 nlmsg_relay };
 
 	dontaudit $2 shadow_t:file { getattr read };
+	typeattribute $2 can_read_shadow_passwords;
+	allow $2 shadow_t:file { getattr read };
 
 	# Transition from the user domain to this domain.
policy/modules/system/authlogin.if +2 -0
 	domain_auto_trans($2,chkpwd_exec_t,$1_chkpwd_t)
@@ -253,6 +255,8 @@ interface(`auth_domtrans_chk_passwd',`
 	allow system_chkpwd_t $1:process sigchld;
 
 	dontaudit $1 shadow_t:file { getattr read };
+	typeattribute $1 can_read_shadow_passwords;
+	allow $1 shadow_t:file { getattr read };
 
Quoted 8 lines

policy/modules/system/authlogin.if interface(`auth_domtrans_chk_passwd',` · line 262

Quoted 2 lines
policy/modules/system/authlogin.if +0 -0
 	dev_read_rand($1)
 	dev_read_urand($1)

This is bad. We don't want to allow such domains access to shadow_t, a significant aim of SE Linux is to restrict access to shadow_t. If your PAM system is correctly patched then it will try to access /etc/shadow directly and then run a helper program which is both SETUID and has a domain_auto_trans() to give it the access it needs.

I see. Will look into why that doesn't seem to be happening then...

Quoted 6 lines
Quoted 6 lines

Index: refpolicy/policy/modules/kernel/terminal.fc
===================================================================

policy/modules/kernel/terminal.fc +0 -0
@@ -1,5 +1,6 @@
 
Quoted 8 lines
Quoted 6 lines
policy/modules/kernel/terminal.fc +1 -0
 /dev/.*tty[^/]*		-c	gen_context(system_u:object_r:tty_device_t,s0)
+/dev/.*tty[^/]*		-l	gen_context(system_u:object_r:tty_device_t,s0)
 /dev/[pt]ty[abcdepqrstuvwxyz][0-9a-f]	-c
 gen_context(system_u:object_r:bsdpty_device_t,s0)
 /dev/adb.*		-c	gen_context(system_u:object_r:tty_device_t,s0)

/dev/capi.* -c gen_context(system_u:object_r:tty_device_t,s0)

Best to leave the symlinks as type device_t. I don't think that there's any

Yes. It seemed as though I needed this in order to log in over serial, but apparently something else must have changed at the same time that I made this change, as backing it out still lets me log in and also lets screen work.

Quoted 10 lines

policy/modules/kernel/terminal.fc line 20

Quoted 7 lines
policy/modules/kernel/terminal.fc +1 -0
@@ -14,6 +15,7 @@
 /dev/rfcomm[0-9]+	-c	gen_context(system_u:object_r:tty_device_t,s0)
 /dev/tty		-c	gen_context(system_u:object_r:devtty_t,s0)
 /dev/ttySG.*		-c	gen_context(system_u:object_r:tty_device_t,s0)
+/dev/tts/[0-9]		-c	gen_context(system_u:object_r:tty_device_t,s0)
 
 /dev/pty/.*		-c	gen_context(system_u:object_r:bsdpty_device_t,s0)

Is Gentoo still using devfs device names? If so you might want to make it work for more than 10 serial ports.

(I'm using udev) Makes no absolutely sense in hindsight, but I was erring on the 'safe' side. I almost picked [0-4] :)

Quoted 1 line

Also Gentoo specific changes should have ifdef(`distro_gentoo' around them.

Ok - I didn't think these were distro specific, but if in fact gentoo's pam is patched differently, the authlogin.if patch would certainly be. Hopefully there's a better way to fix that problem though.

thanks,
-serge

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

#5 lore raw
Quoted 6 lines · Serge E. Hallyn
Quoted 6 lines
Quoted 6 lines
policy/modules/kernel/terminal.fc +1 -0
@@ -14,6 +15,7 @@
 /dev/rfcomm[0-9]+	-c	gen_context(system_u:object_r:tty_device_t,s0)
 /dev/tty		-c	gen_context(system_u:object_r:devtty_t,s0)
 /dev/ttySG.*		-c	gen_context(system_u:object_r:tty_device_t,s0)
+/dev/tts/[0-9]		-c	gen_context(system_u:object_r:tty_device_t,s0)
 
Quoted 7 lines
Quoted 4 lines

policy/modules/kernel/terminal.fc line 20

Quoted 1 line
policy/modules/kernel/terminal.fc +0 -0
 /dev/pty/.*		-c	gen_context(system_u:object_r:bsdpty_device_t,s0)

Is Gentoo still using devfs device names? If so you might want to make it work for more than 10 serial ports.

(I'm using udev) Makes no absolutely sense in hindsight, but I was erring on the 'safe' side. I almost picked [0-4] :)

udev in Fedora doesn't use such names. It seems that Gentoo has been configured to use devfs style names, so that would be a Gentoo specific thing.

Quoted 6 lines
Quoted 2 lines

Also Gentoo specific changes should have ifdef(`distro_gentoo' around them.

Ok - I didn't think these were distro specific, but if in fact gentoo's pam is patched differently, the authlogin.if patch would certainly be. Hopefully there's a better way to fix that problem though.

If Gentoo's PAM works differently in this regard then Gentoo's PAM has to be fixed. This issue makes a significant difference to the attack vectors that can be used. It's not a difficult code change to make either (apart from the issue of everything being painful in PAM).

As for the Gentoo specific device names, we could have things perfectly functional with all possible device names represented. But I don't want to do that. Firstly if a section of policy has ifdef(`distro_whatever' around it then a developer for that distribution can remove the section if their needs change and they don't need to consult with anyone else. A significant problem we face is in getting unneeded policy removed due to the fear of breakage. Something that has ifdef(`distro_gentoo' around it can be removed by any Gentoo developer without complaints from anyone who doesn't use Gentoo. The next issue is that of understanding what the policy does. At some future time someone will want to analyse the labels on device nodes and spurious entries will complicate that. Finally every file contexts entry has a performance impact on setfiles/restorecon. According to the last tests I performed /dev entries don't make much difference as there aren't that many device nodes on a system, but it's good to avoid needless delays anyway.

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.