Skip to contentSkip to conversation

sshd subsystems

DISCUSSION Chris PeBenito 2 participants 5 messages Dec 21, 2003 – Dec 22, 2003 SELinux security module

lore
Share & tools
lore
#0 lore raw

I've been trying to decide what would be the best way to deal with sshd subsystems (sftp-server for example). Right now they can't be used because of their label (transition to unpriv_userdomain domain is denied for one). The simplest way to fix it would be to label the sftp-server binary as shell_exec_t. I was also thinking about using a sshd_subsys_exec_t or something similar instead, and add the appropriate policy. Any thoughts?

Signature · 8 lines
Chris PeBenito
<[email protected]>
Developer,
Hardened Gentoo Linux
Embedded Gentoo Linux
 
Public Key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xE6AF9243
Key fingerprint = B0E6 877A 883F A57A 8E6A  CB00 BC8E E42D E6AF 9243
#1 lore raw
Quoted 7 lines · Chris PeBenito

I've been trying to decide what would be the best way to deal with sshd subsystems (sftp-server for example). Right now they can't be used because of their label (transition to unpriv_userdomain domain is denied for one). The simplest way to fix it would be to label the sftp-server binary as shell_exec_t. I was also thinking about using a sshd_subsys_exec_t or something similar instead, and add the appropriate policy. Any thoughts?

The latter sounds like the correct option. Please send me a patch when you have working policy.

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.
#2 lore raw
Quoted 11 lines · Russell Coker
Quoted 7 lines · Chris PeBenito

I've been trying to decide what would be the best way to deal with sshd subsystems (sftp-server for example). Right now they can't be used because of their label (transition to unpriv_userdomain domain is denied for one). The simplest way to fix it would be to label the sftp-server binary as shell_exec_t. I was also thinking about using a sshd_subsys_exec_t or something similar instead, and add the appropriate policy. Any thoughts?

The latter sounds like the correct option. Please send me a patch when you have working policy.

Ok, this ended up not being as complex. If you sftp in, it still at one point exec's the user's shell, so it transitions ok. After the shell exec's, it seems to exec the subsystem executable. So the executable just has to be an executable type. So I added the couple lines to make subsystem servers be executable by unpriv_userdomain. The file contexts may need to be tweaked, but the first one is where Gentoo puts sftp-server.

Signature · 8 lines
Chris PeBenito
<[email protected]>
Developer,
Hardened Gentoo Linux
Embedded Gentoo Linux
 
Public Key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xE6AF9243
Key fingerprint = B0E6 877A 883F A57A 8E6A  CB00 BC8E E42D E6AF 9243
domains/program/ssh.te +6 -0
diff -urN policy-1.4.orig/domains/program/ssh.te policy-1.4/domains/program/ssh.te
@@ -8,8 +8,10 @@
 
 # sshd_exec_t is the type of the sshd executable.
 # sshd_key_t is the type of the ssh private key files
+# sshd_subsys_exec_t is the type of sshd subsystem executables.
 type sshd_exec_t, file_type, exec_type, sysadmfile;
 type sshd_key_t, file_type, sysadmfile;
+type sshd_subsys_exec_t, file_type, exec_type, sysadmfile;
 
 type ssh_port_t, port_type;
 
@@ -129,6 +131,10 @@
 sshd_program_domain(sshd)
 sshd_spawn_domain(sshd, unpriv_userdomain, userpty_type)
 
+# for sshd subsystems, such as sftp-server.
+can_exec(unpriv_userdomain,sshd_subsys_exec_t)
+allow sshd_t sshd_subsys_exec_t:file getattr;
+
 ifdef(`use_x_ports', `
 # for X forwarding
 allow sshd_t xserver_port_t:tcp_socket name_bind;
file_contexts/program/ssh.fc +3 -0
diff -urN policy-1.4.orig/file_contexts/program/ssh.fc policy-1.4/file_contexts/program/ssh.fc
@@ -9,3 +9,6 @@
 /root/\.ssh(/.*)?		system_u:object_r:sysadm_home_ssh_t
 /home/[^/]+/\.ssh(/.*)?		system_u:object_r:user_home_ssh_t
 /home/jadmin/\.ssh(/.*)?	system_u:object_r:staff_home_ssh_t
+# subsystems
+/usr/lib/misc/sftp-server --	system_u:object_r:sshd_subsys_exec_t
+/usr/libexec/openssh/sftp-server -- system_u:object_r:sshd_subsys_exec_t
#3 lore raw
Quoted 8 lines · Chris PeBenito
Quoted 8 lines
Quoted 7 lines

I've been trying to decide what would be the best way to deal with sshd subsystems (sftp-server for example). Right now they can't be used because of their label (transition to unpriv_userdomain domain is denied for one). The simplest way to fix it would be to label the sftp-server binary as shell_exec_t. I was also thinking about using a sshd_subsys_exec_t or something similar instead, and add the appropriate policy. Any thoughts?

Quoted 7 lines
Quoted 2 lines

The latter sounds like the correct option. Please send me a patch when you have working policy.

Ok, this ended up not being as complex. If you sftp in, it still at one point exec's the user's shell, so it transitions ok. After the shell exec's, it seems to exec the subsystem executable. So the executable just has to be an executable type. So I added the couple lines to make

Why not just label the sftp executable as bin_t then?

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
Quoted 6 lines · Russell Coker
Quoted 4 lines

Ok, this ended up not being as complex. If you sftp in, it still at one point exec's the user's shell, so it transitions ok. After the shell exec's, it seems to exec the subsystem executable. So the executable just has to be an executable type. So I added the couple lines to make

Why not just label the sftp executable as bin_t then?

I thought that some might want a specific type since sftp-server is off in an odd place. But I'm not attached to that, and bin_t would probably be better.

subsystems as bin_t:

domains/program/ssh.te       |    3 +++
file_contexts/program/ssh.fc |    3 +++
2 files changed, 6 insertions(+)
Signature · 8 lines
Chris PeBenito
<[email protected]>
Developer,
Hardened Gentoo Linux
Embedded Gentoo Linux
 
Public Key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xE6AF9243
Key fingerprint = B0E6 877A 883F A57A 8E6A  CB00 BC8E E42D E6AF 9243
domains/program/ssh.te +3 -0
diff -urN policy-1.4.orig/domains/program/ssh.te policy-1.4/domains/program/ssh.te
@@ -129,6 +129,9 @@
 sshd_program_domain(sshd)
 sshd_spawn_domain(sshd, unpriv_userdomain, userpty_type)
 
+# for sshd subsystems, such as sftp-server.
+allow sshd_t bin_t:file getattr;
+
 ifdef(`use_x_ports', `
 # for X forwarding
 allow sshd_t xserver_port_t:tcp_socket name_bind;
file_contexts/program/ssh.fc +3 -0
diff -urN policy-1.4.orig/file_contexts/program/ssh.fc policy-1.4/file_contexts/program/ssh.fc
@@ -9,3 +9,6 @@
 /root/\.ssh(/.*)?		system_u:object_r:sysadm_home_ssh_t
 /home/[^/]+/\.ssh(/.*)?		system_u:object_r:user_home_ssh_t
 /home/jadmin/\.ssh(/.*)?	system_u:object_r:staff_home_ssh_t
+# subsystems
+/usr/lib/misc/sftp-server --	system_u:object_r:bin_t
+/usr/libexec/openssh/sftp-server -- system_u:object_r:bin_t